Take the 2-minute tour ×
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
    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?

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
add comment

1 Answer

up vote 5 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)

try:
    spatialReference.factoryCode = spatialReferenceFactoryCode
    spatialReference.create()
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
1  
@Emi Try spatialreference.org (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
3  
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
add comment

Your Answer

 
discard

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.