ss_whaleman

Rotating the Earth in a data frame to reflect a user-selected country

Discussion created by ss_whaleman on Dec 29, 2011
Latest reply on Dec 30, 2011 by ss_whaleman
I have two data frames, one is a location map.  The Spatial Reference for the location map data frame is World from Space.  The user selects a country from a toolbox script.  I calculate the center of the selected country from its extent and would like to use the X and Y of that center point as the Longitude of Center and Latitude of Center for the Spatial Reference, so the earth rotates and the selected country is in the center of the view.  The output from the program is:

==============================
DataFrame Found: Location_Map
Layers DataFrame was found: Location_Map
The layer found: WORLD_COUNTRIES
"NAME" = 'Guatemala'
Center X: -90.2294998169
Center Y: 15.7832899094
PROJCS['The_World_From_Space',GEOGCS['GCS_Sphere_ARC_INFO',DATUM['D_Sphere_ARC_INFO',SPHEROID['Sphere_ARC_INFO',6370997.0,0.0]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Orthographic'],PARAMETER['False_Easting',0.0],PARAMETER['False_Northing',0.0],PARAMETER['Longitude_Of_Center',-72.5333333334],PARAMETER['Latitude_Of_Center',42.5333333333],UNIT['Meter',1.0]];-7008096.68738543 -7008096.68738543 642628066.972445;-100000 10000;-100000 10000;0.001;0.001;0.001;IsHighPrecision
==================================
PROJCS['The_World_From_Space',GEOGCS['GCS_Sphere_ARC_INFO',DATUM['D_Sphere_ARC_INFO',SPHEROID['Sphere_ARC_INFO',6370997.0,0.0]],PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]],PROJECTION['Orthographic'],PARAMETER['False_Easting',0.0],PARAMETER['False_Northing',0.0],PARAMETER['Longitude_Of_Center',-90.2294998169],PARAMETER['Latitude_Of_Center',15.7832899094],UNIT['Meter',1.0]];-7008096.68738543 -7008096.68738543 642628066.972445;-100000 10000;-100000 10000;0.001;0.001;0.001;IsHighPrecision
========================

The first Spatial Reference is the result of exportToString(), the second is the result fed into loadFromString().  Unfortunately, after running the program, the data frame Spatial Reference does not change.  Is this the wrong approach?  Any suggestions??  Thanks


import arcpy
arcpy.AddMessage("Begin Processing:")
country_selected = arcpy.sys.argv[1] #country name as String
arcpy.AddMessage(country_selected + "...")
arcpy.env.workspace = r"D:\temp"
mxd = arcpy.mapping.MapDocument("CURRENT")
arcpy.AddMessage("=============")
volc_list = []
SR_list = []

for df in arcpy.mapping.ListDataFrames(mxd):
    arcpy.AddMessage("DataFrame Found: " + df.name)
    
    if df.name == "Location_Map":
        mxd.activeView = df.name
        arcpy.AddMessage("Layers DataFrame was found: " + df.name)
        for lyr in arcpy.mapping.ListLayers(mxd,"",df):
            
            if lyr.name == "WORLD_COUNTRIES":
                arcpy.AddMessage("The layer found: " + lyr.name)
                expression = ""'"NAME"'" = '"+country_selected+"'"
                arcpy.AddMessage(expression)
                arcpy.SelectLayerByAttribute_management(lyr,"NEW_SELECTION",expression)
                countryextent = lyr.getSelectedExtent()
                minX = countryextent.XMin
                minY = countryextent.YMin
                maxX = countryextent.XMax
                maxY = countryextent.YMax
                difX = (maxX - minX) / 2
                difY = (maxY - minY) / 2
                cenX = minX + difX
                cenY = minY + difY
                arcpy.AddMessage("Center X: " + str(cenX))
                arcpy.AddMessage("Center Y: " + str(cenY))
                spref = df.spatialReference.exportToString()
                arcpy.AddMessage(spref)
                SR_list = spref.split(",")
                SR_list[16] = str(cenX) + "]" # long of center
                SR_list[18] = str(cenY) + "]" # lat of center
                SR_outstring = ",".join(SR_list)
                arcpy.AddMessage("==================================")
                arcpy.AddMessage(SR_outstring)
                df.spatialReference.loadFromString(SR_outstring)
                arcpy.RefreshActiveView()

Outcomes