# Determining the direction of polygons?

Is 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.

• Which software are you using? Commented Mar 28, 2017 at 7:22
• Can you give some examples (pictures) of what you mean by "polygon is directed to the south", please?
– PolyGeo
Commented Mar 28, 2017 at 7:27
• I would start from the center point of your polygon and find the shortest way to the border. That's also the direction of your roof. Of course this method only works for rectangular houses with just an outer ring. Commented Mar 28, 2017 at 9:17
• Thanks, how would you do this? can you give me a specific method? Commented Mar 28, 2017 at 9:42
• The direction of the longest axis of the polygon will not tell you anything about the aspect of the roof, which is what you really need for solar analysis. For that you will need Lidar, Radar or to use photogrametry from aerial photography/satellite imagery from a couple of look angles. Commented Mar 28, 2017 at 13:55

1. As there is no unique identifier on the building layer, create it.
2. Create oriented minimum bounding boxes (OMBB) from geoprocessing tools.
3. Merge them by location (intersects) with buildings.
4. Change the geometry type of merged layer from polygons to lines (tool: 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.
5. Create lines from merged point layer (tool: point to path) using field "gid" as identity of each building.

1. In the field calculator add the azimuth for new layer with lines: `degrees (azimuth(point_n(\$geometry,1),(point_n(\$geometry,2))))`

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.

• Your send by heaven! Thanks a lot! But at point 5. I don't get it. Do you choose the right attributes by "Select by Expression" tool or how do you get the shortest segments? And what is the "gid" my Layer just includes the columns "Area", "Perimeter", "Width" and "Height" Commented Mar 29, 2017 at 8:53
• I have added point 1 and updated 6 (earlier 5). Now it should be clearer. Shortest segments are calculated from geometry (\$length) and grouped by "gid" Commented Mar 29, 2017 at 10:52
• Hey there, tomalos..... I tried do come along with point 11... Every time I try to build the lines between my points i get nothing. start and end point of the path are the same every time. beside the fact that i just get the columns "MEANX", "MEANY" and "UID" there is no "ID" field in the attribute table. When adding an "ID" field the Result is still the same start and end point of the path... Commented Mar 29, 2017 at 12:58
• Go back to step 10. Before you start step 11, you need to have the "gid" field in the attribute table from buildings layer. For both points of each building should be assigned "gid" of this building. In summary: one building, the same "gid" for two points with two different "UIDs" :). If so, go to point 11. and in the "Point group field" select "gid" and for "Point order field" select "UID". Commented Mar 29, 2017 at 13:26
• I guess the problem is there are no Groups in the point layer. I do have those groups in the clipped layer with the shortest segments, because of the 2 equal sides. But if I go to Vector==> Anlysis tools ==> mean coordinates . The point layer i get contains the coulmns "MEANX", "MEANY" and "UID". The Field which displays the same categories is lost. Commented Mar 29, 2017 at 13:29