Select to view content in your preferred language

Help using PointGeometry with SelectLayerByLocation

2902
19
Jump to solution
01-11-2019 11:36 AM
ZoltanSzecsei
Emerging Contributor

Hi,

The following code fails:

pg = arcpy.PointGeometry(vert,'None',True)
arcpy.SelectLayerByLocation_management("hgt_feats", "WITHIN_A_DISTANCE_3D", pg, 0.005, 'NEW_SELECTION')

with:

File "Z:/Projects/Development/python/ToGround/ToGround.py", line 140, in <module>
arcpy.SelectLayerByLocation_management("hgt_feats", "WITHIN_A_DISTANCE_3D", pg, 0.005, 'NEW_SELECTION')
File "C:\Program Files (x86)\ArcGIS\Desktop10.6\ArcPy\arcpy\management.py", line 7873, in SelectLayerByLocation
raise e
RuntimeError: Object: Error in executing tool

I'm trying to see if there is an underlying polygon vertex at a specific XYZ location.

I do not need to select the underlying polygon, I just need to know if there is one at that location

Any help would be appreciated.

Regards and thanks,

Zoltan

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
DarrenWiens2
MVP Honored Contributor

Try specifying a spatial reference on your PointGeometry, even if it is unprojected.

View solution in original post

19 Replies
DanPatterson_Retired
MVP Emeritus

PointGeometry—ArcPy classes | ArcGIS Desktop  intersects perhaps, if you want to work with arcpy geometry objects

The Select Layer By Location—Data Management toolbox | ArcGIS Desktop are using feature layers

ZoltanSzecsei
Emerging Contributor

Hi Dan

I'll take a deeper look at the Point Geometry classes - but I did find plenty of examples using Geometry with SelectLayerByLocation, so I was wondering why my forehead has square indentations and my keyboard broken 🙂

Thanks and keep well,

Zoltan

0 Kudos
DarrenWiens2
MVP Honored Contributor

Try specifying a spatial reference on your PointGeometry, even if it is unprojected.

ZoltanSzecsei
Emerging Contributor

I have - and have also set arcpy.env.outputCoordinateSystem = arcpy.SpatialReference(blah blah)

It is a projected system with metric coords

Dan's put me on to using geometry methods - now that I take a deeper look, it is a better way to solve my particular issue - I'm just  busy wrapping my head around using disjoint/intersect/whatever...........

0 Kudos
ZoltanSzecsei
Emerging Contributor

AAaargh! Yes! (Darren says: Try specifying a spatial reference on your PointGeometry)

I override it with 'None', so that negates my env setttings.

I've now added the Spatial Reference into the arcpy.PointGeometry() and it is now working.

Big thanks Darren 🙂

Zoltan

JoshuaBixby
MVP Esteemed Contributor

You didn't override it with None, you just created a point geometry without one.  In your original code, I assume vert is an ArcPy Point, and ArcPy Points don't have spatial references so there is nothing to override.

0 Kudos
ZoltanSzecsei
Emerging Contributor

Actually (psychologically) I did "override" it.

If one sets and env to a SRS/CRS, one should be able to assume that all dimension and coordinate related values would be interpreted by ArcGIS to be in the CRS set by the env.

By placing 'None' in a specific command, that (intuitively) explicitly says "override the env requested CRS"

I know this is about symantecs of speach, but I make this point because when ESRI provide certain settings, certain expectations are also "enabled".

HTH 

Z

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

I know what you are saying, and agree, about expectations.  About 1/3 of the defects I log are where the software works but the behavior doesn't agree with documentation.  I don't care which one Esri fixes, either the software or the documentation, but even getting documentation updated has taken multiple versions.  I get fixing software defects takes time, but the slowness up addressing documentation issues has always frustrated me greatly.

0 Kudos
DanPatterson_Retired
MVP Emeritus

Select by Location according to the help files, requires 2 feature layers as input. (A hidden feature of arcpy? )

Zoltan, do you have the example where an arcpy geometry object and a feature layer made it work?

0 Kudos