Scan Dataset and Exporting Maps

933
4
Jump to solution
03-09-2017 01:15 PM
MichelConn1
New Contributor II

I am looking for an automated way to scan through a dataset, panning to the location of each observation on the map, then take a picture of that observation, and then name the picture after one of the variables.

I am thinking that python is going to be my best best for accomplishing this with a for loop but am unsure of functions would be able to accomplish this. I have some experience with python but not a lot of experience with ArcGIS and python. You can see an example below of the type of picture I want to take. I don't have to select each observation like in the picture but that would be nice.

Thanks 

 

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
MichelConn1
New Contributor II

I was able to cobble together some working code from the links you gave thanks.

mxd = arcpy.mapping.MapDocument('CURRENT')
df = arcpy.mapping.ListDataFrames(mxd, "Layers") [0]
OutputLocation=r"\\mriglobal\kcshares\Projects\311190\STATISTICAL ANALYSIS\PLOTS"
Layer = "Export_Output"
cursor = arcpy.SearchCursor(Layer)

for row in cursor:
 FID_txt=str(row.getValue('FID'))
 arcpy.SelectLayerByAttribute_management(Layer, "NEW_SELECTION" , "FID = " + FID_txt) 
 df.zoomToSelectedFeatures() 
 if df.scale<2000 and df.scale>300: 
    df.scale=2000
 if df.scale<300:
    df.scale=1000
 arcpy.RefreshActiveView()
 arcpy.mapping.ExportToJPEG(mxd, OutputLocation + '/' + row.getValue('SRI') + ".jpg", df, 1920, 1080) 
 arcpy.SelectLayerByAttribute_management(Layer, "CLEAR_SELECTION")

View solution in original post

0 Kudos
4 Replies
IanMurray
Frequent Contributor

Hi Michel,

I would look into using cursors to access the data you need for each record in your dataset and reading them to a list(if you only need one value per dataset) or a dictionary if you need more than one.

I would then probably iterate through the list/dictionary and create a defintion query to your layer in your map document using the value(s) as needed, zoom to the feature, zoom back out to a set scale(if you are working with points you will definitely want to zoom back out, polygons you might want to zoom out by a certain amount).  After you have the extent set how you want, export out to whichever format works for you.

Some handy links:

Introduction to the Arcpy Mapping Modules.

https://community.esri.com/external-link.jspa?url=http%3A%2F%2Fdesktop.arcgis.com%2Fen%2Fdesktop%2Fl...

Introduction to arcpy.da.SearchCursor:

http://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&cad=rja&uact=8&sqi=2&ved=0ahUKEwjokLj...

Thread where I posted some code for creating several maps from a single dataset with many records with many values.  Please note I used a slightly different method then, but gives you some ideas for flow and syntax.

https://community.esri.com/thread/160192

Richard Fairhurst excellent blog post about using cursors and dictionaries for data manipulation.  Should help with using cursors and reading in all the data you will need.  I would highly recommend only using the cursors for creating the list/dictionaries of data, since doing alot of geoprocessing while in a cursor tends to bog things down.

https://community.esri.com/blogs/richard_fairhurst/2014/11/08/turbo-charging-data-manipulation-with-...

Arcpy Tool for exporting to PDF:

http://desktop.arcgis.com/en/arcmap/10.3/analyze/arcpy-mapping/exporttopdf.htm

Alternatively, look into Data Driven Pages.

https://community.esri.com/thread/160192

Regards,

Ian

MichelConn1
New Contributor II

Thanks for the response Ian. I'll start looking into this information and see if I can't figure something out. 

0 Kudos
IanMurray
Frequent Contributor

This should be relatively straight forward, I feel a little bad throwing so many links at you.  I know there was another thread on GeoNet for zooming and exporting at multiple scales that is a bit more relevant, but I don't have it bookmarked like some of the others.  I'll dig around and see if I can find it.

Edit: Not so hard to find apparently, though this one is for a script tool. 

https://community.esri.com/thread/95438

MichelConn1
New Contributor II

I was able to cobble together some working code from the links you gave thanks.

mxd = arcpy.mapping.MapDocument('CURRENT')
df = arcpy.mapping.ListDataFrames(mxd, "Layers") [0]
OutputLocation=r"\\mriglobal\kcshares\Projects\311190\STATISTICAL ANALYSIS\PLOTS"
Layer = "Export_Output"
cursor = arcpy.SearchCursor(Layer)

for row in cursor:
 FID_txt=str(row.getValue('FID'))
 arcpy.SelectLayerByAttribute_management(Layer, "NEW_SELECTION" , "FID = " + FID_txt) 
 df.zoomToSelectedFeatures() 
 if df.scale<2000 and df.scale>300: 
    df.scale=2000
 if df.scale<300:
    df.scale=1000
 arcpy.RefreshActiveView()
 arcpy.mapping.ExportToJPEG(mxd, OutputLocation + '/' + row.getValue('SRI') + ".jpg", df, 1920, 1080) 
 arcpy.SelectLayerByAttribute_management(Layer, "CLEAR_SELECTION")
0 Kudos