El siguiente código es parte de una caja de herramientas de Python para 10.1. El parámetro Scale se utiliza para establecer la escala de la panorámica y el parámetro Scale Factor se puede utilizar para alejar ligeramente el zoom (o acercarlo, aunque eso no es realmente útil) para que se capture parte del área circundante. ![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)