Reading geometries |
|
Release 9.3
Last modified June 3, 2010 |
![]() ![]() ![]() Print all topics in : "Data properties and access when scripting" |
Note:
This topic was updated for 9.3.1.
Each feature in a feature class contains a set of points defining the vertices of a polygon or line or a single coordinate defining a point feature. These points can be accessed using the geometry object, which returns them in an array of point objects. The array object can contain any number of geoprocessing objects such as points, geometries, or spatial references.
Count | The number of objects in the array |
Reset() | Resets the array to the first object
NOTE: Reset is used only for non-cursor Arrays. Using reset on a cursor Array will not reset to the first record. |
Next() | Returns the next object in the array |
Add(Object) | Adds an object to the array in the last position |
Insert(Index, Object) | Adds an object to the array in a specific position |
Remove(Index, Object) | Removes a specific object from the array |
RemoveAll() | Removes all objects and creates an empty array |
Replace(Index, Object) | Replaces an object by index position |
GetObject(Index) | Returns a specific object from the array |
ID | A long value used to uniquely identify the point |
X | The horizontal coordinate of the point |
Y | The vertical coordinate of the point |
Z | The elevation value of the point |
M | The measure value of the point |
Search cursor on a point feature class
# Import native arcgisscripting module # import arcgisscripting # Create the geoprocessor object # gp = arcgisscripting.create(9.3) infc = gp.GetParameterAsText(0) # Identify the geometry field # desc = gp.Describe(infc) shapefieldname = desc.ShapeFieldName # Create search cursor # rows = gp.SearchCursor(infc) row = rows.Next() # Enter while loop for each feature/row # while row: # Create the geometry object 'feat' # feat = row.GetValue(shapefieldname) pnt = feat.GetPart() # Print x,y coordinates of current point # print pnt.x, pnt.y row = rows.Next()
2.0 4.0 8.0 10.0 7.0 5.0
Search cursor on a multipoint feature class
# Import native arcgisscripting module # import arcgisscripting # Create the geoprocessor object # gp = arcgisscripting.create(9.3) infc = gp.GetParameterAsText(0) # Identify the geometry field # desc = gp.Describe(infc) shapefieldname = desc.ShapeFieldName # Create search cursor # rows = gp.SearchCursor(infc) row = rows.Next() # Enter while loop for each feature/row # while row: # Create the geometry object # feat = row.GetValue(shapefieldname) # Print the current multipoint's ID # print "Feature " + str(row.getvalue(desc.OIDFieldName)) + ":" partnum = 0 # Count the number of points in the current multipart feature # partcount = feat.PartCount # Enter while loop for each point in the multipoint feature # while partnum < partcount: # Get the point based on the current part number # pnt = feat.GetPart(partnum) # Print x,y coordinates of current point # print pnt.x, pnt.y partnum += 1 row = rows.Next()
Feature 0: 3.0 8.0 4.0 4.0 6.0 6.0 Feature 1: 5.0 9.0 8.0 10.0 Feature 2: 9.0 5.0
Search cursor on a polygon or line feature class
# Import native arcgisscripting module # import arcgisscripting # Create the geoprocessor object # gp = arcgisscripting.create(9.3) infc = gp.GetParameterAsText(0) # Identify the geometry field # desc = gp.Describe(infc) shapefieldname = desc.ShapeFieldName # Create search cursor # rows = gp.SearchCursor(infc) row = rows.Next() # Enter while loop for each feature/row # while row: # Create the geometry object # feat = row.GetValue(shapefieldname) # Print the current multipoint's ID # print "Feature " + str(row.getvalue(desc.OIDFieldName)) + ":" partnum = 0 # Count the number of points in the current multipart feature # partcount = feat.PartCount # Enter while loop for each part in the feature (if a singlepart feature # this will occur only once) # while partnum < partcount: # Print the part number # print "Part " + str(partnum) + ":" part = feat.GetPart(partnum) pnt = part.Next() pntcount = 0 # Enter while loop for each vertex # while pnt: # Print x,y coordinates of current point # print pnt.x, pnt.y pnt = part.Next() pntcount += 1 # If pnt is null, either the part is finished or there is an # interior ring # if not pnt: pnt = part.Next() if pnt: print "Interior Ring:" partnum += 1 row = rows.Next()
Feature 0: Part 0: 3.0 8.0 1.0 8.0 2.0 10.0 3.0 8.0 Feature 1: Part 0: 5.0 3.0 3.0 3.0 3.0 5.0 5.0 3.0 Part 1: 7.0 5.0 5.0 5.0 5.0 7.0 7.0 5.0 Feature 2: Part 0: 9.0 11.0 9.0 8.0 6.0 8.0 6.0 11.0 9.0 11.0 Interior Ring: 7.0 10.0 7.0 9.0 8.0 9.0 8.0 10.0 7.0 10.0