Select to view content in your preferred language

Trouble editing centralMeridian of spatial reference

2909
4
Jump to solution
02-15-2013 04:42 AM
ChrisMathers
Deactivated User
I was trying to make a nice gif for Valentines day to put on our website of the earth rotating in the Werner projection. I made a map with the Bonne projection and changed the central parallel in ArcMap to 89.9 (wont take 90 for some reason) which gives a Stabius-Werner projection in essence. I wrote up a quick bit of code to kick out a png for each meridian between 0 and 359. I was going to merge them into an animated graphic but I cant seem to get the spatialReference object to update. Its moot since Valentines day was yesterday but Im mad at it now and want to make this work.

Making the change by hand in ArcMap data frame options works but is slow; making the change in IDLE or the python window does nothing.:
>>> import arcpy
>>> MXD = arcpy.mapping.MapDocument(r'C:\GIS Projects\FY13\County\Valentines\valentines_werner.mxd')
>>> DF = arcpy.mapping.ListDataFrames(MXD)[0]
>>> DF.spatialReference.centralMeridian
0.0
>>> DF.spatialReference.centralMeridian = 180.0
>>> DF.spatialReference.centralMeridian
0.0
>>> 


My script does nothing either. I left in commented out ways I tried to feed the number in that also didnt work.:
import arcpy

MXD = arcpy.mapping.MapDocument(r'C:\GIS Projects\FY13\County\Valentines\valentines_werner.mxd')
DF = arcpy.mapping.ListDataFrames(MXD)[0]
 
for CM in range(0,360):
    SR.centralMeridian = CM
    DF.spatialReference = SR
    #DF.spatialReference.centralMeridian = CM
    #DF.spatialReference.loadFromString(u"PROJCS['Sphere_Bonne',GEOGCS['GCS_Sphere',DATUM['D_Sphere',SPHEROID['Sphere',6371000.0,0.0]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Bonne'],PARAMETER['False_Easting',0.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',%d.0],PARAMETER['Standard_Parallel_1',89.9],UNIT['Meter',1.0]];-13065200 -16679400 10000;-100000 10000;-100000 10000;0.001;0.001;0.001;IsHighPrecision"%CM)
    arcpy.mapping.ExportToPNG(MXD,
                              r'C:\GIS Projects\FY13\County\Valentines\%02d.png'%CM,
                              DF,
                              df_export_width = 3000,
                              df_export_height = 3000,
                              resolution=300)
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JeffMoulds
Esri Contributor
Try the following...In this example, I am setting the central meridian to "10" in the python window in ArcMap

>>> import arcpy.mapping as ma
>>> mxd = ma.MapDocument('current')
>>> df = ma.ListDataFrames(mxd)[0]
>>> print df.spatialReference.name
World_Bonne
>>> sr = df.spatialReference
>>> spref = sr.exportToString()
>>> print spref
PROJCS['World_Bonne',GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Bonne'],PARAMETER['False_Easting',0.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',0.0],PARAMETER['Standard_Parallel_1',60.0],UNIT['Meter',1.0]];-13065600 -16656200 341910580.382075;-100000 10000;-100000 10000;0.001;0.001;0.001;IsHighPrecision
>>> SR_list = spref.split(",")
>>> print SR_list[15]
PARAMETER['Central_Meridian'
>>> print SR_list[16]
0.0]
>>> SR_list[16] = "10" + "]" # central meridian = 10
>>> SR_outstring = ",".join(SR_list)
>>> print SR_outstring
PROJCS['World_Bonne',GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Bonne'],PARAMETER['False_Easting',0.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',10],PARAMETER['Standard_Parallel_1',60.0],UNIT['Meter',1.0]];-13065600 -16656200 341910580.382075;-100000 10000;-100000 10000;0.001;0.001;0.001;IsHighPrecision
>>> sr.loadFromString(SR_outstring)
>>> df.spatialReference = sr
>>> arcpy.RefreshActiveView()

View solution in original post

0 Kudos
4 Replies
JeffMoulds
Esri Contributor
Try the following...In this example, I am setting the central meridian to "10" in the python window in ArcMap

>>> import arcpy.mapping as ma
>>> mxd = ma.MapDocument('current')
>>> df = ma.ListDataFrames(mxd)[0]
>>> print df.spatialReference.name
World_Bonne
>>> sr = df.spatialReference
>>> spref = sr.exportToString()
>>> print spref
PROJCS['World_Bonne',GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Bonne'],PARAMETER['False_Easting',0.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',0.0],PARAMETER['Standard_Parallel_1',60.0],UNIT['Meter',1.0]];-13065600 -16656200 341910580.382075;-100000 10000;-100000 10000;0.001;0.001;0.001;IsHighPrecision
>>> SR_list = spref.split(",")
>>> print SR_list[15]
PARAMETER['Central_Meridian'
>>> print SR_list[16]
0.0]
>>> SR_list[16] = "10" + "]" # central meridian = 10
>>> SR_outstring = ",".join(SR_list)
>>> print SR_outstring
PROJCS['World_Bonne',GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Bonne'],PARAMETER['False_Easting',0.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',10],PARAMETER['Standard_Parallel_1',60.0],UNIT['Meter',1.0]];-13065600 -16656200 341910580.382075;-100000 10000;-100000 10000;0.001;0.001;0.001;IsHighPrecision
>>> sr.loadFromString(SR_outstring)
>>> df.spatialReference = sr
>>> arcpy.RefreshActiveView()
0 Kudos
ChrisMathers
Deactivated User
Well it seems that making edits to a spatial reference object and setting that whole object as the .spatialReference attribute of the dataframe works. Trying to directly edit the one already part of the dataframe wasnt doing the trick.

import arcpy


MXD = arcpy.mapping.MapDocument(r'C:\GIS Projects\FY13\County\Valentines\valentines_werner.mxd')
DF = arcpy.mapping.ListDataFrames(MXD)[0]
SR = DF.spatialReference


for CM in range(0,360):
    SR.loadFromString(u"PROJCS['Sphere_Bonne',GEOGCS['GCS_Sphere',DATUM['D_Sphere',SPHEROID['Sphere',6371000.0,0.0]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Bonne'],PARAMETER['False_Easting',0.0],PARAMETER['False_Northing',0.0],PARAMETER['Central_Meridian',%d.0],PARAMETER['Standard_Parallel_1',89.9],UNIT['Meter',1.0]];-13065200 -16679400 10000;-100000 10000;-100000 10000;0.001;0.001;0.001;IsHighPrecision"%CM)
    DF.spatialReference = SR
    arcpy.mapping.ExportToPNG(MXD,
                              r'C:\GIS Projects\FY13\County\Valentines\%02d.png'%CM,
                              DF,
                              df_export_width = 3000,
                              df_export_height = 3000,
                              resolution=300)
0 Kudos
curtvprice
MVP Esteemed Contributor

My problem with this is I don't seem to be able to change the central meridian although the help says it is writable.

from arcpy import mapping as am
mxd = am.MapDocument("CURRENT")
df = am.ListDataFrames(mxd)[0]
>>> SR = df.spatialReference
>>> SR.centralMeridian
-85.0
>>> SR.centralMeridian = -100
>>> SR.centralMeridian
-85.0

I'm really wondering what we are missing here. Something important I think!

UPDATE: I was able to do the workaround as well. Here's the python function to do this I came up with. The question is WHY?

def cmerid(sr, merid):
  srs = sr.exportToString()
  pos = srs.find("Central_Meridian',") + len("Central_Meridian',")
  pos2 = pos + srs[pos:].find("]")
  srs1 = "{}{}{}".format(srs[:pos], merid, srs[pos2:])
  SR = arcpy.SpatialReference()
  return SR.loadFromString(srs1)

from arcpy import mapping as am
mxd = am.MapDocument("CURRENT")
df = am.ListDataFrames(mxd)[0]    
sr = df.spatialReference
df.spatialReference = cmerid(sr, -100.0)
arcpy.RefreshActiveView()
0 Kudos
DanPatterson_Retired
MVP Emeritus

what are the names or number of the coordinate systems? (even though it shouldn't matter)

have you tried to create (create() ) from the desired parameters rather than alter an existing one (unless the help has a cavaet)

0 Kudos