Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

Create Polygon.shp from Point.shp using Python Code

$
0
0
Hello, I have a question about the code below. Do I create default point and polygon shapefiles or do I neet to add attributes to the point and polygon shapefiles. I have been trying to work on this code and have not been able to get it to work. Not sure about shortList and pointList. This code has been copied from another post.

Code:

import arcpy
pointFC =  r"C:\Users\whitley-wayne\Desktop\summary\data.gdb\funds"
polygonFC = r"C:\Users\whitley-wayne\Desktop\summary\data.gdb\hab60"
pointList = []

with arcpy.da.SearchCursor(pointFC, "SHAPE@XY") as cursor:
    for row in cursor:
        shortList = list(row[0])
        pointList.append(shortList)

with arcpy.da.InsertCursor(polygonFC, ["SHAPE@"]) as c:
    for pnt in pointList:
        #  start with the lower left
        lowX = pnt[0]
        lowY = pnt[1]
        #  find the upper right
        highX = lowX + 20
        highY = lowY + 20
        array = arcpy.Array([arcpy.Point(lowX, lowY),
                            arcpy.Point(lowX, highY),
                            arcpy.Point(highX, highY),
                            arcpy.Point(highX, lowY),
                            arcpy.Point(lowX, lowY)])
        polygon = arcpy.Polygon(array)
        c.insertRow([polygon])


Viewing all articles
Browse latest Browse all 2485

Trending Articles