Actually, I am having trouble with Select Layer By Location approach. I am getting different results with two method. I dumped what's selected into arcmap and found that setting extent and copy method selects fearues I expected, which is any features which has shared point with the extent rectangle. Somehow method 1 failed to choose some of feature. My questions are
- Is "INTERSECT" correct method to mimic what extent does?
EDIT
Looking into further, this occurred for one small polygon near the edge of the extent (but completely contained by the extent rectangle), not being selected by Select Layer By Location method, whereas setting extent and then copying features catches this one feature. I heve everything in same sapatial reference. The extent polygon has dimension of tens of degree (WGS84), and the feature having trouble is an rectangle of half minute in each side, off from the extent boundary by about half minutes.
I am using ArcGIS 10.2.2, by the way.
# prepare extent from precalculated corner coordinates
sr = arcpy.Describe(feat_lyr).spatialReference
myextent = arcpy.Extent( ((x0,y0), (x0,y1), (x1, y1), (x1, y0)), sr )
# Method 1, using Select By Location
arcpy.env.extent = None
geom_ext = arcpy.Polygon(arcpy.Array(
[getattr( myextent, _ ) for _ in
('lowerLeft', 'upperLeft', 'upperRight', 'lowerRight') ] )
arcpy.SelectLayerByLocation(feat_lyr, 'INTERSECT', geom_ext )
geoms1 = [row[0] for row in arcpy.SearchCursor(feat_lyr, ['SHAPE@'])]
# Method 2, copy feature
arcpy.env.extent = myextent
arcpy.CopyFeatures_management(feat_lyr, feat_fc)
geoms2 = [row[0] for row in arcpy.SearchCursor(feat_fc, ['SHAPE@'])]