+ Reply to Thread
Results 1 to 2 of 2

Thread: error in batch feature to point

  1. #1
    Elaine Kuo
    Join Date
    Apr 2010
    Posts
    204
    Points
    0
    Answers Provided
    3


    0

    Default error in batch feature to point

    Hello,

    I have a python code at hand to batch the process of feature to point.

    Question 1
    In the loop section, it showed that "This object does not support enumeration."
    Please kindly point out the error in the code for a beginner.

    Question 2
    This code did work for a single shapefile but not for multiple ones.
    Please kindly use attached shapefile and have a try. (copying it to two or three)
    Please also help with the error in the batch code.
    Thanks a lot.



    Code
    ##Script Name: Multi centroid
    ##Description: Get centroid of shapefiles
    ##Created By: Elaine Kuo
    ##Date: 29/04/2012


    #Import standard library modules
    import win32com.client, sys, os

    #Create the Geoprocessor object
    GP = win32com.client.Dispatch("esriGeoprocessing.GpDispatch.1")

    #Set the input workspace
    #GP.workspace = sys.argv[1]
    #Set the workspace.
    GP.Workspace= "G:/temp_stage_2_dissolve_by_B_NB/test"

    #Set the output workspace
    #outWorkspace = sys.argv[2]
    #Set the workspace. List all of the feature classes in the dataset
    outWorkspace= "G:/temp_stage_3_centroid_of_B_NB/Sylviidae_86"


    try:
    # Create a list of all the features within the workspace.
    FCs = GP.ListFeatureClasses()



    # Loop through every item in the list that was just generated
    for fc in FCs:

    # Break out the name, no path or extension, using the describe object.
    desc = GP.describe(fc)
    featureName = desc.name

    # Work the magic.
    outFeatureClass = outWorkspace + os.sep + GP.ValidateTableName(featureName, outWorkspace)
    GP.FeaturetoPoint(fc, outFeatureClass)



    except:
    GP.AddMessage(GP.GetMessages(2))
    print GP.GetMessages(2)
    Attached Files

  2. #2
    Dan Lee

    Join Date
    Oct 2009
    Posts
    582
    Points
    143
    Answers Provided
    27


    0

    Default Re: error in batch feature to point

    This doc explains the way to create geoprocessor object in ArcGIS 9.3:
    http://webhelp.esri.com/arcgisdeskto...ocessor_object

    The first table under "Comparing the 9.3-version and 9.2-version geoprocessor" in the above doc shows the differences between using ListFeatureClasses with a 9.3-version and 9.2-version geoprocessor.

    You would use the following code, instead of the Dispatch:
    import arcgisscripting
    gp = arcgisscripting.create(9.3)

    Hope that helps.
    Dan (Geoprocessing)

+ Reply to Thread

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts