Select to view content in your preferred language

How To Remove Points which are Too Close to Each Other?

1149
2
Jump to solution
09-23-2023 09:26 PM
Labels (2)
JSpeight
New Contributor

I have a bunch of data points, which are from Sea-Bird Monitoring.

I need to remove the data points of the sea birds drifting on the ocean to create a heat map for identifying foraging hot spots.

How can I remove the data points that are too close to each other?Screenshot 2023-09-24 172353.png

0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

Manually:

  • Summarize Nearby, choosing your point layer for both input feature classes
  • Select and delete each feature in the output fc where point count > 1
  • Select points by location, intersect with the summarize fc, these are the points you want to keep.

 

Python:

points = "TestPoints"
min_dist = 50

# buffer the points and intersect the points with the buffers
# (this is basically what Summaize Nearby does)
buffers = arcpy.analysis.Buffer(points, "memory/buffers", min_dist)
intersects = arcpy.analysis.Intersect([points, buffers], "memory/intersects")

# count the occurence of each ORIG_FID (the point OID) in the intersections
orig_fids = [row[0] for row in arcpy.da.SearchCursor(intersects, ["ORIG_FID"])]
orig_fid_counts = {fid: len([fid1 for fid1 in orig_fids if fid1 == fid]) for fid in orig_fids}

# create a new field in the point layer that stores the count of nearby points
arcpy.management.AddField(points, "NearbyPoints", "LONG")

# calculate that field
with arcpy.da.UpdateCursor(points, ["OID@", "NearbyPoints"]) as cursor:
    for oid, np in cursor:
        try:
            np = orig_fid_counts[oid] - 1
            cursor.updateRow([oid, np])
        except KeyError:
            pass

 

This will create a new field in your point layer. You only want to include points where that field is 0 in the heatmap. Delete the others or exclude them through selection/definition query.


Have a great day!
Johannes

View solution in original post

2 Replies
JohannesLindner
MVP Frequent Contributor

Manually:

  • Summarize Nearby, choosing your point layer for both input feature classes
  • Select and delete each feature in the output fc where point count > 1
  • Select points by location, intersect with the summarize fc, these are the points you want to keep.

 

Python:

points = "TestPoints"
min_dist = 50

# buffer the points and intersect the points with the buffers
# (this is basically what Summaize Nearby does)
buffers = arcpy.analysis.Buffer(points, "memory/buffers", min_dist)
intersects = arcpy.analysis.Intersect([points, buffers], "memory/intersects")

# count the occurence of each ORIG_FID (the point OID) in the intersections
orig_fids = [row[0] for row in arcpy.da.SearchCursor(intersects, ["ORIG_FID"])]
orig_fid_counts = {fid: len([fid1 for fid1 in orig_fids if fid1 == fid]) for fid in orig_fids}

# create a new field in the point layer that stores the count of nearby points
arcpy.management.AddField(points, "NearbyPoints", "LONG")

# calculate that field
with arcpy.da.UpdateCursor(points, ["OID@", "NearbyPoints"]) as cursor:
    for oid, np in cursor:
        try:
            np = orig_fid_counts[oid] - 1
            cursor.updateRow([oid, np])
        except KeyError:
            pass

 

This will create a new field in your point layer. You only want to include points where that field is 0 in the heatmap. Delete the others or exclude them through selection/definition query.


Have a great day!
Johannes
MudassarShafiq
New Contributor

I am trying to do something similar for bus stops. The data has multiple bus stop points for different service providers and for both inbound and outbound direction for the same geographical location. I used the Near tool to locate the stops within 50m distance. The total bus stops are more than 11,000. Is there a smart way to keep only one stop and delete the rest of the points instead of deleting the stops one by one?

Thank you!

0 Kudos