Calculating rectangular extends for polygon grids

1033
7
Jump to solution
03-15-2012 07:49 AM
WadeGivens
New Contributor II
Looking for a little from the guru's out there on a task I'm trying to accomplish.  I have a vector file I created using the fishnet tool that consists of hundreds of rectagular "grids".  I'd like to loop through the records and find the uuper and lower Y, and left and right X values for each grid and write them to the appropriate new columns in the dataset (UpperY, LowerY, LeftX, RightX)

Any ideas on how to go about doing this?

Thanks again,
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JakeSkinner
Esri Esteemed Contributor
Here is an example that may help:

fc = "fishnet"  rows = arcpy.UpdateCursor(fc) for row in rows:     geom = row.shape     row.LowerX = geom.extent.XMin     row.UpperX = geom.extent.XMax     row.LowerY = geom.extent.YMin     row.UpperY = geom.extent.YMax     rows.updateRow(row)  del row, rows 

View solution in original post

0 Kudos
7 Replies
DarrenWiens2
MVP Honored Contributor
Hmmm... You can get X and Y coordinates of the rectangle centroid from Calculate Geometry (right-click column, choose Calculate Geometry). You can get width and height value from the Minimum Bounding Geometry tool (group by Object ID, envelope shape). Join output back to fishnet. Then, you should be able to subtract or add half the width and height to get your desired values. Warning: totally untested.

edit: I just realized this is in the Python forum. I guarantee there is a Python solution, not that I know it off hand. Check out Reading Geometry. Also, looks relatively simple to get to an Extent object which has the values you're looking for (see the example).
0 Kudos
JakeSkinner
Esri Esteemed Contributor
Here is an example that may help:

fc = "fishnet"  rows = arcpy.UpdateCursor(fc) for row in rows:     geom = row.shape     row.LowerX = geom.extent.XMin     row.UpperX = geom.extent.XMax     row.LowerY = geom.extent.YMin     row.UpperY = geom.extent.YMax     rows.updateRow(row)  del row, rows 
0 Kudos
RaphaelR
Occasional Contributor II
Hi Wade,

one way you could go is with field calculator:
1. create fields for centroidX/centroidY of the grids, calculate geometry for them.
2. create fields for UpperY, LowerY, LeftX, RightX

in field calculator you can then calculate each field:
UpperY = centroidY + (gridheight*0.5)
LowerY = centroidY - (gridheight*0.5)
LeftX = centroidX - (gridwidth*0.5)
RightX = centroidX + (gridwidth*0.5)
0 Kudos
WadeGivens
New Contributor II
Hi Wade,

one way you could go is with field calculator:
1. create fields for centroidX/centroidY of the grids, calculate geometry for them.
2. create fields for UpperY, LowerY, LeftX, RightX

in field calculator you can then calculate each field:
UpperY = centroidY + (gridheight*0.5)
LowerY = centroidY - (gridheight*0.5)
LeftX = centroidX - (gridwidth*0.5)
RightX = centroidX + (gridwidth*0.5)


Thought about doing something similar to this after the first reply, but a little worried as to what the results would be if I want them in decimal degrees.  Going to try the python code above first after my computer finishes up its processing task.

Thanks!
0 Kudos
RaphaelR
Occasional Contributor II
Going to try the python code above


that´s what i´d do too (if i had known it was that straight forward, thanks Jake!) 🙂
0 Kudos
WadeGivens
New Contributor II
Here is an example that may help:

fc = "fishnet"

rows = arcpy.UpdateCursor(fc)
for row in rows:
    geom = row.shape
    row.LowerX = geom.extent.XMin
    row.UpperX = geom.extent.XMax
    row.LowerY = geom.extent.YMin
    row.UpperY = geom.extent.YMax
    rows.updateRow(row)

del row, rows 


Thanks a bunch!  Worked like a charm!
0 Kudos
VAMSHIKRISHNA
New Contributor
Hi,

when i tried to give the field calculator expression in Quantum GIS it is throwing error like "An error occured while evaluating the calculation string"..Please provide me solution.

Thanks in advance,
Vamshi


Hi Wade,

one way you could go is with field calculator:
1. create fields for centroidX/centroidY of the grids, calculate geometry for them.
2. create fields for UpperY, LowerY, LeftX, RightX

in field calculator you can then calculate each field:
UpperY = centroidY + (gridheight*0.5)
LowerY = centroidY - (gridheight*0.5)
LeftX = centroidX - (gridwidth*0.5)
RightX = centroidX + (gridwidth*0.5)
0 Kudos