0
import arcpy

arcpy.env.workspace = r"E:\Reserach\Dengu\Python"
arcpy.env.overwriteOutput = True

input_thana_shapefile = r"E:\Reserach\Dengu\New GIS Data\Dhaka_Thana.shp"
input_dcc_shapefile = r"E:\GIS\RAJUK\RAJUK_Updated\RAJUK_Updated\Dhaka_Combined database\Str_New_DCC.shp"


Thana = ['Adabor', 'Badda', 'Bangshal', 'Biman_Bandar', 'Cantonment', 'Chak_Bazar', 'Dakshinkhan', 'Darus_Salam', 'Demra', 'Dhanmondi', 'Gendaria', 'Gulshan', 'Hazaribagh', 'Jatrabari', 'Kadamtali', 'Kafrul', 'Kalabagan', 'Kamrangir_Char', 'Khilgaon', 'Khilkhet', 'Kotwali', 'Lalbagh', 'Mirpur', 'Mohammadpur', 'Motijheel', 'New_Market', 'Pallabi', 'Paltan', 'Ramna', 'Rampura', 'Sabujbagh', 'Shah_Ali', 'Shahbagh', 'Sher_e_bangla_Nagar', 'Shyampur', 'Sutrapur', 'Tejgaon', 'Tejgaon_Ind_Area', 'Turag', 'Uttar_Khan', 'Uttara']


arcpy.management.CreateFolder(r"E:\Reserach\Dengu\Python", "output_folder_2")

arcpy.MakeFeatureLayer_management(input_dcc_shapefile, 'input_dcc_shapefile_layer')

for x in Thana:
    print(x)
    arcpy.MakeFeatureLayer_management(input_thana_shapefile, 'input_thana_shapefile_layer', """ "NAME" = '{}' """.format(x))
    output_feature_class = f"{output_folder_2}\\{x}_clipped.shp"
    arcpy.analysis.Clip('input_dcc_shapefile_layer', 'input_thana_shapefile_layer', output_feature_class)

What is the problem in this code?

This is the error message:

Traceback (most recent call last):
  File "C:/Users/abhij/OneDrive/Desktop/Yoyo2.py", line 19, in <module>
    arcpy.MakeFeatureLayer_management(input_thana_shapefile, 'input_thana_shapefile_layer', """ "NAME" = '{}' """.format(x))
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 8826, in MakeFeatureLayer
    raise e
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\management.py", line 8823, in MakeFeatureLayer
    retval = convertArcObjectToPythonObject(gp.MakeFeatureLayer_management(*gp_fixargs((in_features, out_layer, where_clause, workspace, field_info), True)))
  File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 512, in <lambda>
    return lambda *args: val(*gp_fixargs(args, True))
arcgisscripting.ExecuteError: ERROR 000358: Invalid expression
Failed to execute (MakeFeatureLayer).

1 Answer 1

0

The error, as described in the error message, appears in line 19, where you are trying to create the feature layer:

arcpy.MakeFeatureLayer_management(input_thana_shapefile, 'input_thana_shapefile_layer', """ "NAME" = '{}' """.format(x))

There seems to be a typo in the where-clause. Make sure the input_thana_shapefile has a field "NAME". Read this on how to build valid SQL query expressions in ArcGIS.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.