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??
da Cursors
and writing buffer toin_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 thein_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.newrow = list(row)
,newrow[-1] = newrow[-1].buffer(100)
, then do something with newrow