change mxd reference from ArcGISonline Basemap Imagery to newly acquired imagery

1715
1
12-27-2012 10:00 AM
ChristopherOneal
New Contributor II
How do I capture the source for the ArcGIS online Bing Imagery currently referenced in a series of mxds so as to change them to a newly acquired image source? I thought that maybe this data is cached and I could access that....not sure where to go from here, but the following code does not work
import arcpy
refLayer = "C:\Users\my_user_name\AppData\Roaming\ESRI\Local Caches\MapCacheV1\maps.live.com_Aerial_en-US\MicrosoftVE" #my guess at the location of the ArcGISONLINE BING IMAGERY
newImage = "G:\GIS\IMAGERY\8-28-2012_Ortho.tif"
mxd = arcpy.mapping.MapDocument(r'G:\GIS\volume1.mxd')
for df in arcpy.mapping.ListDataFrames(mxd):
    for refLayer in arcpy.mapping.ListLayers(mxd, "Bing Maps Aerial", df):
        arcpy.mapping.InsertLayer(df,refLayer,newImage,"BEFORE")
        arcpy.mapping.RemoveLayer(df, refLayer)

print 'finished'
Tags (2)
0 Kudos
1 Reply
JeffBarrette
Esri Regular Contributor
I just tested this using arcpy.mapping.UpdateLayer.

http://resources.arcgis.com/en/help/main/10.1/#/UpdateLayer/00s30000003p000000/

Steps:
- I created a new MXD and added BingMapsAerial.  In the TOC, it is added as Basemap\BingMapsAerial.
- I also added the Esri Imagery basemap (Basemap\World_Imagery).  I right clicked on the BaseMap group name and saved it out to a layer file (Basemap.lyr).
- I removed the Esri basemap (I added it just to create the layer file).
- Next I ran the following code from the Python window in ArcMap:
mxd = arcpy.mapping.MapDocument("current")
df = arcpy.mapping.ListDataFrames(mxd)[0]
lyr = arcpy.mapping.ListLayers(mxd, "Basemap")[0]  #this is the bing group layer
lyrFile = arcpy.mapping.Layer(r"C:\Temp\Basemap.lyr")
arcpy.mapping.UpdateLayer(df, lyr, lyrFile, False)
arcpy.RefreshActiveView()


Jeff
0 Kudos