C:\Python27\ArcGIS10.5\python.exe "F:/GIS/Python/GIS Data/SearchCursor.py"
0
Traceback (most recent call last):
File "F:/GIS/Python/GIS Data/SearchCursor.py", line 17, in <module>
arcpy.management.SelectLayerByLocation('points_layers', 'WITHIN', 'countries_layer')
File "C:\Program Files (x86)\ArcGIS\Desktop10.5\ArcPy\arcpy\management.py", line 7860, in SelectLayerByLocation
raise e
arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000368: Invalid input data.
Failed to execute (SelectLayerByLocation).
My Code
import arcpy
arcpy.env.overwriteOutput = True
points = r'F:\GIS\Python\GIS Data\World_Cities\World_Cities.shp'
countries = r'F:\GIS\Python\GIS Data\Countries\Country__5m_.shp'
outpath = r'F:\GIS\Python\Output'
arcpy.env.workspace = 'F:\GIS\Python\Output New'
with arcpy.da.SearchCursor(countries, ['FID', 'Ctry']) as country_cursor:
for x in country_cursor:
print x[0]
arcpy.MakeFeatureLayer_management(points, 'points_layer')
arcpy.MakeFeatureLayer_management(countries, 'countries_layer', """ "FID" = {} """.format(x[0]))
arcpy.management.SelectLayerByLocation('points_layers', 'WITHIN', 'countries_layer')
arcpy.FeatureClassToFeatureClass_conversion('points_layer', outpath, 'cities_in_{}'.format(x[1]))
perhaps 'points_layers' should be points_layer lose the ' and the s
I've never used the WITHIN value before. I think what you probably want is INTERSECT. That's a much more common way of finding points within the polygon boundaries of shapes like counties.