Select to view content in your preferred language

Error 000368

1640
2
09-17-2022 04:29 AM
AbhijitBiswas
New Contributor

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]))
Tags (1)
0 Kudos
2 Replies
DanPatterson
MVP Esteemed Contributor

perhaps 'points_layers' should be points_layer  lose the ' and the s

 


... sort of retired...
0 Kudos
RogerDunnGIS
Frequent Contributor

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.

0 Kudos