2

I'm new to GIS and need to create a shortest path avoiding buildings. The buildings are represented as polygons in a shapefile.

In QGIS I created a buffer polygon for each building, corresponding the distance the path have to keep from the buildings. This polygons are overlapping each other a lot by every aglomeration of hauses.

My idea would be to rasterize this overlapping polygons into a DEM layer, so that: the elevation value of each point corresponds to the number of polygons overlapping over this point. And having this, a least cost path algorithm would give me the wanted path.

But... the tools to merge polygons or for rasterization doesn't helped yet.

Isn't this the way how things like this are done? If not with QGIS, maybe with GeoTools or other software running under Linux?

EDIT: an Image to illustrate the problem

Polygons representing buildings, buffer polygons around the buildings and the expected path.

I have in mangenta the polygons representing buildings.
In red an approximation of the expected path.
In turquoise the bufferzones around the houses representing the minimal distance the path have to keep from the houses, if possible.
We see: it is impossible to avoid all bufferzones.
The path costs will increase for each buildig it is coming too close. If the path goes between one house and a group of two houses close together, it have to choose violate the buffer zone of the lonely house over the other.

How I'm trying to solve it: add the number of bufferzone polygons at each raster point to a DEM-Layer.

But maybe my approach isn't ideal:
is there a way to create a DEM layer directly from the buildigs, defining a slope aroung them, summing up the slopes elevation values when they are overlapping?

6
  • Just an idea: clip raster with polygon layer?
    – Babel
    May 3 at 19:30
  • "doesn't helped yet": can you substantiate that? Why, what didn't work? Why not dissolve all polygons? Than you can rasterize this layer, creating pixels with an extreme value like 9999 meters.
    – Babel
    May 3 at 19:32
  • Dissolve is a good start - but if I have the number of overlapping polygons for the raster points, the least cost path algorithm can avoid dense areas, going over lonely houses where it's impossible to avoid it completely.
    – Nic Stray
    May 4 at 20:49
  • Sharing your data (at least a sample) and or a screenshot would extremely help to understand what you want to do. Otherwise, it's difficult to imagine and it will be just guesswork.
    – Babel
    May 4 at 20:53
  • I hope the added image with explanations will help to clarify my intents.
    – Nic Stray
    May 5 at 11:16
1
  1. Create a polygon-grid (squares) over you buffer polygons in the same size that you want your pixels to be (in my case: 1x1 meter). The extent of the grid should be the same as the buffer layer.

  2. Than calculate how many buffers each grid-cell covers. You can do this calculating a new attribute with field calculator and an expression like this: array_length ( overlay_intersects( 'buffer', $id)) where buffer is the name of your buffer layer (overlay_intersects is available since QGIS 3.16). Depending on the extent, number of features, size of grid etc., this can quite take a while.

  3. Now, based on this attribute value, you can rasterize the grid layer. You get a raster with the pixel value corresponding to the number of buffer-polygons that overlap at this point. Use the same pixel size as for the grid-cells and use the grid layer for the extent of the raster.

Screenshot 1: buildings (orange), overlapping buffer (blue), and grid with size 1x1 meter: enter image description here

Screenshot 2: Close-up of the grid, labeled with the output of the array_length() expression from above, corresponding to the no. of overlapping buffer-polygons: enter image description here

Screenshot 3: result of rasterize: enter image description here

2
  • It's exactly what I was looking for! Really important to upgrade to QGIS 3.16 - the version in the repository of my ubuntu neighter has array_length. Unfortunately the calculations really need hours over a little Cutout of my data (actually 56.000 from 600.000 Grid cells with 100x100 meters).
    – Nic Stray
    May 7 at 13:51
  • New versions indeed come always with tons of new functions. array_length() was introduced in QGIS 3.0: qgis.org/en/site/forusers/visualchangelog30/…
    – Babel
    May 7 at 13:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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