import arcpy
arcpy.env.overwriteOutput = True
points = r'C:\Users\Temitope\PycharmProjects\Scripts\DATA\ne_10m_populated_places_simple.shp'
countries = r'C:\Users\Temitope\PycharmProjects\Scripts\DATA\ne_50m_admin_0_countries.shp'
outpath = r'C:\Users\Temitope\PycharmProjects\Scripts\Output'
arcpy.MakeFeatureLayer_management(points, 'points_layer')
with arcpy.da.SearchCursor(countries, ['FID', 'SOVEREIGNT']) as country_cursor:
for x in country_cursor:
print x[1]
arcpy.MakeFeatureLayer_management(countries, 'countries_layer', """ "FID" = {} """.format(x[0]))
arcpy.SelectLayerByLocation_management('points_layer', 'WITHIN', 'countries_layer')
formatted_output_name = x[1].replace('(', '_').replace(')', '_')
arcpy.FeatureClassToFeatureClass_conversion('points_layer', outpath, 'cities_in_{}'.format(formatted_output_name))
print 'Successfully converted {}'.format(formatted_output_name)
print 'Finished'
THIS IS MY OUTPUT:
Senegal
Successfully converted Senegal
Saudi Arabia
Successfully converted Saudi Arabia
Traceback (most recent call last):
File "C:/Users/Temitope/PycharmProjects/Scripts/gis_scripts/gis_script.py", line 17, in <module>
arcpy.FeatureClassToFeatureClass_conversion('points_layer', outpath, 'cities_in_{}'.format(formatted_output_name))
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe3' in position 1: ordinal not in range(128)
Process finished with exit code 1
Any ideas?
print x[1]
line.formatted_output_name = x[1].decode('latin-1').replace('(', '_').replace(')', '_')