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) 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) 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.extent maxdiffxy = max([ext.XMax-ext.XMin,ext.YMax-ext.YMin])#max width or height of feature if maxdiffxy<1000: row = 6000 else: row = 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