I am using the following code segment to create a spatial reference.
spatialReferance = arcpy.SpatialReference()
spatialReferance.factoryCode = spatialReferanceFactoryCode
spatialReferance.create()
But it gives the following error:
Runtime error : ERROR 999999: Error executing function. the input string is not a geographic or projected coordinate system
How can I programmatically determine whether a factory code is valid or not?
Answer
See Do ArcGIS SpatialReference object factory codes correspond with EPSG numbers? in particular @mkennedy and @blah238 answers.
As to whether a factory code is valid or not... In Python, you can use the EAFP method (Easier to Ask for Forgiveness than Permission)
try:
spatialReference.factoryCode = spatialReferenceFactoryCode
spatialReference.create()
except RuntimeError:
print 'factoryCode is not valid'
No comments:
Post a Comment