Skip to main content
1 of 5

Using ArcPy to Insert Polygons

I am trying to insert three polygon into a shapefile. The goal is to use a function that will create the polygon. That way, I can pass the coordinates of the polygon into the function. I have read multiple pages of documentation on this.

I am new and not seeing where the error is. The error I keep getting is that "float is not iterable". I am writing this in a Jupyter Noteobook using ESRI online. Any suggestions or help is greatly appreciated.

import arcpy
import shapefile
import csv
import sys

Set the workspace
arcpy.env.workspace = "/arcgis/home/"

Sets the Spatial Reference
sr = arcpy.SpatialReference(4326) #WGS84

# Create a polygon feature class
fc = "polygon_file1.shp"
arcpy.CreateFeatureclass_management(arcpy.env.workspace, fc, "POLYGON", spatial_reference=sr)

Create polygon object and write it to the feature class
def insert_polygon(x1, y1, x2, y2, x3, y3, x4, y4):
polygon = arcpy.Polygon([arcpy.Point(x1, y1), arcpy.Point(x2, y2), arcpy.Point(x3, y3), arcpy.Point(x4,y4), arcpy.Point(x1,y1)])
with arcpy.da.InsetCursor(fc, ["SHAPE@"]) as cursor:
cursor.insertRow([polygon])
return

insert_polygon(-92.421457,39.447925,-92.419858,39.448451,-92.417868,39.446918,-92.421349,39.446094)

insert_polygon(-92.413072,39.446835,-92.413072,39.447879,-92.412267,39.446073,-92.416441,39.445087)

insert_polygon(-92.417900,39.449872,-92.412493,39.451015,-92.411978,39.449888,-92.417299,39.448778)