>>> 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 >>>
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)
Solved! Go to Solution.
>>> 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()
>>> 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()
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)
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()
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)