I have a script below where I am trying to convert a CSV of a WKT polygons that I would like to export out into a shapefile and keep getting the following error on line 21 with: arcpy.management.CreateFeatureclass(output_folder,output_shapefile_name + ".shp", "POLYGON", spatial_reference)

The error I am receiving is:

Object: Error in executing tool

I have checked the spatial reference, am at a loss at what might be causing this issue. Could it be a folder permissions issue with where the files are located?

import arcpy
import csv
import os

# Set the input CSV file path containing WKT polygons
input_csv_file = r"Z:\ArcGIS\Name\File.csv"

# Set the output folder path for the shapefile
output_folder = r"Z:\ArcGIS\Name\Nationwide"

# Set the output shapefile name (without extension)
output_shapefile_name = "NationGh6"

# Create a spatial reference object for WGS84 (EPSG:4326)
spatial_reference = arcpy.SpatialReference(4326)

# Create the output shapefile path
output_shapefile = os.path.join(output_folder, output_shapefile_name + ".shp")

# Create the output shapefile with the specified fields and spatial reference
arcpy.management.CreateFeatureclass(output_folder,output_shapefile_name + ".shp", "POLYGON", spatial_reference)

# Add a field to store the WKT representation
arcpy.management.AddField(output_shapefile, "GH6Polygon", "TEXT")

# Open the input CSV file and create an insert cursor for the shapefile
with open(input_csv_file, 'r') as csv_file:
    csv_reader = csv.DictReader(csv_file)

    # Create an insert cursor for the shapefile
    with arcpy.da.InsertCursor(output_shapefile, ["SHAPE@","GH6Polygon"]) as insert_cursor:
        for row in csv_reader:
            # Get the WKT polygon from the CSV row
            wkt_polygon = row["GH6Polygon"]

            # Create a Geometry object from the WKT with the specified spatial reference
            geom = arcpy.FromWKT(wkt_polygon, spatial_reference)

            # Create a polygon feature for polygons
            if geom.type == 'polygon':
                polygon = arcpy.Polygon(geom, spatial_reference)
                insert_cursor.insertRow([polygon, wkt_polygon])

print(f"Conversion from CSV to shapefile '{output_shapefile}' complete.")

1 Answer 1


If you take a look at tool reference for Create Feature Class you can see that the:

  • first parameter is: path,
  • second: name,
  • third: type and
  • fourth: template

So you are passing spatial_reference as the template with: arcpy.management.CreateFeatureclass(output_folder,output_shapefile_name + ".shp", "POLYGON", spatial_reference)

Specify the parameter names to fix it and make the code more readable:

arcpy.management.CreateFeatureclass(out_path=output_folder, out_name=output_shapefile_name+".shp", geometry_type="polygon", spatial_reference=spatial_reference)

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.