Select to view content in your preferred language

automated polygon movement?

1816
11
09-18-2012 12:44 PM
leifolson
Emerging Contributor
Hi,

I am trying to write a script that takes a single polygon shapefile ( a facility footprint), a grid of planning units, and a landcover shapefile, and, for each planning unit gridcell, shifts the geographic location of the footprint shapefile, and uses the newly located footprint to erase the underlying landcover. What's the best way to iterate through the cells, and aligns the footprint shapefile with the center of the gridcell? Thanks...
Tags (2)
0 Kudos
11 Replies
T__WayneWhitley
Honored Contributor
I can see that you are appropriately getting the 1st (and only) part, which is an array (or list?) of point objects....makes sense for single-part features I think.  You've set a variable before the loop begins for the 1st part (index 0).

So far so good, you feed adjusted point values based on this into another point array to feed into a new polygon geometry.
Great, but what is the purpose of incrementing your index variable?  What other geometry could you be referencing?  I think this is at least partly where your mistake is.......every time you fetch a new poly geom with the search, you should only have 1 part, correct?  (not considering 'holes' - regardless, the 'single part' should come 1st, if I'm not mistaken)

I agree with the others, better structuring and error trapping would be very useful.  Hope this helps.
0 Kudos
markdenil
Frequent Contributor
a nested list is a list nested within another list
(you can nest dictionarys too, and lists within dictionaries and vice versa..)

In this case, you want a list of verticies for the polygon
and each vertex entry is a list of the x and y coordinates.

line this:
theFeatureList = [
    [59.9359664290001, 58.2873293230001],
    [59.9354474180001, 58.292897049],
    [59.9359664290001, 58.2873293230001],
    [15.7361337040001, 69.5741156380001],
    [5.46961326000007, 74.605524862],
    [21.6743239320001, 90.0000000000001],
    [61.6145099540001, 90.0000000000001],
    [74.588779291, 78.7328713650001],
    [74.9956238680001, 62.052243682],
    [59.9359664290001, 58.2873293230001],
    [29.5877337620001, 75.2087581980001],
    [29.5902670670001, 75.2091884760001],
    [29.5877337620001, 75.2087581980001]
    ]


Then, as you loop through the outer list, it returns a llist of xy pairs you can access by index (0 and 1).

Furthermore, if your grid is regular, you needn't make a list of each new anchor point;
you can just increment the offsets.
offsetX = 0, offsetY = 0
draw the first polygon
offsetX += cellSizeX
draw the second

when you finish that row (by counting the steps)
reset offsetX to 0 and increment offsetY += cellSizeY
0 Kudos