Skip to main content
naming
Source Link
Vince
  • 20.5k
  • 16
  • 49
  • 65

Using ArcPy to Insert Polygonsinsert 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 Notebook using ESRI onlineArcGIS Online.

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)

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 Notebook using ESRI online.

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)

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 Notebook using ArcGIS Online.

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)
Improved formatting
Source Link
Hornbydd
  • 45k
  • 5
  • 43
  • 84

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 Notebook using ESRI online.

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)

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 Notebook using ESRI online.

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)

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 Notebook using ESRI online.

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)
deleted 108 characters in body
Source Link
TomazicM
  • 27.3k
  • 25
  • 33
  • 43

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)

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)

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)

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)
deleted 43 characters in body; edited tags
Source Link
PolyGeo
  • 65.5k
  • 29
  • 115
  • 352
Loading
Source Link
Loading