2

Imagine that I have two point feature datasets, being zero_point and points. I would like use zero_point as my input feature to create a selection of points that are 1) as close as possible to zero_point and 2) do not exceed a threshold value. To illustrate, I have the following distributions of zero_point and points:enter image description here

Assume that my threshold of aggregated values (values are represented by labels) of feature points is 10, then the expected output would be:

enter image description here

How can I realize a selection which is 1) based on distance relative to the input feature AND 2) a certain threshold, preferably using ArcPy?

ArcPy code:

#define workspace
arcpy.env.workspace = "c:/temp/MyProject-SO_20jan.gdb"

#create empty feature class
sr = arcpy.SpatialReference(28992) #Create a spatial reference object.

#create empty point features

## == points == ##
arcpy.CreateFeatureclass_management(out_path=arcpy.env.workspace, out_name="points", geometry_type="POINT", spatial_reference=sr)
## == zero_point == ##
arcpy.CreateFeatureclass_management(out_path=arcpy.env.workspace, out_name="zero_point", geometry_type="POINT", spatial_reference=sr)

#add value column to points dataset
fields = [("Value","LONG","4")]

# Create the fields using the above parameters
for field in fields:
    arcpy.AddField_management("points", field[0], field[1], "", "",
                              field[2], "", "NON_NULLABLE", "NON_REQUIRED", "")


#create values with geometry
row_values = [(1, (100000, 30000)), (1, (107000, 30700)), (2, (110000, 40000)),
             (102, (113000, 29000)), (170, (103000, 34070)), (10, (100000, 32070)), (2, (115000, 40000)),
             (502, (110000, 29000)), (5, (108000, 38000)), (1, (107000, 40000))]

#add values to empty feature datasets

## == points ==##

cursor = arcpy.da.InsertCursor("points",("Value", "SHAPE@XY"))

for row in row_values:
    cursor.insertRow(row)
    
del cursor

## == zero point == ##

cursor = arcpy.da.InsertCursor("zero_point", ["SHAPE@XY"])
xy = (105000, 35000)
cursor.insertRow([xy])

del cursor


1 Answer 1

0

Using ArcPy I would select all points within your specified distance then remove from the selection all points above your threshold, so Select By Location followed by Select By Attribute.

1
  • Your answer assumes a specified distance, however there is no specified distance, only a specified threshold. I think a first step can be to create a "Distance" column in the points dataset which quantifies distance of each point to zero point (this distance can be obtained via a spatial join). Then, sort the dataset by the distance column. Afterwards create an additional column which accumulates the "Value" column. However, an extra step is needed which accumulates values only if it can add up to 10 or less (thereby discarding values such as 10 and 170) but I don't know how to do that exactly Commented Jan 24, 2023 at 8:05

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.