Skip to content

Instantly share code, notes, and snippets.

@amarinelli
Created September 17, 2014 20:47
Show Gist options
  • Save amarinelli/14245c90834054738544 to your computer and use it in GitHub Desktop.
Save amarinelli/14245c90834054738544 to your computer and use it in GitHub Desktop.
Sample 'Select by Location' using point geometry and query layer
import arcpy
point = arcpy.Point(592326.779, 6241287.454)
ref = arcpy.SpatialReference(26708) #SRID
ptGeometry = arcpy.PointGeometry(point, ref)
conn = r'Database Connections\[email protected]'
layer = "polygon"
query = "select * from data_view_spatial2"
u_id = "leaseid (Text, Nullable)"
arcpy.MakeQueryLayer_management(conn, layer, query, u_id, "POLYGON")
arcpy.SelectLayerByLocation_management(layer, "CONTAINS",ptGeometry, "#", "NEW_SELECTION")
result = int(arcpy.GetCount_management("polygon").getOutput(0))
print result
print "done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment