<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Create polygons from csv file: RuntimeError: Object: CreateObject cannot create geometry from inputs in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/create-polygons-from-csv-file-runtimeerror-object/m-p/1169629#M64456</link>
    <description>&lt;P&gt;Has to be done by an insertcursor?&lt;/P&gt;&lt;P&gt;cobble the parts from above that does the splitting, then throw it into your cursor if you must&lt;/P&gt;</description>
    <pubDate>Mon, 02 May 2022 00:34:03 GMT</pubDate>
    <dc:creator>DanPatterson</dc:creator>
    <dc:date>2022-05-02T00:34:03Z</dc:date>
    <item>
      <title>Create polygons from csv file: RuntimeError: Object: CreateObject cannot create geometry from inputs</title>
      <link>https://community.esri.com/t5/python-questions/create-polygons-from-csv-file-runtimeerror-object/m-p/1169535#M64444</link>
      <description>&lt;P&gt;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".&lt;/P&gt;&lt;P&gt;I followed the code sample from &lt;A title="Writing geometries --ArcGIS Pro" href="https://pro.arcgis.com/en/pro-app/latest/arcpy/get-started/writing-geometries.htm" target="_blank" rel="noopener"&gt;https://pro.arcgis.com/en/pro-app/latest/arcpy/get-started/writing-geometries.htm&lt;/A&gt;. 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?&lt;/P&gt;&lt;LI-CODE lang="python"&gt;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()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 May 2022 18:36:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-polygons-from-csv-file-runtimeerror-object/m-p/1169535#M64444</guid>
      <dc:creator>ZhexinYin</dc:creator>
      <dc:date>2022-05-02T18:36:44Z</dc:date>
    </item>
    <item>
      <title>Re: Create polygons from csv file: RuntimeError: Object: CreateObject cannot create geometry from inputs</title>
      <link>https://community.esri.com/t5/python-questions/create-polygons-from-csv-file-runtimeerror-object/m-p/1169543#M64445</link>
      <description>&lt;LI-CODE lang="python"&gt;import numpy as np
import arcpy
name = "c:/temp/parcel_points.csv"
dt = np.dtype([('PARCELID', 'i8'), ('POINT_X', 'f8'), ('POINT_Y', 'f8')])
a = np.genfromtxt(
    name, dtype=dt, delimiter=",", names=True, autostrip=True,
    encoding=None)
ids = a['PARCELID']
w = np.nonzero((ids[1:] - ids[:-1] != 0))[0]
p_lst = np.array_split(a, w)
frst = p_lst[0]
xs = frst[['POINT_X', 'POINT_Y']].tolist()
p = arcpy.Polygon(arcpy.Array([arcpy.Point(i[0], i[1]) for i in xs]))&lt;/LI-CODE&gt;&lt;P&gt;'p' is the first polygon (line 11 and 12) in the 'p_list' which was obtained from splitting the array based on where the PARCELID s breakpoints occurred.&lt;/P&gt;&lt;P&gt;You can cobble the rest of the polygons by creating a list to hold the polygons and cycle through lines 11 to 13.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="poly.png" style="width: 219px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/40260i82D579C431DD0AD4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="poly.png" alt="poly.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 30 Apr 2022 03:13:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-polygons-from-csv-file-runtimeerror-object/m-p/1169543#M64445</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2022-04-30T03:13:38Z</dc:date>
    </item>
    <item>
      <title>Re: Create polygons from csv file: RuntimeError: Object: CreateObject cannot create geometry from inputs</title>
      <link>https://community.esri.com/t5/python-questions/create-polygons-from-csv-file-runtimeerror-object/m-p/1169626#M64455</link>
      <description>&lt;P&gt;Thank you so much for the help! I forgot to mention that the task has to be completed via insertcursor method. I believe I'm almost there since I was able to create an unseparated polygon through the code below. I'm just not able to separate them through ID.&lt;/P&gt;&lt;LI-CODE lang="c"&gt;import os
import arcpy
import fileinput

in_dir = "D:/demo"
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()

	for line in fileinput.input(in_csv):
		if not fileinput.isfirstline():
			point.ID, point.X, point.Y = line.split(",")
			array.add(point)
	cursor.insertRow([arcpy.Polygon(array)])
	fileinput.close()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 01 May 2022 20:18:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-polygons-from-csv-file-runtimeerror-object/m-p/1169626#M64455</guid>
      <dc:creator>ZhexinYin</dc:creator>
      <dc:date>2022-05-01T20:18:58Z</dc:date>
    </item>
    <item>
      <title>Re: Create polygons from csv file: RuntimeError: Object: CreateObject cannot create geometry from inputs</title>
      <link>https://community.esri.com/t5/python-questions/create-polygons-from-csv-file-runtimeerror-object/m-p/1169629#M64456</link>
      <description>&lt;P&gt;Has to be done by an insertcursor?&lt;/P&gt;&lt;P&gt;cobble the parts from above that does the splitting, then throw it into your cursor if you must&lt;/P&gt;</description>
      <pubDate>Mon, 02 May 2022 00:34:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-polygons-from-csv-file-runtimeerror-object/m-p/1169629#M64456</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2022-05-02T00:34:03Z</dc:date>
    </item>
    <item>
      <title>Re: Create polygons from csv file: RuntimeError: Object: CreateObject cannot create geometry from inputs</title>
      <link>https://community.esri.com/t5/python-questions/create-polygons-from-csv-file-runtimeerror-object/m-p/1169816#M64460</link>
      <description>&lt;P&gt;I have updated the code above and solved the runtime error. It was caused by false indentation. But the code still not able to separate polygons by ID. Is there anyway this code can be improved instead of rewriting the whole thing to make it work?&lt;/P&gt;</description>
      <pubDate>Mon, 02 May 2022 18:40:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-polygons-from-csv-file-runtimeerror-object/m-p/1169816#M64460</guid>
      <dc:creator>ZhexinYin</dc:creator>
      <dc:date>2022-05-02T18:40:41Z</dc:date>
    </item>
    <item>
      <title>Re: Create polygons from csv file: RuntimeError: Object: CreateObject cannot create geometry from inputs</title>
      <link>https://community.esri.com/t5/python-questions/create-polygons-from-csv-file-runtimeerror-object/m-p/1170533#M64481</link>
      <description>&lt;P&gt;To fix your problem you will need to alter your code to:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Add a field to the&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;output feature class to store the parcel id.&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;Modify the insert cursor to also update this parcel update&lt;/SPAN&gt;&lt;/LI&gt;&lt;LI&gt;&lt;SPAN&gt;Insert the row with the geometry and the parcel id every time the parcel id changes.&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;SPAN&gt;The&amp;nbsp; code will look like this:&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import csv
import os
import arcpy

in_dir = "D:/demo"
csvFile = "parcel_points.csv"
fc = "polygonFromCSV"
in_csv = os.path.join(in_dir, csvFile)
sr = arcpy.SpatialReference(26910)


# Create output feature class
arcpy.management.CreateFeatureclass(
    in_dir, fc, geometry_type="POLYGON", spatial_reference=sr
)
out_feature_class = os.path.join(in_dir, fc)
# Add a field to transfer PARCELID from input csv
arcpy.management.AddField(out_feature_class, "PARCELID", "LONG")

with arcpy.da.InsertCursor(out_feature_class, ["SHAPE@", "PARCELID"]) as cursor:
    point_list = []
    parcel_value = None
    is_first_pass = True

    with open(in_csv, mode="r") as csv_file:
        csv_reader = csv.reader(csv_file, delimiter=",")
        header = next(csv_reader)
        for row in csv_reader:
            #print(f"Parcel id:{row[0]} with X {row[1]} and Y {row[2]}.")

            if is_first_pass:
                parcel_value = row[0]
                is_first_pass = False
            elif row[0] != parcel_value:
                # Parcel ID has changed, write the polygon
                polygon = arcpy.Polygon(arcpy.Array(point_list), sr)
                cursor.insertRow([polygon, parcel_value])
                # Reset the current group
                parcel_value = row[0]
                point_list = []

            # Add the point to the feature's array of points
            point_list.append(arcpy.Point(row[1], row[2]))

        # final insert
        polygon = arcpy.Polygon(arcpy.Array(point_list), sr)
        cursor.insertRow([polygon, parcel_value])&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 04 May 2022 10:27:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-polygons-from-csv-file-runtimeerror-object/m-p/1170533#M64481</guid>
      <dc:creator>MarkBryant</dc:creator>
      <dc:date>2022-05-04T10:27:47Z</dc:date>
    </item>
    <item>
      <title>Re: Create polygons from csv file: RuntimeError: Object: CreateObject cannot create geometry from inputs</title>
      <link>https://community.esri.com/t5/python-questions/create-polygons-from-csv-file-runtimeerror-object/m-p/1173029#M64532</link>
      <description>&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 11 May 2022 20:47:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/create-polygons-from-csv-file-runtimeerror-object/m-p/1173029#M64532</guid>
      <dc:creator>ZhexinYin</dc:creator>
      <dc:date>2022-05-11T20:47:17Z</dc:date>
    </item>
  </channel>
</rss>

