6

I want to get the perimeter of each polygon (building) I have. Some polygons are adjacent, thus sharing a side. Shared sides should be excluded from the calculation for each polygon. In simpler words: I need to get the exposition perimeter (and then the surface) of each building. One workaround I came up with is:

  1. get the lines from the polygon and assign to these line features the polygon ID. No matter which ID gets assigned to the shared sides.
  2. create a dissolved layer of these polygons so that adjacent polygons are merged into one, then get a negative buffer. The buffering should be as tight as possible (smaller than the smallest polygon).
  3. use this negative buffer to exclude the intersected lines, which should only be the shared sides.

Is there a more straightforward and possibly safer approach to get perimeters without shared sides?

Taras
  • 32,823
  • 4
  • 66
  • 137
Michele Cordini
  • 877
  • 8
  • 20
  • 1
    I suggest you to use topology data; topology stores the boundaries as arcs, as well as which polygons share these arcs, so you are looking for polygons that have an arc shared with no other polygon (or the "outer" polygon), you may do that in postgis or with topojson https://gis.stackexchange.com/questions/447724/computing-polygon-arc-table-and-left-right-polygon-table-in-postgis – Elio Diaz Dec 15 '23 at 16:53

2 Answers2

6

Use this expression to calculate the perimeter without shared sides:

 length(
     intersection (
         boundary($geometry),
         boundary(
             buffer (
                 collect_geometries (
                     array_append(
                         overlay_touches (@layer, $geometry),
                         $geometry
                     )
                 ),0
             )
         )
     )
 )

Remark: make sure you use a local CRS that is suitable for measurements, e.g. local UTM zone or a national grid.

The expression (including a round() function) used to calculate the outer perimeter - for visualization purpose, the blue lines show the distance measured for each polygon; the polygon in the red oval shows the calculated vs. measured value to demonstrate that the expression returns the desired result:

enter image description here

Babel
  • 71,072
  • 14
  • 78
  • 208
4

This seems to do the trick:

  1. "Dissolve" the building layer
  2. Convert the dissolved layer to lines using "Polygons to lines"
  3. Run the "Intersection" tool between the original buildings and the lines

Result:

enter image description here

Taras
  • 32,823
  • 4
  • 66
  • 137
Pieter
  • 1,876
  • 7
  • 9