Skip to content

Commit

Permalink
[processing] Fix missing points in polygons menu item (fix #15670)
Browse files Browse the repository at this point in the history
Also add a unit test
  • Loading branch information
nyalldawson committed Oct 10, 2016
1 parent 90aebd1 commit d4323ad
Show file tree
Hide file tree
Showing 6 changed files with 219 additions and 1 deletion.
2 changes: 1 addition & 1 deletion python/plugins/processing/gui/menus.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
analysisToolsMenu = vectorMenu + "/" + Processing.tr('&Analysis Tools')
defaultMenuEntries.update({'qgis:distancematrix': analysisToolsMenu,
'qgis:sumlinelengths': analysisToolsMenu,
'qgis:pointsinpolygon': analysisToolsMenu,
'qgis:countpointsinpolygon': analysisToolsMenu,
'qgis:listuniquevalues': analysisToolsMenu,
'qgis:basicstatisticsfornumericfields': analysisToolsMenu,
'qgis:basicstatisticsfortextfields': analysisToolsMenu,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<GMLFeatureClassList>
<GMLFeatureClass>
<Name>points_in_polys</Name>
<ElementPath>points_in_polys</ElementPath>
<GeometryType>3</GeometryType>
<SRSName>EPSG:4326</SRSName>
<DatasetSpecificInfo>
<FeatureCount>6</FeatureCount>
<ExtentXMin>-1.00000</ExtentXMin>
<ExtentXMax>10.00000</ExtentXMax>
<ExtentYMin>-3.00000</ExtentYMin>
<ExtentYMax>6.00000</ExtentYMax>
</DatasetSpecificInfo>
<PropertyDefn>
<Name>name</Name>
<ElementPath>name</ElementPath>
<Type>String</Type>
<Width>5</Width>
</PropertyDefn>
<PropertyDefn>
<Name>intval</Name>
<ElementPath>intval</ElementPath>
<Type>Integer</Type>
</PropertyDefn>
<PropertyDefn>
<Name>floatval</Name>
<ElementPath>floatval</ElementPath>
<Type>Real</Type>
</PropertyDefn>
<PropertyDefn>
<Name>NUMPOINTS</Name>
<ElementPath>NUMPOINTS</ElementPath>
<Type>Integer</Type>
</PropertyDefn>
</GMLFeatureClass>
</GMLFeatureClassList>
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="utf-8" ?>
<ogr:FeatureCollection
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=""
xmlns:ogr="http://ogr.maptools.org/"
xmlns:gml="http://www.opengis.net/gml">
<gml:boundedBy>
<gml:Box>
<gml:coord><gml:X>-1</gml:X><gml:Y>-3</gml:Y></gml:coord>
<gml:coord><gml:X>10</gml:X><gml:Y>6</gml:Y></gml:coord>
</gml:Box>
</gml:boundedBy>

<gml:featureMember>
<ogr:points_in_polys fid="polys.0">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>-1,-1 -1,3 3,3 3,2 2,2 2,-1 -1,-1</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:name>aaaaa</ogr:name>
<ogr:intval>33</ogr:intval>
<ogr:floatval>44.123456</ogr:floatval>
<ogr:NUMPOINTS>4</ogr:NUMPOINTS>
</ogr:points_in_polys>
</gml:featureMember>
<gml:featureMember>
<ogr:points_in_polys fid="polys.1">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>5,5 6,4 4,4 5,5</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:name>Aaaaa</ogr:name>
<ogr:intval>-33</ogr:intval>
<ogr:floatval>0</ogr:floatval>
<ogr:NUMPOINTS>1</ogr:NUMPOINTS>
</ogr:points_in_polys>
</gml:featureMember>
<gml:featureMember>
<ogr:points_in_polys fid="polys.2">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>2,5 2,6 3,6 3,5 2,5</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:name>bbaaa</ogr:name>
<ogr:floatval>0.123</ogr:floatval>
<ogr:NUMPOINTS>0</ogr:NUMPOINTS>
</ogr:points_in_polys>
</gml:featureMember>
<gml:featureMember>
<ogr:points_in_polys fid="polys.3">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>6,1 10,1 10,-3 6,-3 6,1</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs><gml:innerBoundaryIs><gml:LinearRing><gml:coordinates>7,0 7,-2 9,-2 9,0 7,0</gml:coordinates></gml:LinearRing></gml:innerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:name>ASDF</ogr:name>
<ogr:intval>0</ogr:intval>
<ogr:NUMPOINTS>2</ogr:NUMPOINTS>
</ogr:points_in_polys>
</gml:featureMember>
<gml:featureMember>
<ogr:points_in_polys fid="polys.4">
<ogr:intval>120</ogr:intval>
<ogr:floatval>-100291.43213</ogr:floatval>
<ogr:NUMPOINTS>0</ogr:NUMPOINTS>
</ogr:points_in_polys>
</gml:featureMember>
<gml:featureMember>
<ogr:points_in_polys fid="polys.5">
<ogr:geometryProperty><gml:Polygon srsName="EPSG:4326"><gml:outerBoundaryIs><gml:LinearRing><gml:coordinates>3,2 6,1 6,-3 2,-1 2,2 3,2</gml:coordinates></gml:LinearRing></gml:outerBoundaryIs></gml:Polygon></ogr:geometryProperty>
<ogr:name>elim</ogr:name>
<ogr:intval>2</ogr:intval>
<ogr:floatval>3.33</ogr:floatval>
<ogr:NUMPOINTS>3</ogr:NUMPOINTS>
</ogr:points_in_polys>
</gml:featureMember>
</ogr:FeatureCollection>
15 changes: 15 additions & 0 deletions python/plugins/processing/tests/testdata/points_in_polys.gfs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<GMLFeatureClassList>
<GMLFeatureClass>
<Name>points_in_polys</Name>
<ElementPath>points_in_polys</ElementPath>
<GeometryType>1</GeometryType>
<SRSName>EPSG:4326</SRSName>
<DatasetSpecificInfo>
<FeatureCount>15</FeatureCount>
<ExtentXMin>-0.13645</ExtentXMin>
<ExtentXMax>7.79548</ExtentXMax>
<ExtentYMin>-2.63675</ExtentYMin>
<ExtentYMax>5.68735</ExtentYMax>
</DatasetSpecificInfo>
</GMLFeatureClass>
</GMLFeatureClassList>
87 changes: 87 additions & 0 deletions python/plugins/processing/tests/testdata/points_in_polys.gml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?xml version="1.0" encoding="utf-8" ?>
<ogr:FeatureCollection
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=""
xmlns:ogr="http://ogr.maptools.org/"
xmlns:gml="http://www.opengis.net/gml">
<gml:boundedBy>
<gml:Box>
<gml:coord><gml:X>-0.1364457831325305</gml:X><gml:Y>-2.636746987951807</gml:Y></gml:coord>
<gml:coord><gml:X>7.795481927710844</gml:X><gml:Y>5.687349397590362</gml:Y></gml:coord>
</gml:Box>
</gml:boundedBy>

<gml:featureMember>
<ogr:points_in_polys fid="points_in_polys.0">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>1.078012048192771,2.499397590361446</gml:coordinates></gml:Point></ogr:geometryProperty>
</ogr:points_in_polys>
</gml:featureMember>
<gml:featureMember>
<ogr:points_in_polys fid="points_in_polys.1">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>0.154518072289156,2.499397590361446</gml:coordinates></gml:Point></ogr:geometryProperty>
</ogr:points_in_polys>
</gml:featureMember>
<gml:featureMember>
<ogr:points_in_polys fid="points_in_polys.2">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>-0.136445783132531,0.551204819277109</gml:coordinates></gml:Point></ogr:geometryProperty>
</ogr:points_in_polys>
</gml:featureMember>
<gml:featureMember>
<ogr:points_in_polys fid="points_in_polys.3">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>0.926204819277108,0.563855421686747</gml:coordinates></gml:Point></ogr:geometryProperty>
</ogr:points_in_polys>
</gml:featureMember>
<gml:featureMember>
<ogr:points_in_polys fid="points_in_polys.4">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>2.279819277108433,3.941566265060241</gml:coordinates></gml:Point></ogr:geometryProperty>
</ogr:points_in_polys>
</gml:featureMember>
<gml:featureMember>
<ogr:points_in_polys fid="points_in_polys.5">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>4.40512048192771,2.347590361445783</gml:coordinates></gml:Point></ogr:geometryProperty>
</ogr:points_in_polys>
</gml:featureMember>
<gml:featureMember>
<ogr:points_in_polys fid="points_in_polys.6">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>4.430421686746987,5.687349397590362</gml:coordinates></gml:Point></ogr:geometryProperty>
</ogr:points_in_polys>
</gml:featureMember>
<gml:featureMember>
<ogr:points_in_polys fid="points_in_polys.7">
</ogr:points_in_polys>
</gml:featureMember>
<gml:featureMember>
<ogr:points_in_polys fid="points_in_polys.8">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>5.379216867469879,0.18433734939759</gml:coordinates></gml:Point></ogr:geometryProperty>
</ogr:points_in_polys>
</gml:featureMember>
<gml:featureMember>
<ogr:points_in_polys fid="points_in_polys.9">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>4.253313253012048,-0.777108433734941</gml:coordinates></gml:Point></ogr:geometryProperty>
</ogr:points_in_polys>
</gml:featureMember>
<gml:featureMember>
<ogr:points_in_polys fid="points_in_polys.10">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>4.569578313253012,-1.257831325301205</gml:coordinates></gml:Point></ogr:geometryProperty>
</ogr:points_in_polys>
</gml:featureMember>
<gml:featureMember>
<ogr:points_in_polys fid="points_in_polys.11">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>7.744879518072288,-2.636746987951807</gml:coordinates></gml:Point></ogr:geometryProperty>
</ogr:points_in_polys>
</gml:featureMember>
<gml:featureMember>
<ogr:points_in_polys fid="points_in_polys.12">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>7.795481927710844,0.525903614457832</gml:coordinates></gml:Point></ogr:geometryProperty>
</ogr:points_in_polys>
</gml:featureMember>
<gml:featureMember>
<ogr:points_in_polys fid="points_in_polys.13">
<ogr:geometryProperty><gml:Point srsName="EPSG:4326"><gml:coordinates>5.126204819277108,4.283132530120482</gml:coordinates></gml:Point></ogr:geometryProperty>
</ogr:points_in_polys>
</gml:featureMember>
<gml:featureMember>
<ogr:points_in_polys fid="points_in_polys.14">
</ogr:points_in_polys>
</gml:featureMember>
</ogr:FeatureCollection>
16 changes: 16 additions & 0 deletions python/plugins/processing/tests/testdata/qgis_algorithm_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1005,3 +1005,19 @@ tests:
OUTPUT:
name: expected/add_geometry_pointz.gml
type: vector


- algorithm: qgis:countpointsinpolygon
name: Count points in polygon
params:
FIELD: NUMPOINTS
POINTS:
name: points_in_polys.gml
type: vector
POLYGONS:
name: polys.gml
type: vector
results:
OUTPUT:
name: expected/points_in_polys.gml
type: vector

0 comments on commit d4323ad

Please sign in to comment.