I’ve created a feature class with a one to many relationships to a table.
One point many classes.
However I want to label the point with the classes attributes.
Esri wrote VB solution but it's not supported at version 10.1.
Answer
i found the answer here at wolf mapper blog - right click on the point shapefile and select “Properties” > “Labels” tab > “Expression…” button. In the “Label Expression” window select “Python” as the “Parser:” and click the check-box next to “Advanced.” Insert the following code:
def FindLabel ( [LocID] ):
import arcpy
myDataTable = "data table" #insert data table name
myComponent = "Arsenic" #insert component name
myScreeningLevel = "32" #insert exceedance level
myQuerySelect = '"location_id"' + " = '" + [LocID] + "' and " + '"component"' + " like '" + myComponent + "%'"
myFieldsQuerySelect = "OBJECTID; location_id; component; top_depth_inches; bottom_depth_inches; result; units"
mySortQuerySelect = "top_depth_inches"
myText = ""
mxd = mxd = arcpy.mapping.MapDocument("CURRENT")
for table in arcpy.mapping.ListTableViews(mxd):
if table.name == myDataTable:
rows = arcpy.SearchCursor(table, myQuerySelect, "", myFieldsQuerySelect, mySortQuerySelect)
myText = "" + [LocID] + " \n" + "" + myComponent + " " + "\n"
currentState = ""
for row in rows:
if currentState != row.OBJECTID:
currentState = row.OBJECTID
if float(row.result) >= float(myScreeningLevel):
myText = myText + str(int(row.top_depth_inches)) + '"-' + str(int(row.bottom_depth_inches)) + "" " + str(row.result) + " " + str(row.units) + "\n"
else:
myText = myText + str(int(row.top_depth_inches)) + '"-' + str(int(row.bottom_depth_inches)) + '" ' + str(row.result) + " " + str(row.units) + "\n"
return myText
No comments:
Post a Comment