I know ArcPy allows you to access geometries directly using the CopyFeatures_management method. Note in their code sample for the Geometry object, it is very simple to copy the geometries to in-memory objects of type Geometry (and extremely fast). The geometry object of course relates to the geometry/shape and completely bypasses attribute information.

My question is whether there is a way to identify the OID of each geometry cheaply?

A little background in what I am trying to perform:

  1. For all feature classes in a geodatabase
  2. Read through each feature's geometry
  3. Go over the points in the geometry
  4. Calculate the distances between the points
  5. If the distance is below a threshold, that specific feature needs to marked for review (meaning I need either the OID/FID or any other field to identify it).

As I am still in ArcGIS 10.0, I would prefer to not use cursors that seem to work a lot slower than simply dealing with the geometries.

  • Can you tell us why you are doing this? Presumably you are looking to remove excess vertices or simplify polygons. – blah238 Oct 25 '12 at 21:40
  • Also when you say "If the distance is below a threshold", is "the distance" ANY of the distances between any consecutive pair of vertices, a sum of all of the distances (perimeter) or some other measurement? – blah238 Oct 25 '12 at 21:44
  • How are you currently looping over each feature in a feature class other than with a cursor? – blah238 Oct 25 '12 at 21:46
  • Presuming you ARE currently using a cursor, have you tried specifying just the SHAPE and OBJECTID fields for the cursor's fields argument? – blah238 Oct 25 '12 at 21:47
  • 1
    @blah238 Let me try and answer all your questions. 1) I am trying to remove excess vertices. Visually, I noticed ~300 vertices following a (visually straight) road of ~100 feet length (this seems excessive). 2) The distance below a threshold is the distance between two consecutive vertices (pnt1 to pnt2, pnt2 to pnt3, etc). 3) Right now I am looping only through the geometries by using a geometry list (see the example in the Geometry link above). 4) I am not using a cursor, as even a cursor with simply SHAPE and OID attributes is extremely slow compared with the geometry method alone. – Michalis Avraam Oct 25 '12 at 21:57

You can't determine the OID directly from the geometry object, it doesn't know anything about it. The row object in a cursor has that field, just use row.OID in your cursor.

You probably want to just Generate a Near Table and then Select by Attributes on the new table against the distance field to find geometries that are too close ([]NEAR_DIST] < X). Once you've run select by attributes you can use a cursor to iterate over only the OIDs that matter:

oids = set()
for row in arcpy.SearchCursor(r'in_memory\new_near_table'):

And from there you can select by attributes on the original table:

arcpy.management.SelectLayerByAttribute("original_lyr", "NEW_SELECTION", 'OID in (%s)' % (', '.join(str(oid) for oid in sorted(oids))))
  • Thank you for the answer, but I am trying to avoid using cursors to solve this problem as they are extremely slow in 10. A Near Table would work if the FCs where points, these are all polygons though. Perhaps a polygon to point, and then Near would do the trick though. Thanks! – Michalis Avraam Oct 25 '12 at 19:07
  • The near tools work on every geometry type, not just points. – Jason Scheirer Oct 25 '12 at 19:31
  • They do work on every geometry type, but if I run a Near Tool on a polygon it will not report back the distances between each vertex in the polygon. – Michalis Avraam Oct 25 '12 at 19:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.