Skip to content

Commit

Permalink
msGetInnerList(): fix behaviour for inner ring touching its outer ring (
Browse files Browse the repository at this point in the history
#5299)

Currently the behaviour was undefined if the first point of the inner
ring touched its outer ring.
  • Loading branch information
rouault committed Sep 8, 2016
1 parent 9b8a907 commit f8e104e
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 1 deletion.
12 changes: 11 additions & 1 deletion mapprimitive.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,17 @@ int *msGetInnerList(shapeObj *shape, int r, int *outerlist)
continue;
}

list[i] = msPointInPolygon(&(shape->line[i].point[0]), &(shape->line[r]));
/* A valid inner ring may touch its outer ring at most one point. */
/* In the case the first point matches a vertex of an outer ring, */
/* msPointInPolygon() might return 0 or 1 (depending on coordinate values, */
/* see msGetOuterList()), so test a second point if the first test */
/* returned that the point is not inside the outer ring. */
/* Fixes #5299 */
/* Of course all of this assumes that the geometries are indeed valid in */
/* OGC terms, otherwise all logic of msIsOuterRing(), msGetOuterList(), */
/* and msGetInnerList() has undefined behaviour. */
list[i] = msPointInPolygon(&(shape->line[i].point[0]), &(shape->line[r])) ||
msPointInPolygon(&(shape->line[i].point[1]), &(shape->line[r]));
}

return(list);
Expand Down
2 changes: 2 additions & 0 deletions msautotest/wxs/data/test5299.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
id,WKT
1,"MULTIPOLYGON(((676881.746 253159.65,676952.5 253142.812,676984.539 253076.568,676992.16 253047.552,676907.575 252978.182,676793.971 252977.057,676763.746 253101.446,676881.746 253159.65),(676881.746 253159.65,676835.762 253108.566,676841.704 253079.649,676870.271 253078.765,676924.143 253120.438,676881.746 253159.65)))"
45 changes: 45 additions & 0 deletions msautotest/wxs/expected/wfs_test5299.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
Content-Type: text/xml; charset=UTF-8

<?xml version='1.0' encoding="UTF-8" ?>
<wfs:FeatureCollection
xmlns:ms="http://mapserver.gis.umn.edu/mapserver"
xmlns:wfs="http://www.opengis.net/wfs"
xmlns:gml="http://www.opengis.net/gml"
xmlns:ogc="http://www.opengis.net/ogc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-basic.xsd
http://mapserver.gis.umn.edu/mapserver http://127.0.0.0.1?SERVICE=WFS&amp;VERSION=1.0.0&amp;REQUEST=DescribeFeatureType&amp;TYPENAME=test5299&amp;OUTPUTFORMAT=XMLSCHEMA">
<gml:boundedBy>
<gml:Box srsName="EPSG:4326">
<gml:coordinates>676763.746000,252977.057000 676992.160000,253159.650000</gml:coordinates>
</gml:Box>
</gml:boundedBy>
<gml:featureMember>
<ms:test5299>
<gml:boundedBy>
<gml:Box srsName="EPSG:4326">
<gml:coordinates>676763.746000,252977.057000 676992.160000,253159.650000</gml:coordinates>
</gml:Box>
</gml:boundedBy>
<ms:msGeometry>
<gml:MultiPolygon srsName="EPSG:4326">
<gml:polygonMember>
<gml:Polygon>
<gml:outerBoundaryIs>
<gml:LinearRing>
<gml:coordinates>676881.746000,253159.650000 676952.500000,253142.812000 676984.539000,253076.568000 676992.160000,253047.552000 676907.575000,252978.182000 676793.971000,252977.057000 676763.746000,253101.446000 676881.746000,253159.650000 </gml:coordinates>
</gml:LinearRing>
</gml:outerBoundaryIs>
<gml:innerBoundaryIs>
<gml:LinearRing>
<gml:coordinates>676881.746000,253159.650000 676835.762000,253108.566000 676841.704000,253079.649000 676870.271000,253078.765000 676924.143000,253120.438000 676881.746000,253159.650000 </gml:coordinates>
</gml:LinearRing>
</gml:innerBoundaryIs>
</gml:Polygon>
</gml:polygonMember>
</gml:MultiPolygon>
</ms:msGeometry>
</ms:test5299>
</gml:featureMember>
</wfs:FeatureCollection>

41 changes: 41 additions & 0 deletions msautotest/wxs/wfs_test5299.map
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#
# Test fix for #5299
#
# REQUIRES: SUPPORTS=WFS INPUT=OGR
#
# Generate dump to gml2
# RUN_PARMS: wfs_test5299.xml [MAPSERV] QUERY_STRING="map=[MAPFILE]&SERVICE=WFS&VERSION=1.0.0&REQUEST=GetFeature&TYPENAME=test5299" > [RESULT]

MAP
NAME test
EXTENT 0 0 10 10
SIZE 200 200

PROJECTION
"init=epsg:4326"
END

WEB
METADATA
OWS_ONLINERESOURCE "http://127.0.0.0.1"
OWS_SRS "EPSG:4326"
OWS_ENABLE_REQUEST "*"
END
END

LAYER
NAME test5299
TYPE POLYGON
STATUS ON
CONNECTIONTYPE OGR
CONNECTION "data/test5299.csv"

METADATA
"ows_geomtype" "MultiPolygon"
END

STYLEITEM "AUTO"
CLASS
END
END
END

0 comments on commit f8e104e

Please sign in to comment.