Select to view content in your preferred language

gp.InsertCursor method (ArcGIS 9.3)

700
1
02-21-2011 07:41 AM
MarkWiygul
Emerging Contributor
Hi, I'm learning to script and have been experimenting with 'cursors'.  I keep getting an error at the command prompt:

"rowc.Shape=geom
RuntimeError: ERROR 999999: Error executing function.  The coordinates or measures are out of bounds." 

By accident I found a workaround but I don't understand why it works and think I shouldn't need it.  I create two varibles to store the polygon.Extent and polygon.Area fields from a feature class that I wish to copy over to another feature class.  I run a gp.Search.Cursor first to find the polygons containing the ZIPCODE to copy. The ZIPCODE argument is retrieved using sys.argv[1] from the command prompt.  I copy the polygon.Shape which I understand encapsulates the area and extent fields within the geoprocessor.  Ayhow, I get the above error message when I attempt to do that.  I then figured I needed to copy the Area and Extent fields and Insert those attributes as well.  After I created the varibles to store the Area and Extent I forgot to Insert them, but it worked!  I tried 'commenting' those varibles back out and get the error.  Then I 'uncomment' the varibles back in and behold, it works! 

If I used some unconventional terms or names its because I'm new.  Sorry, my indentation gets removed when I post.  Thanks for any feedback!

Below is my entire program:

import arcgisscripting, sys
gp = arcgisscripting.create(9.3)
getzip = sys.argv[1]

gp.Workspace = "C:\\Student\\PYTH\\Database\\MySD.mdb"
cur = gp.SearchCursor ("Zipcodes", "[ZIP] = %d" % int(getzip))

#search for polygons based on a zipcode entered as an argument

listID=[]  # store a list of objectid(s) for zipcodes that have numerous polygons
rowa = cur.Next()
counter = 0
while rowa:
    listID+=[rowa.OBJECTID]   
    counter +=1
    rowa=cur.Next()
print '%d polygon(s) counted so found meeting criteria' % counter
print 'The  OBJECTID(s) are... ', listID

#search for and save the geometry of each feature with an objectid saved in listID above

for x in listID:
    cur = gp.SearchCursor("Zipcodes", "[OBJECTID] = %d" %x)
    rowb=cur.Next()
    geom=rowb.Shape   # i believe this line should store the entire geometry
    geoA=geom.Area   # error -999999 if I comment this line out
    geoX=geom.Extent   # error - 999999 if I comment this line out


    cur=gp.InsertCursor("polyBlank")   #  insert the geometry and zipcode into a new feature class
    rowc=cur.NewRow()
    rowc.Shape=geom
    rowc.ZIP=getzip
    cur.InsertRow(rowc)
    print "added polygon ", x
del cur
Tags (2)
0 Kudos
1 Reply
KimOllivier
Honored Contributor
This is not the way to make a subset of features, although with some editing and additions it would be possible. You cannot get a geometry object from a cursor without extracting each vertex to make a new object, you do not need to get area and perimeter because they are geometry properties.

MakeFeatureLayer_management will create a layer using your definition similar to the cursor, but it will be an in memory bitmap that you do not need to access.

Copy_management will take the featurelayer and create a new featureclass of the subset.

import arcgisscripting, sys
gp = arcgisscripting.create(9.3)
getzip = sys.argv[1]

gp.Workspace = "C:\\Student\\PYTH\\Database\\MySD.mdb"

gp.MakeFeatureLayer_management ("Zipcodes", "Ziplayer","[ZIP] = %d" % int(getzip))
gp.Copy_management("Ziplayer","Polyblank")
0 Kudos