4

I have a shapefile with building poligons and a raster file with the roof orientation (0-360º). I would like to assign the orientation to the building shapefile using QGIS. I converted the raster file to vector. My strategy rely on adding columns to the building shapefile assigning the 4 main orientations (N,W,S,E) areas.

One example. "dataframe.shp":

enter image description here enter image description here

and vector file of the orientation (with the attribute table presenting the orientation values in º) '"orientation.shp"' :

enter image description here enter image description here

With this, what I would like to obtain is 4 columns with the area for each main orientation for each building polygon.

Example of rational -> using field calculator for the south orientaion column:

CASE
    WHEN  "DN">135 and "DN"<225  THEN (SUM AREA OF each polgon within this range inside building polygon)
    Else 0
END

I dont know how to complete the conditional and assign it to each building polygon ('dataframe.shp'). Also, I am afraid that is infesiable for a large dataset.

1 Answer 1

5

You can use sum() with a filter, like this:

sum(area($geometry),filter:="DN">135 and "DN"<225 and intersects($geometry,get_feature('buildingpolygon',"buildingid",'thisbuildingid'))

Maybe even simpler if you add the building ids first via an intersection operation and then just use this in an group_by parameter, like:

sum(area($geometry),group_by:="buildingid",filter:="DN">135 and "DN"<225)
5
  • TY. But with this option I cannot perform the operation for all building polygons, right? Because I am refering to the building id. Also, I performe this in the "Field Calculator" for which layer? Commented Jan 13, 2023 at 15:29
  • Perform this in the layer 'orientation'. You can calculate it for all buildings at once because the group by statement ensures the correct sum is added to the correct feature.
    – MrXsquared
    Commented Jan 13, 2023 at 15:36
  • Ok. So I did this: sum("DN",group_by:="Name",filter:="DN">135 and "DN"<225) after the intersection with the dataframe. But the sum value that I get it is not the sum of the areas of the "orientation" layer polygons (ex pixels from raster). It seems the sum of the degree values. As I would like to have this info in the "dataframe" layer I would need to perform the "join by location" again ...? Commented Jan 13, 2023 at 16:05
  • Sorry, my mistake. Use area($geometry) or $area in the sum, just corrected the answer.
    – MrXsquared
    Commented Jan 13, 2023 at 16:10
  • TY. Worked fine. I had to perform again a join location to consider the data on the dataframe. Commented Jan 13, 2023 at 21:55

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