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

Create a polygon grid has some odd results

$
0
0
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

Code:

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

Attached Thumbnails
Click image for larger version

Name:	py123.jpg‎
Views:	N/A
Size:	13.3 KB
ID:	22128  

Viewing all articles
Browse latest Browse all 2485