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.
- As there is no unique identifier on the building layer, create it.
- Create oriented minimum bounding boxes (OMBB) from geoprocessing tools.
- Merge them by location (intersects) with buildings.
- Change the geometry type of merged layer from polygons to lines (tool: polygons to lines).
- Split lines into single sections (tool: split lines).
- 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")
- Create a new layer from selected.
- In the field calculator, create a field for new layer with a unique id ($id).
- Create a point layer with the center of each segment (center of gravity? I'm not sure about English name of this tool).
- At this point, the attributes are lost again, so you need to merge by location. Change the value in accuracy field if needed.
- Create lines from merged point layer (tool: point to path) using field "gid" as identity of each building.
- In the field calculator add the azimuth for new layer with lines:
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.