I have a script that creates a polyline geometry from scratch using some math to generate coordinate pairs. At the same time, there is a user-defined polygon shapefile that is used to "erase" the polylines. Doing this using the low-level geometry methods (e.g. http://bit.ly/1vBMSjP under the "Methods" section) is much, much faster than using feature classes (e.g. arcpy.Erase_analysis). However I am trying to figure out the fastest way to assign a projection to the un-projected polyline geometry coordinates. Is there a way to set a default projection for all processing in arcpy?
I want to use this geometry operator to erase the polyline geometry:
However this fails if both geometry objects do not have the same projection. So my question is, is it possible to set a default projection for all geometry and arcpy operations, so that a new geometry created from scratch will be assumed to have that projection?
For reference, below are the three strategies that I have used so far to assign a projection to the geometry, since I have not been able to figure out how to assign a default projection.
use the "Define Projection" function
where lineGeometry is a Polyline geometry object created from calculated coordinates, and SpatialReference is read from the polygon shapefile. This is very slow (possibly because the geometry is converted to a feature class internally, then back to a geometry).
copy the line geometry into a pre-existing polyline feature class with a defined projection, then copy it back to a geometry list object. Oddly enough this is much faster than #1 above.
g = arcpy.Geometry() arcpy.CopyFeatures_management(lineGeometry,linesTemp) lineProjected = arcpy.CopyFeatures_management(linesTemp, g) currentLine = linesTemp
Use a polyline feature class with a defined projection, with only one polyline feature in it. Then, copy the line geometry directly into the SHAPE field of the existing polyline feature, overwriting the existing geometry. Then copy it back to a geometry list object. This is the fastest method I have found so far.
g = arcpy.Geometry() with arcpy.da.UpdateCursor(linesTemp,["SHAPE@"]) as cursor: for row in cursor: row = lineGeometry #Update the current cursor with the changes cursor.updateRow(row) #Copy the projected line feature back out into a geometry list lineProjected = arcpy.CopyFeatures_management(linesTemp, g) #Get the actual line geometry from the geometry list lineGeometry= lineProjected