So I am kind of new to python world and I'm trying to create a polygon feature class including multiple polygons from a csv file attached (parcel_points.csv) containing 3 columns: "PARCELID", "POINT_X", "POINT_Y".
I followed the code sample from https://pro.arcgis.com/en/pro-app/latest/arcpy/get-started/writing-geometries.htm. I'm currently stuck on separating each polygon by "PARCELID" but I keep getting "RuntimeError: Object: CreateObject cannot create geometry from inputs". Where did I do wrong?
import os
import arcpy
import fileinput
in_dir = "D:/WPS/JHU/Programming in GIS AS.430.606.81.SP22/Week 13/Final"
csvFile = "parcel_points.csv"
fc = "polygonFromCSV"
geoType = "Polygon"
in_csv = os.path.join(in_dir, csvFile)
arcpy.env.workspace = in_dir
sr = arcpy.SpatialReference(26910)
arcpy.management.CreateFeatureclass(in_dir, fc, geoType, "", "", "", sr)
with arcpy.da.InsertCursor(fc, ["SHAPE@"]) as cursor:
array = arcpy.Array()
point = arcpy.Point()
tempID = -1
for line in fileinput.input(in_csv):
if not fileinput.isfirstline():
point.ID, point.X, point.Y = line.split(",")
if tempID == -1:
tempID = line[0]
if tempID != line[0]:
cursor.insertRow([arcpy.Polygon(array)])
array.removeAll()
point.removeAll()
array.add(point)
tempID = line[0]
cursor.insertRow([arcpy.Polygon(array)])
fileinput.close()