2

I have a point featureclass with multiple overlapping features. The figure shows two sets of overlapping points--the first set of 2 has values 4 and 6 and the second set of three has values 5, 6, and 7.

How can I select the point with the highest value in each set of overlapping points? I am using ArcGIS and arcpy with the basic license.

enter image description here

  • 3
    Buffer and dissolve, intersect points with buffers (or spatial join), use summary statistics to find the max value for each case buffer id then join with intersected points by buffer id and select where buffer.Value = sumtable.Value_max. Works best for integer values. – Michael Stimson Jul 12 '17 at 21:08
  • 2
    Dissolve, no multiparts, no fields, statistics max – FelixIP Jul 12 '17 at 21:28
  • Spatial join with INTERSECTS or ARE_IDENTICAL_TO operator as setting field mapping to MAX for the to-be-joined features. – fatih_dur Jul 12 '17 at 22:00
  • @faith_dur That seems to do the trick. The problem is, field mappings are a real pain to script. – Aaron Jul 14 '17 at 1:18
3

Assuming that stacked points have identical XY values, I'd make use of cursors. Tabular methods are faster and cleaner than using spatial tools. First determine which XYs occur more than once in your feature class. Then iterate through the feature class a second time, skipping XYs that occur only once and making use of a dictionary to store previous values. Something like this:

#layer name
layer = "LAYER"
#value field
valueField = "Val"

#create list of duplicate xys
xys = set ()
dupXys = set ()
with arcpy.da.SearchCursor (layer, "SHAPE@XY") as curs:
    for xy, in curs:
        if xy in xys: dupXys.add (xy)
        else: xys.add (xy)

#get oids of highest value XY
xyDi = {}
with arcpy.da.SearchCursor (layer, ["OID@", "SHAPE@XY", valueField]) as curs:
    for oid, xy, val in curs:
        #skip nonstacked points
        if not xy in dupXys:
            continue
        #check if xy has been added to dictionary
        try:
            lastOid, lastVal = xyDi [xy]
        #if not, add xy to dictionary with oid and val
        except:
            xyDi [xy] = (oid, val)
            #continue cursor
            continue
        #check if old value is less than current value
        if lastVal < val:
            #if true, update dictionary
            xyDi [xy] = (oid, val)

#create oid sql
path = arcpy.Describe (layer).path
oidFld = arcpy.AddFieldDelimiters (path, arcpy.Describe (layer).OIDFieldName)
oids = [oid for oid, val in xyDi.values ()]
oidStr = ", ".join (map (str, oids))
sql = "{} IN ({})".format (oidFld, oidStr)

#select
arcpy.SelectLayerByAttribute_management (layer, "", sql)
|improve this answer|||||
  • Many thanks. This finds the max point in a stack, although the final selection only contains the max value points and discards the points that are not stacked. – Aaron Jul 14 '17 at 1:27
  • 1
    Just skip the first cursor and comment out if not xy in dupXys: continue to select unstacked points. – Emil Brundage Jul 14 '17 at 1:30
  • Wow, that is a really slick solution and lightning fast from a computational standpoint. – Aaron Jul 14 '17 at 1:36
  • 1
    Thanks. If you want to select ties you need to get a little fancier, but not much. Right now it just selects the first one it comes across. – Emil Brundage Jul 14 '17 at 1:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.