Export specific polygons to jpeg

213
2
06-18-2021 05:53 PM
Kvbass
by
New Contributor

ArcGIS 10.1

Hello, I am new to using python. I have figured out how to export specific maps as a jpeg.

What I am trying to do now is use python to zoom into a specific polygon in the data view and export it as a jpeg with the polygon's name.

For context, this will involve multiple polygons within the same shapefiles and will also need to account for multiple shapefiles of this nature. 

Help with this would be greatly appreciated !

 

import arcpy
from arcpy import env
from arcpy import mapping
env.workspace = "CURRENT"


mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
for lyr in arcpy.mapping.ListLayers(mxd):

Tags (2)
0 Kudos
2 Replies
DavidPike
MVP Frequent Contributor

Are you aware of Creating Data Driven Pages—Help | ArcGIS for Desktop or is this just an arcpy learning exercise?

0 Kudos
DavidPike
MVP Frequent Contributor

from Combining Data Driven Pages with Python and arcpy.mapping (esri.com) 

'The following example zooms to a selected parcel, toggles on different layer visibility and exports the layout for multiple themes in order to create a parcel report with a soil map, a flood map and a zoning map:'

 

import arcpy, os

#Specify output path and final output PDF
outPath = r”C:MyProjectoutput\”
finalPdf = arcpy.mapping.PDFDocumentCreate(outPath + “ParcelReport.pdf”)

#Specify the map document and the data frame
mxd = arcpy.mapping.MapDocument(r”C:MyProjectMyParcelMap.mxd”)
df = arcpy.mapping.ListDataFrames(mxd, “Layers”)[0]

#Select a parcel using the LocAddress attribute and zoom to selected
parcelLayer = arcpy.mapping.ListLayers(mxd, “Parcels”, df)[0]
arcpy.SelectLayerByAttribute_management(parcelLayer, “NEW_SELECTION”, “”LocAddress” = ’519 Main St’”)
df.zoomToSelectedFeatures()

#Turn on visibility for each theme and export the page
lyrList = [“Soils”, “Floodplains”, “Zones”]
for lyrName in lyrList:
  lyr = arcpy.mapping.ListLayers(mxd, lyrName, df)[0]
  lyr.visible = True

  #Export each theme to a temporary PDF and append to the final PDF
  tmpPdf = outPath + lyrName + “_temp.pdf”
  if os.path.exists(tmpPdf):
  os.remove(tmpPdf)
  arcpy.mapping.ExportToPDF(mxd, tmpPdf)
  finalPdf.appendPages(tmpPdf)

  #Turn off layer visibility and clean up for next pass through the loop
  lyr.visible = False
  del lyr, tmpPdf
del mxd, df, finalPdf