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?

blah238
35.9k8 gold badges97 silver badges204 bronze badges
asked Oct 10, 2012 at 4:26
2
  • What is the value of spatialReferanceFactoryCode? Commented Oct 10, 2012 at 5:09
  • @om_henners: spatialReferanceFactoryCode = 32146 Commented 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'
answered Oct 10, 2012 at 5:14
5
  • Actually I want to check if the code valid or not. Is there any property that can tell me that? Commented Oct 10, 2012 at 5:25
  • 1
    @Emi Try spatialreference.org (it is by the way) Commented Oct 10, 2012 at 5:35
  • @om_henners: sorry for the misunderstanding. Actually I want to do it programmatically. Commented 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). Commented 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. Commented Aug 31, 2015 at 2:25

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.