4

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!

5
  • Shoud be !Shape! in expession
    – FelixIP
    Dec 4, 2014 at 4:21
  • You'd think @FelixIP.. just like the field calculator expression but I tried that and got a different error: Invalid syntax (<string>, line 1). You would also note that Shape doesn't appear in the list of fields to select (it's directly after OBJECTID). Dec 4, 2014 at 4:26
  • 1
    I think being able to access the SHAPE@ tokens for writing label expressions would make a great ArcGIS Idea.
    – PolyGeo
    Dec 4, 2014 at 6:09
  • Me 2 @PolyGeo. You can declare cursors in a label expression same as in a field calculator expression so why not SHAPE@? Dec 4, 2014 at 6:14
  • Yeah - my superficial understanding is that both label expressions and the field calculator run cursors in the background and in the case of the former it would already seem to be accessing its geometry to decide where to place the label.
    – PolyGeo
    Dec 4, 2014 at 6:22

1 Answer 1

9

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]
0

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.