Modify Spatial Reference Object

887
1
06-15-2011 11:42 AM
GregYetman
Occasional Contributor
Hi,

I want to modify a spatial reference object to change the central meridian of a Mollweide projection. The documentation for the Spatial Reference Object lists the centralMeridian property as read-write but when I try and modify it the value doesn't change. Am I missing something obvious?

Code below. Running ArcGIS 10, SP2.

The code below runs with no errors:

import arcpy
outputPrj = r'C:\Program Files (x86)\ArcGIS\Desktop10.0\Coordinate Systems\Projected Coordinate Systems\World\Mollweide (world).prj'
spatialRef = arcpy.SpatialReference(outputPrj)
print 'central meridian', spatialRef.centralMeridian
spatialRef.centralMeridian = -70.1
print 'modified ref central meridian', spatialRef.centralMeridian

and it prints the text below, showing that the property hasn't changed:

central meridian 0.0
modified ref central meridian 0.0
Tags (2)
0 Kudos
1 Reply
KimOllivier
Occasional Contributor III
The spatial reference object is read-only. See the old Geoprocessor Programming Model 9.3 PDF.

One way to change the central meridian is to manually edit and save a modified spatial reference file after editing in ArcCatalog.

Otherwise you have to dump the parameters to a string, do a search and replace and then create an object from the complex string object. I can't believe that this is as intended.

import arcpy
outputPrj = r'C:\temp\Mollweide (world).prj'
spatialRef = arcpy.SpatialReference()
spatialRef.createFromFile(outputPrj)
stRef = spatialRef.exportToString()
stRef = stRef.replace("Central_Meridian',0.0","Central_Meridian',-70.1")
spRef2 = arcpy.SpatialReference()
spRef2.loadFromString(stRef)
print spRef2.name,spRef2.centralMeridian


I see that the ArcGIS 10 help suggests some spatial reference properties are read/write. But ArcGIS 9.3 marks them all as read-only. I thought that it may be that sourcing from a protected directory may make them read-only, but that was not the case. I also tried creating from a factory code, setting properties and using sr.create() (which is necessary) but the properties are still read-only.
0 Kudos