3

I have a shapefile with many minimum bounding box (envelope) polygons and I need to find out, if the boxes are rather landscape or portrait format. (See pic below, one of the selected boxes should be marked as landscape, the other as portrait)

I got the width and length of the boxes, however, the shorter line is always taken as the width by ESRI default so I cannot find out if the box is landscape or portrait using these values.

Anyone has an idea on how to solve this in an easy way?

All I can come up with is computing the corner coordinates, but not sure how to do it exactly.

I work with ArcGIS Desktop 10.1.

enter image description here

  • 1
    How did you get the width and height of the boxes? What language? In ArcObjects you can get the envelope (IEnvelope) from the geometry (also in arcpy) where the width is always delta X and the height is always delta Y for the feature... if dX > dY landscape else portrait. Arcpy has geometry.extent.XMin (and YMin and XMax and YMax) you could calculate your dX and dY from here - no swapping! Can you post your code so far to get an idea where you're up to please. – Michael Stimson May 13 '15 at 4:39
  • 1
    "the shorter line is always taken as the width by ESRI default" does not sound right to me either - if you post your code snippet for this it will no doubt help. – PolyGeo May 13 '15 at 5:22
  • @MichaelMiles-Stimson I didn't use a code - I am not familiair with coding.. I used the minimum bounding box tool in ArcGIS instead link ◾For 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. – user3476078 May 13 '15 at 6:38
7

Michael Miles-Stimson had the same idea as me, but since you aren't familiar with coding, here's another (similar) option. Turns out this is pretty easy to do using Field Calculator.

Create a field called something like "Orientation" and make it a text type.

Open the field calculator and set the parser to Python.

Tick the "Show Codeblock" box and enter the following code:

def orientation(shape):
    if shape.extent.YMax - shape.extent.YMin > shape.extent.XMax - shape.extent.XMin:
        return "Portrait"
    elif shape.extent.YMax - shape.extent.YMin < shape.extent.XMax - shape.extent.XMin:
        return "Landscape"
    else: 
        return "Square"

In the expression type the following:

orientation( !SHAPE!)

enter image description here

|improve this answer|||||
  • Thanks, I came up with a similar idea without coding now as well! – user3476078 May 13 '15 at 7:15
0

Actually the answer is very easy 1) Calculate XMax XMin YMax YMin in Field Calculator with Python

!shape.extent.XMax!

Create 2 Fields where you calculate the difference between XMax and XMin, same for Y. Calculate Ratio All bigger than 1 is landscape, all smaller than 1 is portrait

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.