Over the past decade, GIS professionals who can manipulate the software both manually and automatically are becoming increasingly more marketable within the industry. Automating mundane/repetitive tasks frees up time to focus on more advanced analyses and other GIS processes.
On one of our current contracts, we are required to create map products in response to “breaking news” events. These maps provide situational awareness to our client regarding the status of assets within their area of jurisdiction. Time is of the essence during these events, and the faster a map product can go out, the better.
Since the maps generated for these events are all formatted identically, I decided to create a Python script, coupled with a detailed and specific ArcMap MXD template, to perform most of the ground work associated with their creation.
I originally wrote a stand-alone Python script that was run solely using the IDLE window. While this achieved the results I wanted, I knew I could make it more user-friendly. I then created a shortcut on the desktop that connected to the script and launched the file upon user-double-click. I then pointed the shortcut to a faux-executable file that I pinned to the taskbar. Finally, to improve efficiency, I connected the script to a tool for use within ArcMap/ArcCatalog. I did this to make it look similar to the tool suite that my coworkers often use.
The Python script:
- Prompts the user to define the workspace
- Creates folders inside that workspace
arcpy.CreateFolder_management(workspace, projectFolder) arcpy.CreateFolder_management(projectFolder, dataFolder) arcpy.CreateFolder_management(projectFolder, mxdFolder) arcpy.CreateFolder_management(projectFolder, pdfFolder)
- Gets latitude/longitude from user
- Uses latitude/longitude to generate a point
- Projects the point to WGS 1984
sr = arcpy.SpatialReference(4326) infc = r"DataEvent.shp" arcpy.DefineProjection_management(infc, sr)
- Adds fields to the point feature class (Event.shp)
- Puts information into those fields (latitude, longitude, and name or event name)
- Creates 1, 2, 5, and 10 mile buffers around the point
- Adds fields and attributes into the four resulting buffer data sets
- Replaces source paths of dummy layers sitting in the template (Quicklook_Template_11x17) MXD’s main data frame with those of the newly created Event.shp , OneMileBuffer.shp, TwoMileBuffer.shp, FiveMileBuffer.shp, and TenMileBuffer.shp
- Zooms main data frame to location of One Mile Buffer
- Adds the one mile buffer to the locator map and pans the locator map to the location of the one mile buffer
- Reprojects the Main Data Frame to the proper NAD 1983 UTM Zone based upon the longitude of the point obtained from the user, using an if statement
- Turns on relevant layers in the locator map and the main data frame (Site of Interest, Basemap, Event, and One Mile Buffer, etc.)
- Updates map title with the user supplied information
- Updates location of event with user supplied information
- Obtains system time yyyymmdd for input into the file name with the title and other information
- Saves a copy of the new file as (Quicklook_yyyymmdd_Title.mxd)
time = str(datetime.datetime.now()) time = time[:4]+time[5:7]+time[8:10] mxd.saveACopy(workspace + "/" + projectFolder + "MXDQuicklook_" + time + "_" + title + ".mxd")
- Launches the ArcMap application and opens the newly generated file for further editing.
- The entire process takes roughly 10 seconds to run.
- Has a dynamically updated timestamp based upon the system time
- Has an option to source a picture of the event using a URL
- Is connected to relevant background data (our basemap and some point datasets we use)
- Has “dummy layers” that contain all the symbol and labeling standards for the One Mile Buffer and Event, which then just have their data source replaced based upon the new data created by the user
- Has a graphic legend to the side of the layout for those who prefer to use it
- Has an auto-generating legend in the layout that pulls from the event, one mile buffer, and Site of Interest data in the Main Data Frame (only classes of items that are within the visible extent). If the user should decide to zoom/pan, the legend will change depending on the resultant data shown.
- The auto-generating legend produces symbols and text that is the same size as the graphic legend
The ArcGIS tool:
- Connects to the Python script on disk
- Uses input parameters to set values of the variables in the Python script
- Set the General Workspace (folder)
- Enter the Title for the Map (string)
- Enter the Latitude (double)
- Enter the Longitude (double)
- Enter the Name of the Event (string)
- Enter the Location of the Event (string)
- Contains descriptions or help regarding each input parameter so the user knows what to input for each
- Once the user clicks “run” the tool runs the script and generates the map
Shown is a generalized version of the map that is created from the template.
This post was written by: