3

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?

2
  • What is the value of spatialReferanceFactoryCode?
    – om_henners
    Oct 10, 2012 at 5:09
  • @om_henners: spatialReferanceFactoryCode = 32146
    – Emi
    Oct 10, 2012 at 5:17

1 Answer 1

8

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'
5
  • Actually I want to check if the code valid or not. Is there any property that can tell me that?
    – Emi
    Oct 10, 2012 at 5:25
  • 1
    @Emi Try spatialreference.org (it is by the way)
    – om_henners
    Oct 10, 2012 at 5:35
  • @om_henners: sorry for the misunderstanding. Actually I want to do it programmatically.
    – Emi
    Oct 10, 2012 at 5:56
  • 4
    There is no way to check whether a code is valid without trying to create a coordinate system (spatial reference).
    – mkennedy
    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. Aug 31, 2015 at 2:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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