1

I have a table with 50k entries. There is a to field and from field with location in either lat/lng or street address. All these location are in the USA

I would now like to automate the creation of unique jpg maps for each entry showing the route to get from point a to b. I have a ArcGIS 10 license along with spatial analyst (not sure if these will help).

Any suggested workflows to automate the creation of these maps?

2
  • 1
    I actually just wrote a script that loops over the features and exports the layout view for each feature to PNG. Would something like this be useful?
    – Paul
    Aug 9, 2013 at 16:51
  • 1
    Paul.. That would likely help. Automating the routing and showing a path on street data will also be important.
    – jotamon
    Aug 9, 2013 at 16:52

1 Answer 1

4

The following code is part of a Python toolbox for 10.1. The Scale parameter is used to set the scale for panning and the Scale Factor parameter can be used to slightly zoom out (or in, though that's not really useful) so that some of the surrounding area is captured. enter image description here

from os.path import join

shpin,field,pan,scale,factor,folder = [parameters[x].valueAsText for x in xrange(6)]    

arcpy.env.workspace = folder    
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
entries = int(arcpy.GetCount_management(shpin).getOutput(0))+1      
factor = float(factor) if factor else 1
if not scale: scale = df.scale

#Get name of ObjectID
oidname = [str(x.name) for x in arcpy.ListFields(shpin, "*", "OID")][0]

def clearmem(shp):
    [arcpy.Delete_management(x) for x in shp if arcpy.Exists(x)]        

try:                        
    names = [[row[0], "{0}.png".format(row[1])] 
             for row in arcpy.da.SearchCursor(shpin, ["OID@", field])]

    arcpy.SetProgressor("step", "Exporting features to PNG", 0, entries, 1)
    for i,(oid,val) in enumerate(names):    
        arcpy.SetProgressorPosition(i)

        #Remove invalid character names and make sure output name is unique
        unival = arcpy.CreateUniqueName("".join(x for x in val if x not in r"\/:*?<>|"))                

        #Create layer of 1 feature, based on OID.
        layer = arcpy.MakeFeatureLayer_management(shpin, "templyr", '"{0}"={1}'.format(oidname, oid))

        #Set extent of map document to extent of 1-feature layer                
        df.extent = arcpy.Describe(arcpy.CopyFeatures_management(layer, "in_memory/fc")).extent 
        clearmem(["templyr", "in_memory/fc"])   

        #"Zoom out" by a specified factor if set to zoom to selected;
        #otherwise set scale to specified value.                
        df.scale = df.scale * factor if pan == "false" else scale                   

        #Change title bar to name of feature.
        for x in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"): x.text = val[0:-4]

        arcpy.mapping.ExportToPNG(mxd, join(folder, unival))                

except Exception as e:
    clearmem(["templyr", "in_memory/fc"])
    arcpy.AddMessage(e)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.