Select to view content in your preferred language

SelectLayerByLocation 'WITHIN_A_DISTANCE' from point vs 'INTERSECT' point buffer

1815
3
06-20-2013 01:25 PM
CharlesArnold
Deactivated User
I'm having trouble understanding the 'WITHIN_A_DISTANCE' option for arcpy.SelectLayerByLocation_management.

When I use arcpy.SelectLayerByLocation_management(lbTaCentroidsLayerName, 'WITHIN_A_DISTANCE', sitePntGeom, '25 Miles'), I get 815 points selected, but when I do arcpy.SelectLayerByLocation_management(lbTaCentroidsLayerName, 'INTERSECT', siteBufferFc) with a 25 miles buffer of the sitePntGeom, I get 1182 points selected.

Am I missing something obvious?

In [1]: import arcpy

In [3]: siteLon, siteLat = -122.276518, 47.191838

In [4]: sitePoint = arcpy.Point(siteLon, siteLat)

In [7]: sitePntGeom = arcpy.PointGeometry(sitePoint, wgs1984SpatialRef)

In [13]: lbTaCentroidsLayerName = 'centroidsFeatureLayer'

In [14]: arcpy.MakeFeatureLayer_management(centroidsFeatureClassName, lbTaCentroidsLayerName)
Out[14]: <Result 'centroidsFeatureLayer'>

In [15]: arcpy.SelectLayerByLocation_management(lbTaCentroidsLayerName, 'WITHIN_A_DISTANCE', sitePntGeom, '25 Miles')
Out[15]: <Result 'centroidsFeatureLayer'>

In [16]: int(arcpy.GetCount_management(lbTaCentroidsLayerName).getOutput(0))
Out[16]: 815

In [17]: siteBufferFc = 'in_memory/siteBuffer'

In [18]: arcpy.Buffer_analysis(sitePntGeom, siteBufferFc, '25 Miles')
Out[18]: <Result 'in_memory\\siteBuffer'>

In [19]: arcpy.SelectLayerByLocation_management(lbTaCentroidsLayerName, 'INTERSECT', siteBufferFc)
Out[19]: <Result 'centroidsFeatureLayer'>

In [20]: int(arcpy.GetCount_management(lbTaCentroidsLayerName).getOutput(0))
Out[20]: 1182

In [21]:
Tags (2)
0 Kudos
3 Replies
DarrenWiens2
MVP Alum
I assume it's because 'sitePntGeom' is assigned a geographic coordinate system (wgs1984SpatialRef), making oblong buffers, while SelectLayerByLocation may be using a projected coordinate system, making a circular search area. Is the feature class (centroidsFeatureClassName) projected? In any case, buffering unprojected data is not recommended.

edit: actually, buffering geographic data results in geodesic buffers, which are more accurate than Euclidean buffers made for projected data.
0 Kudos
CharlesArnold
Deactivated User
I assume it's because 'sitePntGeom' is assigned a geographic coordinate system (wgs1984SpatialRef), making oblong buffers, while SelectLayerByLocation may be using a projected coordinate system, making a circular search area. Is the feature class (centroidsFeatureClassName) projected? In any case, buffering unprojected data is not recommended.


Why is buffering unprojected data not recommended?
0 Kudos
DarrenWiens2
MVP Alum
Oh, on further inspection apparently buffering geographic data is preferred (news to me) in order to avoid distortions introduced by the projection.

I still feel like this is the cause of the difference in selected points, although now I'm questioning everything.
0 Kudos