Select to view content in your preferred language

How to test using ArcPy for an existing Point feature at a given location

1002
15
Jump to solution
01-28-2026 11:54 AM
PeterAnderton
Emerging Contributor

I have an process that will calculate (x, y) coordinate pairs from other data, and I also have an existing feature class of Points. How can I test using ArcPy whether there is already an existing Point feature at my calculated (x, y) position? The idea is that if there IS an existing Point at that position, then I will note a particular field value of that Point and use it elsewhere in the wider process; if there ISN'T an existing Point then I will generate a new one at that position.

The rationale behind this is that I am trying to recreate using Python within ArcGIS Pro a process that I actually first wrote over two decades ago (!) using MapBasic within the MapInfo GIS. MapBasic had a very handy function called SearchPoint(), which simply took a Point feature class name plus the (x, y) coordinates of interest as parameters, and returned how many points there were at that location (although all I needed to know was whether the answer was zero or non-zero). After extensive online searching I cannot find anything directly equivalent within ArcGIS Python. Functions such as Count Overlapping, Near Table, Buffer, etc. all seem to work with all features within a feature class, or compare all features in one class against all features in another, etc., which isn't what I'm looking for.

Some might suggest calculating all my required (x, y) locations first, removing any duplicates, then generating all my Points in one go, but the process doesn't work like that; coordinates will change over time, new Points may or may not be needed on an ad hoc basis. I just want a simple test of a single given location against a dataset of existing Points that I can use within a wider Python script.  

Obviously I could just iterate over all existing Points, testing each one in turn against my calculated coordinates, but I wanted to know whether there was some existing ArcPy function optimised for my intended use case, as thus far I have not been able to find anything remotely similar.

I should perhaps stress that, although in a previous life many years ago I wrote thousands of lines of MapBasic, I am new to Python programming in ArcGIS Pro, so I may well be missing something blindingly obvious!

0 Kudos
15 Replies
DanPatterson
MVP Esteemed Contributor

You can read from the featureclass (fc) what you want

array = arcpy.da.FeatureClassToNumPyArray(fc, ["OID@", "SHAPE@XY"])  # oid and paired coordinates
array = arcpy.da.FeatureClassToNumPyArray(fc, ["SHAPE@X","SHAPE@Y"]) # just the x, y as separate fields
# "some!!!" of the possibilities are in the code samples

... sort of retired...
0 Kudos
PeterAnderton
Emerging Contributor

I think this numpy-based approach will give me what I need, certainly for my immediate purposes, so I have marked this as the solution.

Many thanks for all your help.

0 Kudos
DanPatterson
MVP Esteemed Contributor

If you get bogged down on any details, give us a buzz.  on that note, arc returns "structured" arrays, since you want just the coordinates, here is a final tip for now.

# -- points in arc** format
pnts_arc 
array([( 8.78, 91.06), (30.24,  8.75), (98.45, 77.13), (18.81, 49.23),
       ( 5.66, 19.19), (57.84, 62.84), (93.75, 98.79), (88.83, 44.78),
       (52.11, 85.75), (32.27, 37.44)],
      dtype=[('SHAPE@X', '<f8'), ('SHAPE@Y', '<f8')])
# -- a quick import and conversion to get an unstructured array to work with
from numpy.lib.recfunctions import unstructured_to_structured as uts

pnts_numpy = stu(pnts_arc)

pnts_numpy 
array([[ 8.78, 91.06],
       [30.24,  8.75],
       [98.45, 77.13],
       [18.81, 49.23],
       [ 5.66, 19.19],
       [57.84, 62.84],
       [93.75, 98.79],
       [88.83, 44.78],
       [52.11, 85.75],
       [32.27, 37.44]])

... sort of retired...
0 Kudos
DeanAnderson2
Frequent Contributor
I would use ArcPro "Near" tool within a python script.
0 Kudos
DanPatterson
MVP Esteemed Contributor

which can be done using numpy as well.

an old missive Generate Near Table for points - Esri Community

and a newer one Really close points - Esri Community


... sort of retired...
0 Kudos
PeterAnderton
Emerging Contributor

Clearly there's more to numpy than I ever knew! Lots of ideas to try...

0 Kudos