1

I'm playing around with data driven pages, and have a polyline feature class that I'm using as my index. Now, because the lines are all of variable lengths I can't just use the default settings as some pages will be way too zoomed out. Instead I want to create a scale field to use, calculated based on the length of the line. What I have found so far is how to calculate it based on the difference between the length and height but this doesn't quite give the required results:

import arcpy
from arcpy import env
import os

env.workspace = r"U:"
mxd = arcpy.mapping.MapDocument(r"U:\EMS.mxd")
df = arcpy.mapping.ListDataFrames(mxd)[0]
newWeed = r"U:\ArcGIS\EMS\split_weed_index.shp"

print "Adding SCALE field"
addField =[['SCALE','TEXT', "", "", "", "", 'NULLABLE', "", ""]]
for item in addField:
    arcpy.AddField_management(newWeed, item[0])

scalefield = "SCALE" #scale field added above
lengthfield = "L" #actual length field

print "Calculating scales"
with arcpy.da.UpdateCursor(newWeed ,["SHAPE@", scalefield]) as cursor:
    for row in cursor:
        ext = row[0].extent
        maxdiffxy = max([ext.XMax-ext.XMin,ext.YMax-ext.YMin])#max width or 
height of feature
        if maxdiffxy<1000:
            row[1] = 6000
        else:
            row[1] = 10000
        cursor.updateRow(row)

print "Scales calculated"


print "Done"

Ideally I'd want something along the lines of "if the length is 1700m or more set the scale to 1:10000, otherwise 1:6000

  • There is a dynamic scale option (not sure of the name) that let you use a field to set the scale of each page. Adding a scale field to your line layer and using the field calculator could solve your problemn – J.R Apr 18 at 11:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.