0

We have a database containing line segments.

Due to certain particularities in our project, we need to perform some analysis operations line by line instead of just performing the operation in the whole feature class (please don't question this seemingly bad decision, this is not the scope of this question and we have our reasons for doing that).

Now, this cerainly leads to a performance penalty (of course).

When performing the analysis (such as using arcpy.Buffer_analysis), a new feature class is created, and we need to access the results via cursor.

fields= ["OID@", "SHAPE@", ....]
with arcpy.da.SearchCursor(table, fields) as cursor:
    for line in cursor:
        shape = line[1]    

        #here, a feature class is being created, but I just wanted the buffer feature itself
        buffer = arcpy.Buffer_analysis(shape, r'in_memory\Buffer', DistBUFFER, "FULL", "FLAT")

        #here we need to use a cursor to access the created buffer
        with arcpy.da.SearchCursor(buffer, otherFields) as anotherCursor:
            ... do stuff ...

Is there a way to use the analysis functions without creating a new feature class? I mean, make the analysis return the objects directly in a list in the buffer variable, bypassing the create feature and use cursor steps??

3
  • 4
    From your script - using the da Cursors and writing buffer to in_memory -- you're following all the best practices. I don't see anyway you could really optimize that. You could look at using the Geometry functions > buffer -- but its hard to say if that'll show much performance improvement vs the in_memory result of the tool. I think the size and complexity of your data will determine if using the geometry functions is worthwhile or not.
    – KHibma
    Commented May 2 at 13:49
  • Can you buffer the geometry only? newrow = list(row) , newrow[-1] = newrow[-1].buffer(100), then do something with newrow
    – Bera
    Commented May 2 at 14:08
  • Might be worth reading Using geometry objects with geoprocessing tools - ArcGIS Pro | Documentation, it seems similar or related to what you are trying to do.
    – bixb0012
    Commented May 2 at 14:24

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.