Skip to content

Commit

Permalink
[FEATURE][processing] New algorithm "Overlap analysis"
Browse files Browse the repository at this point in the history
This algorithm calculates the area and percentage cover
by which features from an input layer are overlapped by
features from a selection of overlay layers.

New attributes are added to the output layer reporting
the total area of overlap and percentage of the input
feature overlapped by each of the selected overlay layers.

This is quite a common GIS task request, yet is full
of traps for inexperienced users, and the amount of
manual data work usually done by users to calculate
these figures can often lead to mistakes and inaccurate
results. It's nice to have a robust, fast, inbuilt
algorithm which allows this task to be done in a
single step without risk of human error.
  • Loading branch information
nyalldawson committed May 13, 2019
1 parent 56a6edf commit 2ec429c
Show file tree
Hide file tree
Showing 14 changed files with 1,116 additions and 0 deletions.
Binary file not shown.
86 changes: 86 additions & 0 deletions python/plugins/processing/tests/testdata/custom/overlay0_4326.gml
@@ -0,0 +1,86 @@
<?xml version="1.0" encoding="utf-8" ?>
<ogr:FeatureCollection
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ogr.maptools.org/ overlay0_4326.xsd"
xmlns:ogr="http://ogr.maptools.org/"
xmlns:gml="http://www.opengis.net/gml">
<gml:boundedBy>
<gml:Box>
<gml:coord><gml:X>8.983152841195214e-06</gml:X><gml:Y>8.983152840993819e-06</gml:Y></gml:coord>
<gml:coord><gml:X>8.983152841195213e-05</gml:X><gml:Y>0.0001437304454559011</gml:Y></gml:coord>
</gml:Box>
</gml:boundedBy>

<gml:featureMember>
<ogr:overlay0_4326 fid="overlay0_4326.0">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>0.000008983152841,0.000008983152841 0.000044915764206,0.000008983152841 0.000044915764206,0.000044915764205 0.000008983152841,0.000044915764205 0.000008983152841,0.000008983152841</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:id_a>A1</ogr:id_a>
</ogr:overlay0_4326>
</gml:featureMember>
<gml:featureMember>
<ogr:overlay0_4326 fid="overlay0_4326.1">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>0.000017966305682,0.000017966305682 0.000035932611365,0.000017966305682 0.000035932611365,0.000035932611364 0.000017966305682,0.000035932611364 0.000017966305682,0.000017966305682</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:id_a>A2</ogr:id_a>
</ogr:overlay0_4326>
</gml:featureMember>
<gml:featureMember>
<ogr:overlay0_4326 fid="overlay0_4326.2">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>0.000062882069888,0.000017966305682 0.000080848375571,0.000017966305682 0.000080848375571,0.000035932611364 0.000062882069888,0.000035932611364 0.000062882069888,0.000017966305682</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:id_a>A3</ogr:id_a>
</ogr:overlay0_4326>
</gml:featureMember>
<gml:featureMember>
<ogr:overlay0_4326 fid="overlay0_4326.3">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>0.000053898917047,0.000008983152841 0.000089831528412,0.000008983152841 0.000089831528412,0.000044915764205 0.000053898917047,0.000044915764205 0.000053898917047,0.000008983152841</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:id_a>A4</ogr:id_a>
</ogr:overlay0_4326>
</gml:featureMember>
<gml:featureMember>
<ogr:overlay0_4326 fid="overlay0_4326.4">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>0.000008983152841,0.000053898917046 0.000026949458524,0.000053898917046 0.000026949458524,0.00008983152841 0.000008983152841,0.00008983152841 0.000008983152841,0.000053898917046</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:id_a>A5</ogr:id_a>
</ogr:overlay0_4326>
</gml:featureMember>
<gml:featureMember>
<ogr:overlay0_4326 fid="overlay0_4326.5">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>0.000026949458524,0.000053898917046 0.000044915764206,0.000053898917046 0.000044915764206,0.00008983152841 0.000026949458524,0.00008983152841 0.000026949458524,0.000053898917046</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:id_a>A6</ogr:id_a>
</ogr:overlay0_4326>
</gml:featureMember>
<gml:featureMember>
<ogr:overlay0_4326 fid="overlay0_4326.6">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>0.000053898917047,0.000053898917046 0.000089831528412,0.000053898917046 0.000089831528412,0.00008983152841 0.000053898917047,0.00008983152841 0.000053898917047,0.000053898917046</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:id_a>A7</ogr:id_a>
</ogr:overlay0_4326>
</gml:featureMember>
<gml:featureMember>
<ogr:overlay0_4326 fid="overlay0_4326.7">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>0.000008983152841,0.000098814681251 0.000035932611365,0.000098814681251 0.000035932611365,0.000125764139774 0.000008983152841,0.000125764139774 0.000008983152841,0.000098814681251</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:id_a>A8</ogr:id_a>
</ogr:overlay0_4326>
</gml:featureMember>
<gml:featureMember>
<ogr:overlay0_4326 fid="overlay0_4326.8">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>0.000008983152841,0.000116780986933 0.000035932611365,0.000116780986933 0.000035932611365,0.000143730445456 0.000008983152841,0.000143730445456 0.000008983152841,0.000116780986933</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:id_a>A9</ogr:id_a>
</ogr:overlay0_4326>
</gml:featureMember>
<gml:featureMember>
<ogr:overlay0_4326 fid="overlay0_4326.9">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>0.000017966305682,0.000107797834092 0.000044915764206,0.000107797834092 0.000044915764206,0.000134747292615 0.000017966305682,0.000134747292615 0.000017966305682,0.000107797834092</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:id_a>A10</ogr:id_a>
</ogr:overlay0_4326>
</gml:featureMember>
<gml:featureMember>
<ogr:overlay0_4326 fid="overlay0_4326.10">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>0.000053898917047,0.000098814681251 0.000089831528412,0.000098814681251 0.000089831528412,0.000107797834092 0.000062882069888,0.000107797834092 0.000062882069888,0.000134747292615 0.000053898917047,0.000134747292615 0.000053898917047,0.000098814681251</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:id_a>A11</ogr:id_a>
</ogr:overlay0_4326>
</gml:featureMember>
<gml:featureMember>
<ogr:overlay0_4326 fid="overlay0_4326.11">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>0.00007186522273,0.000116780986933 0.000089831528412,0.000116780986933 0.000089831528412,0.000134747292615 0.00007186522273,0.000134747292615 0.00007186522273,0.000116780986933</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:id_a>A12</ogr:id_a>
</ogr:overlay0_4326>
</gml:featureMember>
</ogr:FeatureCollection>
29 changes: 29 additions & 0 deletions python/plugins/processing/tests/testdata/custom/overlay0_4326.xsd
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://ogr.maptools.org/" xmlns:ogr="http://ogr.maptools.org/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:gml="http://www.opengis.net/gml" elementFormDefault="qualified" version="1.0">
<xs:import namespace="http://www.opengis.net/gml" schemaLocation="http://schemas.opengis.net/gml/2.1.2/feature.xsd"/>
<xs:element name="FeatureCollection" type="ogr:FeatureCollectionType" substitutionGroup="gml:_FeatureCollection"/>
<xs:complexType name="FeatureCollectionType">
<xs:complexContent>
<xs:extension base="gml:AbstractFeatureCollectionType">
<xs:attribute name="lockId" type="xs:string" use="optional"/>
<xs:attribute name="scope" type="xs:string" use="optional"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:element name="overlay0_4326" type="ogr:overlay0_4326_Type" substitutionGroup="gml:_Feature"/>
<xs:complexType name="overlay0_4326_Type">
<xs:complexContent>
<xs:extension base="gml:AbstractFeatureType">
<xs:sequence>
<xs:element name="geometryProperty" type="gml:PolygonPropertyType" nillable="true" minOccurs="0" maxOccurs="1"/>
<xs:element name="id_a" nillable="true" minOccurs="0" maxOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string">
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:schema>
Binary file modified python/plugins/processing/tests/testdata/custom/pol.gpkg
Binary file not shown.
Binary file not shown.

0 comments on commit 2ec429c

Please sign in to comment.