Thursday 19 May 2016

intersection - Mapping building to only one grid which contains more than half of its area using QGIS?


I have a shapefile of a city map and I have created vector grid as polygons.


After intersecting the two shapefiles, a building will map to all the grids it overlaps.


However, if I just want it to map to the one grid which contains the majority of the building (>50%), how could I achieve it?


Is there a function or plugin in gqis for this task? Or do I have to write my own code to do this?


I am new to QGIS.



Answer




  1. Intersect your building layer and grid layer (Vector > Geoprocessing Tools > Intersect). The result should be your buildings, cut up wherever they cross a grid line. Those pieces should have both the building id attribute and the grid cell id attribute.

  2. Open the attribute table use the Field Calculator to create a new field and calculate the area of each cut up building piece. The calculation is simple: $area. This method also ensures that the largest piece gets the grid ID, even if that piece is less than 50% of the total.


  3. Once you have the areas added to the table, you'll need the Group Stats plugin. With that you can use the building ID as a row (see the tutorial) and the area field as a column with the value max. Should generate a table with just one row per building, showing only the maximum area. Theoretically you'll have a grid ID in there as well that will tell you which one that building falls in. You can save out the resulting table and join it back to the buildings based on building ID to transfer the chosen grid ID.


Note this is untested, and I'm not well versed on the finer points of QGIS (particularly that plugin). This is based on how I would do it in ArcGIS and looking up comparable tools in QGIS.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...