I want to create my own projected coordinate system based on one of geographical coordinate systems and set custom values to properties as longitude, scaleFactor etc.

I found SpatialReference class.

But can't understand how set geographical coordinate system that will be base for my coordinate system - GCS property is read only, and no methods for set its value.

And also, when I calls create method, result is RuntimeError: ERROR 999999: Error executing function.

Article has example with only reading existing property, but hasn't examples with creating CS.

What am I doing wrong, and where can I find examples for CS creating?

My code:

new_sr = arcpy.SpatialReference()
new_sr.linearUnitName = u'meters'
new_sr.longitude = 30
new_sr.longitudeOf1st = 10
new_sr.longitudeOf2nd = 50
new_sr.longitudeOfOrigin = 30
new_sr.projectionCode = 100500
new_sr.projectionName = u'my_projection'
new_sr.scaleFactor = 2
new_sr.standardParallel1 = 50
new_sr.standardParallel2 = 60
new_sr.create() # RuntimeError: ERROR 999999: Error executing function

May be I must set some other properties, or vice versa remove unnessecary?

  • Well, you have too many parameters for one. The projectionCode and projectionName are the map projection algorithm you want to use like 43020 or "Lambert_Conformal_Conic." 100500 isn't valid. Look in the Documentation folder for projected_coordinate_systems.pdf for the list of projections and parameters that are used with each one. – mkennedy Nov 6 '15 at 17:27
  • Thanks, JamesSLC already answered. And code from my question is non-working because arcpy.SpatialReference can't change values for some reason (this magic is described in article), not only because of wrong parameters count or values – General Failure Nov 7 '15 at 5:20

To answer your initial question, 'how set geographical coordinate system that will be base for my coordinate system - GCS property is read only, and no methods for set its value'

You can use a numeric code for either a projected or geographic coordinate system when creating the Spatial Reference Object, like this:

sr = arcpy.SpatialReference(104926)

ESRI provides a list of projected and geographic coordinate systems and their numeric codes here. I used 104926 it is the code for GCS_Atlas_2000 which is a geographic coordinate system. When you initiate a Spatial Reference object with a numeric code a valid Spatial Reference Object is returned. You can then access its properties. Editing a Spatial Reference Object can be quite tricky (see here), however you can pick and choose the properties you want from the created spatial reference to populate your custom spatial reference.

At the very least you can export your base spatial reference with sr.exportToString() and manually edit the properties you want to change in the string and/or file you output the string to. Definitely not ideal, but it will get the job done.


You may be interested in the recently added arcpy.GenerateOptimalCoordinateSystem function, see doc at https://pro.arcgis.com/en/pro-app/latest/arcpy/functions/generateoptimalcoordinatesystem.htm.

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.