Monday 21 November 2016

qgis - Percentage of polygon in one shapefile within polygon of another


I'm a newbie, apologies if this is obvious/has already been asked and answered but I couldn't find anything.


I have two shapefiles: 1. an administrative boundary layer for a county in the UK known as an LSOA boundary that has 500 little zones in it 2. a flood zone.



Ideally I want to find out which of the little LSOA zones are ≥50% within the flood zone and end up with a yes/no or a 1/0 for each of the 500 LSOA zones.


But I don't know how to do this. I figured I could Join the two shapefiles, but there's no common attribute between them. Then I thought I could use the Join Attribute by Location function, which worked and shows me which LSOA are in the flood zone, but that's nearly all of them (see image 2).


I think this is an SQL problem but I don't know. I'm new to QGIS and have never used PostgreSQL.


Any help would be greatly appreciated. I can provide whatever info you lovely people need to help me out.


enter image description here


enter image description here



Answer



This is a relatively simple task using the geoprocessing tools included in QGIS.





  1. Calculate the area of your LSOA zones.



    • Open the LSOA layer attribute table.

    • Enable editing mode.

    • Open the field calculator.

    • Create a new field of type "Decimal number (real)" with the expression "$area".

    • Disable editing mode (saving edits).





  2. Merge the flood zone layer into a single multi-part feature.



    • Vector > Geometry Tools > Singleparts to Multipart.

    • Select "--- Merge all ---" for the Unique ID field.




  3. Intersect the LSOA zone layer with the multipart flood zone layer.



    • Vector > Geoprocessing Tools > Intersect.


    • Input layer is the LSOA zones, intersect layer is the flood zones.




  4. The resulting layer will be the parts of the LSOA zones (with the attributes from the LSOA zones layer) which overlapped with the flood zones layer. To calculate the proportion of each LSOA zone within a flood zone:



    • Calculate the area of the intersected features (as in step #1), then

    • Add another field, dividing the original (total) area by the intersected area. The result is a decimal between 0 and 1. Multiply by 100 to give a percentage.





  5. Join the original LSOA layer to the intersected layer, using the unique ID shared by both layers.




  6. Export the joined layer as a new shapefile.




  7. Delete the duplicated attributes.





Et voilĂ !


Without step #2, an individual feature would be created for each different flood zone feature for each LSOA feature. This probably isn't what you want if you're only interested in the total coverage for each LSOA zone. If you want to differentiate between fluvial / tidal / pluvial flooding (and the flood zone data supports it), you could convert singlepart s to multipart specifying the "TYPE" field as the Unique ID field.


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