1

I have a point shapefile with a high number of attribute fields. For a single point, there is only 1 of these attribute fields completed, the others have a "NULL" value for that point. The field name for which a value is available is furthermore defined in the field "Blockname".

So, for point 1, the value in the field "Blockname" is OVSTNP_180. In the field "OVSTNP_180" (and only in this field), there is a value listed (e.g. 741).

In order to label the points, I would like to create a field "label" where this value (741 in the example above) is calculated. Which expression do I need to use (in ArcGIS)?

I assumed that, for example in ArcGIS, I could state something like this: Label= ["[Blockname]"] but that does not work...

3
  • Which of QGIS or ArcGIS Desktop do you wish to ask about in this question. By asking about both you are effectively asking two questions which goes against the Tour.
    – PolyGeo
    Commented Feb 16, 2017 at 21:23
  • This is a complex calculation using a field value to define the field to copy from, I would think this would require some python (arcpy). It might be possible to do with QGIS but I can't think of a way to do this with pyqgis. Can you edit your question with a screen shot of your table and pick a platform that you're truly interested in... if you have both ArcGis and QGIS that's fine but I think this would be one of those things that's easier in arcpy. Commented Feb 16, 2017 at 21:32
  • I limited the question to ArcGIS. Commented Feb 16, 2017 at 22:03

1 Answer 1

2

Since all other fields are <Null>, the following works, although it probably won't be very performant if you have lots of points and fields. I'd suggest using the same logic in field calculator to populate your label field.

Note, I'm not using field at all. enter image description here

def FindLabel ( [a] , [b] , [c] ):
  return max([a] , [b] , [c])

If say, the other fields weren't all empty, the following would work to populate your label field properly based on the value in field.

fc = '/path/to/fc'
fields = ['a', 'b', 'c']
source = 'field'
label = 'label'

with arcpy.da.UpdateCursor(fc, [source] + fields + [label]) as uCursor:
    for row in uCursor:
        row = list(row)
        i = fields.index(row[0]) + 1   # adding 1 since source is first
        row[-1] = row[i]
        uCursor.updateRow(row)

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.