Select to view content in your preferred language

Create a polygon grid has some odd results

551
1
02-24-2013 11:33 AM
StuartMoore
Frequent Contributor
Hi,
ive created the below code to create a polygon grid 2 squares wide and 1 high, the code works fine and creates the grid with the attributes but when i select one of the squares in arcMap the highlight selects both (screenshot attached)

any ideas as to what ive done wrong?

Thanks

Stu

import arcpy

cur = arcpy.InsertCursor("c:/PY123.shp")

point = arcpy.Point()
array = arcpy.Array()

for x in range(2):
    for y in range(1):
        point.X = x
        point.Y = y
        array.add(point)
        point.X = x+1
        point.Y = y
        array.add(point)
        point.X = x+1
        point.Y = y+1
        array.add(point)
        point.X = x
        point.Y = y+1
        array.add(point)
        point.X = x
        point.Y = y
        array.add(point)
        array.add(array.getObject(0))
        feat = cur.newRow()
        feat.setValue("Col", x)
        feat.setValue("Row", y)
        feat.shape = arcpy.Polygon(array)
        cur.insertRow(feat)
        array.removeAll()

del cur
Tags (2)
0 Kudos
1 Reply
JakeSkinner
Esri Esteemed Contributor
Hi Stu,

I would recommend using the Create Fishnet tool to create the polygon grid, and then use the Update cursor to update the attributes.
0 Kudos