I have a Shapefile:
A layer file:
And a map document:
How can I add points.shp to map.mxd with the properties of symbology.lyr all using python?
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.Sign up to join this community
I just tested this and it worked!
The layer file that I added, and then changed the data source of, was saved from a layer called dummy that pointed at a dummy.shp file.
import arcpy mxd = arcpy.mapping.MapDocument("C:\\MAPS\\map.mxd") df = arcpy.mapping.ListDataFrames(mxd,"Layers") addLayer = arcpy.mapping.Layer("C:\\SYMBOLOGY\\symbology.lyr") arcpy.mapping.AddLayer(df, addLayer) lyr = arcpy.mapping.ListLayers(mxd,"dummy",df) print lyr.name print lyr.dataSource lyr.replaceDataSource("C:\\DATA\\", "SHAPEFILE_WORKSPACE", "points") lyr.name = "points" print lyr.dataSource print lyr.name mxd.saveACopy("C:\\MAPS\\map2.mxd")
I haven't tested this out, but the easiest way should be to simply rename (or copy) symbology.lyr to points.lyr (the same basename as your shapefile). Generally speaking, when you load a shapefile into ArcMap that has a similarly name Layer file, the symbology of the layer "follows" the raw data (shapefile) and is applied on load.