Select to view content in your preferred language

length and width of polygon from particular direction

8179
11
05-22-2012 06:49 AM
RudPlatt
Deactivated User
I would like to find the length and width of polygons with respect to a compass direction stored in the attribute table. Does anyone have any thoughts on how to do this?

Thanks for your help!
0 Kudos
11 Replies
BruceNielsen
Frequent Contributor
I think what you'd have to do is rotate the polygon the given amount in the opposite direction, then use the extent values (Min/Max X or Y, depending on the angle's reference axis) for the feature. I'm not sure that can be done in Modelbuilder or Python; it may require ArcObjects.

Someone else may have a simpler solution...
0 Kudos
DanLee
by Esri Regular Contributor
Esri Regular Contributor
Rud,

In case the directions happen to align with the largest/longest extents of the polygons, and if you have ArcGIS 10, you can try Minimum Bounding Geometry tool (Data Management toolbox - Features toolset), which has the RECTANGLE_BY_WIDTH and RECTANGEL_BY_AREA options available for ArcView license. The width and length measurements can be included in the output.

Otherwise, if you can find a script that rotates the features by the directions, you can then use the Minimum Bounding Geometry tool to get the measurements.
0 Kudos
JoelCalhoun
Deactivated User
I'm not sure if this is helpful but there is also a Cartography tool called Calculate Polygon MainAngle.
I have used this in conjuction with the previously mentioned  Minimum Bounding Geometry tool.

My issue was that I needed to create an atlas from an irregular index grid of roughly 2600 tiles at various scales and I needed a way to determine which tiles had the largest extents factoring in the scale so that I could make sure I wasn't clipping any tile boundaries in the data frame of my atlas.  In my case, since the data frame is rectangluar and not rotated I only need to know the largest North-South and East-West extents of my index grid tiles factoring in map scale. 

Rather than setting up the data driven pages atlas and clicking through 2600 tiles to see if any of the tiles were clipped I used the two previously mentioned tools to script a solution. 

I used the Minimum Bounding Geometry tool to find the largest and smallest extents of each tile's envelope.  But without knowing which direction that longest side is, it's not much use. 
So then I used the Calculate Main Angle tool to give me the angle of the longest extent of the polygon evelope created from the previous tool.

I also added two fields to the temp polygon envelopes dataset that are scale factor fields (Max and Min widths from the Minimim Bounding Geometry tool / map scale).

I run some cursors over the polygon envelopes dataset that pulls out the largest extent factoring in scale and it's direction, and then the largest extent in the opposite direction.

I then add a new field to my index grid and populate the two tiles with the direction in which they are the largest, or if one tile is the largest in both directions I just populate that tile with "Both".

Anyway,  I don't know if anyone else has needed to figure this out but I am willing to share my code if anyone really needs it.


Joel
0 Kudos
DanLee
by Esri Regular Contributor
Esri Regular Contributor
I just want to let you know that if you check the option of "Add geometric characteristics as attributes to output", Minimum Bounding Geometry will include a field for orientation:
    MBG_Orientation�??The orientation of the longer side of the resulting rectangle.
http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00170000003q000000
0 Kudos
JoelCalhoun
Deactivated User
I just want to let you know that if you check the option of "Add geometric characteristics as attributes to output", Minimum Bounding Geometry will include a field for orientation:
    MBG_Orientation�??The orientation of the longer side of the resulting rectangle.
http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00170000003q000000



I know that the documentation indicates that the tool is supposed to output the orientation for envelopes but I do not believe that it does.

Each geometry type can be characterized by one or more unique measurements; these measurements can optionally be added to the output as new fields as described below. The width, length, and diameter values are in feature units; the orientation angles are in decimal degrees clockwise from north. The prefix, MBG_, indicates minimum boulding geometry field.

For RECTANGLE_BY_AREA, RECTANGLE_BY_WIDTH, and ENVELOPE, the new fields and measurements are:
MBG_Width�??The length of the shorter side of the resulting rectangle.
MBG_Length�??The length of the longer side of the resulting rectangle.
MBG_Orientation�??The orientation of the longer side of the resulting rectangle.

I have tested several times using the tool in toolbox checking the "Add geometry characteristics as attributes to output" option and in the scripting environment using the "MBG_FIELDS" option.

In both cases the only MBG fields that I see in the output are MBG_Width and MBG_Length.

I tested using the RECTANGLE_BY_WIDTH option and the MBG_Orientation field did show up.

I haven't tested the RECTANGLE_BY_AREA option but it definitely seems that MBG_Orientation is not in the output when the ENVELOPE option is selected.


Is this a bug or was orientation not meant to be part of the ENVELOPE option?  If not then I would like to see the help documents updated to reflect the way the tool actually works.


Thanks,



Joel
0 Kudos
DanLee
by Esri Regular Contributor
Esri Regular Contributor
For ENVELOPE option, the MBG_Orientation field is not included in the output by design. So, this is a documentation error. I will make sure it gets fixed. Thanks for the good catch!
0 Kudos
RudPlatt
Deactivated User
Rotating by attribute and calculating the width of the bounding envelope sounds like a promising approach!

Unfortunately I'm having a problem finding a script that rotates polygons by attributes.  I've pasted one in below that is supposed to be used in the field calculator, but it fails every time I run it.  Does anyone know of any other scripts for rotating polygons, or can you spot the problem with this one? (I did modify the name of the angle field)

'=========================
'polygon_rotate_byFieldValues.cal
'Author: Ianko Tchoukanski
'http://www.ian-ko.com
'=========================
Dim pPolygon As IPolygon
dim pArea As IArea
Dim pOrigin As IPoint
Dim dAngle As Double
Dim pTransform As ITransform2D
Dim Pi as Double
Dim sAngleField
'=======================
'adjust the value below
sAngleField = [Angle]
'=======================
Pi = 4 * Atn(1)
If (Not IsNull([Shape])) Then
  Set pPolygon = [Shape]
  dAngle = sAngleField*Pi/180
  If (Not pPolygon.IsEmpty) Then
    Set pArea = pPolygon
    Set pOrigin = pArea.Centroid
    Set pTransform = pPolygon
    pTransform.Rotate pOrigin, dAngle
  End If
End If
__esri_field_calculator_splitter__
pPolygon
0 Kudos
RudPlatt
Deactivated User
Here is my (awkward) solution:

1. Run "polygon_rotate_byFieldValues.cal" using ArcGIS 9.x to rotate the polygons.  This will not work on ArcGIS 10.x
2. On the output, run the minimum bounding geometry tool using geometry type: envelope.
3. On the output, run the minimum bounding geometry tool using geometry type: width.

You must run the MBG tool twice, or else you cannot know the orientation of the longest side.
0 Kudos
DanLee
by Esri Regular Contributor
Esri Regular Contributor
Rud,

You should not have to run the tool twice. Here is how:

Once the polygons are rotated, run Minimum Bounding Geometry tool with the RECTANGLE_BY_WIDTH type, make sure you check the box "Add geometric characteristics as attributes to output". The output has the MBG_Width and MBG_Length fields.

Joel,

Thanks again for pointing out the doc error. The ArcGIS 10 web help has been updated:
http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00170000003q000000
0 Kudos