Add basemap by arcpy (python)

4403
2
04-14-2014 02:12 PM
TakeoShibata
New Contributor
Hi All

I am wondering how to add Base Map by arcpy.
It is such a simple operation if you use ArcGIS Desktop GUI

But I am wondering how to do the same in arcpy code.
[ATTACH=CONFIG]33091[/ATTACH]
Tags (2)
0 Kudos
2 Replies
MattEiben
Occasional Contributor
If you add one of those basemaps to your ArcMap session, you can right click on the "Basemap" group layer on your Table of Contents and save a .lyr file to your system somewhere.  (Use the "Save As Layer File..." button) Then you could run something like this in your script to add it to your map.

basemapLayer = arcpy.mapping.Layer(path_to_your_basemap_lyr_file)

mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "*")[0]

arcpy.mapping.AddLayer(df, basemapLayer, "BOTTOM")


Of course, the downside to this method is you'd need a copy of the .lyr file for that basemap somewhere on your system.

Matt
PedroHenrique_de_Aquino_Bravin
Esri Contributor

Hi Matt,

Thank you for put this process in a script form, it is very useful!

Best regards,
Pedro Bravini

0 Kudos