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?
1 Answer 1
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'
-
Actually I want to check if the code valid or not. Is there any property that can tell me that?Emi– Emi2012年10月10日 05:25:36 +00:00Commented Oct 10, 2012 at 5:25
-
1@Emi Try spatialreference.org (it is by the way)om_henners– om_henners2012年10月10日 05:35:38 +00:00Commented Oct 10, 2012 at 5:35
-
@om_henners: sorry for the misunderstanding. Actually I want to do it programmatically.Emi– Emi2012年10月10日 05:56:38 +00:00Commented Oct 10, 2012 at 5:56
-
4There is no way to check whether a code is valid without trying to create a coordinate system (spatial reference).mkennedy– mkennedy2012年10月10日 17:28:31 +00:00Commented Oct 10, 2012 at 17:28
-
+1 for EAFP method. That is so python! Try to do it and catch it if it breaks.. there isn't a IsNumeric for strings in python (off topic but related) possibly because you can find out in the same way.Michael Stimson– Michael Stimson2015年08月31日 02:25:08 +00:00Commented Aug 31, 2015 at 2:25
Explore related questions
See similar questions with these tags.
spatialReferanceFactoryCode
?