[GIS] Determining the direction of polygons

alignmentdirectionpolygonqgis

enter image description hereIs there a way in QGIS to figure out the direction of a polygon, if there are no values given? What I need to know is if a polygon is directed to the south.

I want to know the direction of a house because of a solar research. I want to say if the longer side of a house is directed to the street and this direction is south or north or west or east.

is there a way to say "draw a (simple) line from the centriod of a polygon to the longest side of the polygon?

Best Answer

  1. As there is no unique identifier on the building layer, create it. enter image description here
  2. Create oriented minimum bounding boxes (OMBB) from geoprocessing tools. OMBB
  3. Merge them by location (intersects) with buildings. merge
  4. Change the geometry type of merged layer from polygons to lines (tool: polygons to lines). polygons to lines
  5. Split lines into single sections (tool: split lines).
  6. On layer with split lines use "Select by expression" to choose the two shortest segments of the OMBB of each building ("gid" is the identity of each building and it is required)

$length < (minimum( $length , "gid" )+ 0.1)

The shortest sections of each building have the same or near the same length, so two sections will be selected for each building. For some reason not all the necessary lines are selected and I had to select several lines manually. Does anyone know why? Alternatively (or maybe better) use this:

$length != maximum($length, "gid")

  1. Create a new layer from selected.
  2. In the field calculator, create a field for new layer with a unique id ($id).
  3. Create a point layer with the center of each segment (center of gravity? I'm not sure about English name of this tool).
  4. At this point, the attributes are lost again, so you need to merge by location. Change the value in accuracy field if needed. enter image description here
  5. Create lines from merged point layer (tool: point to path) using field "gid" as identity of each building.

enter image description here

  1. In the field calculator add the azimuth for new layer with lines: degrees (azimuth(point_n($geometry,1),(point_n($geometry,2)))) enter image description here

I see two problems in this method: 1. It is not known that line runs from north to south or from south to north. 2. For some geometries, the result may be different than expected (see largest geometry above).

Works in QGIS 2.18 and later. Does not work in older.

Related Question