Sign up ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am using the following code segment to create a spatial reference.

    spatialReferance = arcpy.SpatialReference()
    spatialReferance.factoryCode = spatialReferanceFactoryCode

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?

share|improve this question
What is the value of spatialReferanceFactoryCode? –  om_henners Oct 10 '12 at 5:09
@om_henners: spatialReferanceFactoryCode = 32146 –  Emi Oct 10 '12 at 5:17

1 Answer 1

up vote 7 down vote accepted

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)

    spatialReference.factoryCode = spatialReferenceFactoryCode
except RuntimeError:
    print 'factoryCode is not valid'
share|improve this answer
Actually I want to check if the code valid or not. Is there any property that can tell me that? –  Emi Oct 10 '12 at 5:25
@Emi Try (it is by the way) –  om_henners Oct 10 '12 at 5:35
@om_henners: sorry for the misunderstanding. Actually I want to do it programmatically. –  Emi Oct 10 '12 at 5:56
There is no way to check whether a code is valid without trying to create a coordinate system (spatial reference). –  mkennedy Oct 10 '12 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 Miles-Stimson Aug 31 at 2:25

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.