Thursday, 14 September 2017

labeling - ArcGis label last vertex Z value


Is it possible to label a feature in ArcMap using geometry values?


In this instance I want to label features (polylines) with the Live Z value of the last vertex obtained from the Shape.


However when I try something simple like the XMin of the extent of the shape:


enter image description here


It returns an error:


enter image description here


Is it possible to use the features' geometry to formulate a label? I do not want to calculate values from the geometry into a field and then label that field unless I absolutely have to:


enter image description here


Ideally the label should be live, changing as the feature is modified.



Based on the answer by Felix:


def FindLabel ( [OBJECTID]  ):
mxd = arcpy.mapping.MapDocument("CURRENT")
layers=arcpy.mapping.ListLayers(mxd, "WatrcrsL")
lr=layers[0]
with arcpy.da.SearchCursor(lr, 'Shape@','OBJECTID = '+str( [OBJECTID] )) as cursor:
for row in cursor:
a=row[0].lastPoint.Z
return a


Will label the features with the last points' Z value live!



Answer



Example for point layer


def FindLabel ( [FID] ):
mxd = arcpy.mapping.MapDocument("CURRENT")
layers=arcpy.mapping.ListLayers(mxd, "ac_pipes_aspoints")
lr=layers[0]
with arcpy.da.SearchCursor(lr, 'Shape@XY',r'"FID"='+str( [FID] )) as cursor:
for row in cursor:
a=row[0]

return a[0]

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...