How to automate map generation using arcpy in ArcMap

306
1
10-30-2020 09:27 AM
VinayDhanvada
New Contributor

I have prepared a python toolbox in ArcMap 10.7 which finally gives a raster layer (vulnerability index) as an output. I update the symbology which needs to be used for the map. I wish to automate map generation (The map should contain the north arrow, legend, scale bar, and title of the map. The final is exporting it to JPEG.

My problem is, I am not able to add any elements to the map. I don't even know where to start. Could someone please help me!

Thanks in advance.

# For displaying the results in arcmap
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "*")[0]

# Adding a map layer
addLayer = arcpy.mapping.Layer(os.path.join(arcpy.env.workspace,"vulnerability_index"))
arcpy.mapping.AddLayer(df, addLayer, "BOTTOM")

# Updating the symbology
updateLayer = arcpy.mapping.ListLayers(mxd,"*",df)[0]
sourceLayer = arcpy.mapping.Layer(Symbology)  #Symbology is a 'DElayer' parameter which we select on the tool interface)
arcpy.mapping.UpdateLayer(df,updateLayer, sourceLayer, True)
addLayer = arcpy.mapping.Layer(os.path.join(arcpy.env.workspace,"vulnerability_index"))


#Adding map elements

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX


# Generate JPEG map
arcpy.mapping.ExportToJPEG(mxd, os.path.join(arcpy.env.workspace,"vulnerability_index.jpeg"),resolution=300)
return

0 Kudos
1 Reply
nita14
by
Regular Contributor

Hi,

You need to have the elements already added to the map. Then, you can manipulates its properties.

Check this one:

https://desktop.arcgis.com/en/arcmap/10.7/analyze/arcpy-mapping/mapsurroundelement-class.htm

BR,

Adam

0 Kudos