Opened 4 years ago

Closed 3 years ago

Last modified 3 years ago

#1031 closed defect (invalid)

Union of two Polygons results in GeometryCollection

Reported by: brownjt Owned by: geos-devel@…
Priority: minor Milestone: 3.10.0
Component: Default Version: 3.8.0
Severity: Unassigned Keywords:
Cc:

Description

#include <geos/io/WKBReader.h>
#include <sstream>
#include <cassert>

int main()
{
    std::string a = "008000000300000001000000AD411EBB077FFFFFFF415079606E6666660000000000000000411EBE527FFFFFFF415079606E6666660000000000000000411EBF3E199999984150795F119999990000000000000000411EBF3EB333333241507954BE6666660000000000000000411EBF3B4CCCCCCC41507950419999990000000000000000411EBF3DB33333324150794C9E6666660000000000000000411EBF4E1999999841507945980000000000000000000000411EBF50B333333241507941719999990000000000000000411EBF58E66666654150793D5E6666660000000000000000411EBF874CCCCCCC41507928AB3333330000000000000000411EBF8BE666666541507927DE6666660000000000000000411EBF8AE666666541507926FB3333330000000000000000411EBFA37FFFFFFF415079173E6666660000000000000000411EBFA0199999984150790CA19999990000000000000000411EBF91B3333332415079075B3333330000000000000000411EBF881999999841507901E80000000000000000000000411EBF85B3333332415078FE180000000000000000000000411EBF88E6666665415078FD1E6666660000000000000000411EBF82B3333332415078F9E4CCCCCC0000000000000000411EBF81E6666665415078F5DB3333330000000000000000411EBF6CE6666665415078E47B3333330000000000000000411EBF6C19999998415078E174CCCCCC0000000000000000411EBF737FFFFFFF415078DCFE6666660000000000000000411EB9DB4CCCCCCC415078DCFE6666660000000000000000411EB9157FFFFFFF415078DE9E6666660000000000000000411EB88B19999998415078DF4B3333330000000000000000411EB7E64CCCCCCC415078DFD19999990000000000000000411EB72E19999998415078E00B3333330000000000000000411EB72E19999998415078E05E6666660000000000000000411EB72A19999998415078E0619999990000000000000000411EB72A19999998415078E0DE6666660000000000000000411EB72619999998415078E0E19999990000000000000000411EB72619999998415078E19E6666660000000000000000411EB72219999998415078E1A19999990000000000000000411EB72219999998415078E21E6666660000000000000000411EB71E19999998415078E2219999990000000000000000411EB71E19999998415078E29E6666660000000000000000411EB71A19999998415078E2A19999990000000000000000411EB71A19999998415078E31E6666660000000000000000411EB71619999998415078E3219999990000000000000000411EB71619999998415078E39E6666660000000000000000411EB71219999998415078E3A19999990000000000000000411EB71219999998415078E41E6666660000000000000000411EB70E19999998415078E4219999990000000000000000411EB70E19999998415078E49E6666660000000000000000411EB70A19999998415078E4A19999990000000000000000411EB70A19999998415078E51E6666660000000000000000411EB70619999998415078E5219999990000000000000000411EB70619999998415078E59E6666660000000000000000411EB70219999998415078E5A19999990000000000000000411EB70219999998415078E61E6666660000000000000000411EB6FE19999998415078E6219999990000000000000000411EB6FE19999998415078E69E6666660000000000000000411EB6FA19999998415078E6A19999990000000000000000411EB6FA19999998415078E71E6666660000000000000000411EB6F619999998415078E7219999990000000000000000411EB6F619999998415078E75E6666660000000000000000411EB6EE19999998415078E7619999990000000000000000411EB6EA19999998415078E7DE6666660000000000000000411EB6E619999998415078E7E19999990000000000000000411EB6E619999998415078E81E6666660000000000000000411EB6DE19999998415078E8219999990000000000000000411EB6DA19999998415078E89E6666660000000000000000411EB6D619999998415078E8A19999990000000000000000411EB6D619999998415078E8DE6666660000000000000000411EB6CE19999998415078E8E19999990000000000000000411EB6CA19999998415078E95E6666660000000000000000411EB6C619999998415078E9619999990000000000000000411EB6C619999998415078E99E6666660000000000000000411EB6BE19999998415078E9A19999990000000000000000411EB6BA19999998415078EA1E6666660000000000000000411EB6B619999998415078EA219999990000000000000000411EB6B619999998415078EA5E6666660000000000000000411EB6AE19999998415078EA619999990000000000000000411EB6AA19999998415078EADE6666660000000000000000411EB6A619999998415078EAE19999990000000000000000411EB6A619999998415078EB1E6666660000000000000000411EB69E19999998415078EB219999990000000000000000411EB69A19999998415078EB9E6666660000000000000000411EB69619999998415078EBA19999990000000000000000411EB69619999998415078EBDE6666660000000000000000411EB68E19999998415078EBE19999990000000000000000411EB68A19999998415078EC5E6666660000000000000000411EB68619999998415078EC619999990000000000000000411EB68619999998415078EC9E6666660000000000000000411EB67E19999998415078ECA19999990000000000000000411EB67A19999998415078ED1E6666660000000000000000411EB67619999998415078ED219999990000000000000000411EB67619999998415078ED5E6666660000000000000000411EB66E19999998415078ED619999990000000000000000411EB66A19999998415078EDDE6666660000000000000000411EB66219999998415078EDE19999990000000000000000411EB65E19999998415078EE5E6666660000000000000000411EB65A19999998415078EE619999990000000000000000411EB65A19999998415078EE9E6666660000000000000000411EB65219999998415078EEA19999990000000000000000411EB64E19999998415078EF1E6666660000000000000000411EB64A19999998415078EF219999990000000000000000411EB64A19999998415078EF5E6666660000000000000000411EB64219999998415078EF619999990000000000000000411EB63E19999998415078EFDE6666660000000000000000411EB63A19999998415078EFE19999990000000000000000411EB63A19999998415078F01E6666660000000000000000411EB63219999998415078F0219999990000000000000000411EB62E19999998415078F09E6666660000000000000000411EB62A19999998415078F0A19999990000000000000000411EB62A19999998415078F0DE6666660000000000000000411EB62219999998415078F0E19999990000000000000000411EB61E19999998415078F15E6666660000000000000000411EB61A19999998415078F1619999990000000000000000411EB61A19999998415078F19E6666660000000000000000411EB61219999998415078F1A19999990000000000000000411EB60E19999998415078F21E6666660000000000000000411EB60A19999998415078F2219999990000000000000000411EB60A19999998415078F25E6666660000000000000000411EB60619999998415078F2619999990000000000000000411EB60619999998415078FB5E6666660000000000000000411EB60219999998415078FB619999990000000000000000411EB60219999998415079079E6666660000000000000000411EB5FE1999999841507907A19999990000000000000000411EB5FE1999999841507913DE6666660000000000000000411EB5FA1999999841507913E19999990000000000000000411EB5FA19999998415079201E6666660000000000000000411EB5F61999999841507920219999990000000000000000411EB5F6199999984150792C9E6666660000000000000000411EB5F2199999984150792CA19999990000000000000000411EB5F21999999841507938DE6666660000000000000000411EB5EE1999999841507938E19999990000000000000000411EB5EE19999998415079451E6666660000000000000000411EB5EA1999999841507945219999990000000000000000411EB5EA19999998415079515E6666660000000000000000411EB5E61999999841507951619999990000000000000000411EB5E619999998415079565E6666660000000000000000411EB5E21999999841507956619999990000000000000000411EB5E21999999841507956DE6666660000000000000000411EB5DE1999999841507956E19999990000000000000000411EB5DE19999998415079575E6666660000000000000000411EB5DA1999999841507957619999990000000000000000411EB5DA1999999841507957DE6666660000000000000000411EB5D61999999841507957E19999990000000000000000411EB5D619999998415079585E6666660000000000000000411EB5D21999999841507958619999990000000000000000411EB5D21999999841507958DE6666660000000000000000411EB5CE1999999841507958E19999990000000000000000411EB5CE19999998415079595E6666660000000000000000411EB5CA1999999841507959619999990000000000000000411EB5CA1999999841507959DE6666660000000000000000411EB5C61999999841507959E19999990000000000000000411EB5C6199999984150795A5E6666660000000000000000411EB5C2199999984150795A619999990000000000000000411EB5C2199999984150795ADE6666660000000000000000411EB5BE199999984150795AE19999990000000000000000411EB5BE199999984150795B5E6666660000000000000000411EB5BA199999984150795B619999990000000000000000411EB5BA199999984150795BDE6666660000000000000000411EB5B6199999984150795BE19999990000000000000000411EB5B6199999984150795C5E6666660000000000000000411EB5B2199999984150795C619999990000000000000000411EB5B2199999984150795CDE6666660000000000000000411EB5AE199999984150795CE19999990000000000000000411EB5AE199999984150795D5E6666660000000000000000411EB5AA199999984150795D619999990000000000000000411EB5AA199999984150795DDE6666660000000000000000411EB5A6199999984150795DE19999990000000000000000411EB5A6199999984150795E5E6666660000000000000000411EB5A2199999984150795E619999990000000000000000411EB5A2199999984150795EDE6666660000000000000000411EB59E199999984150795EE19999990000000000000000411EB59E199999984150795F5E6666660000000000000000411EB59A199999984150795F680000000000000000000000411EB5CCE66666654150795FAB3333330000000000000000411EBA81199999984150795FAE6666660000000000000000411EBB077FFFFFFF415079606E6666660000000000000000";
    std::string b = "008000000300000001000000BA411EBC61E666666641507993B80000000000000000000000411EBF9CB333333241507993B80000000000000000000000411EBF97199999994150798F2E6666660000000000000000411EBF9BB333333241507986D199999A0000000000000000411EBF934CCCCCCC41507982E199999A0000000000000000411EBF80E66666664150797DD4CCCCCD0000000000000000411EBF75E6666666415079797B3333330000000000000000411EBF697FFFFFFF4150796D7199999A0000000000000000411EBF4D4CCCCCCC41507963980000000000000000000000411EBF447FFFFFFF4150795F7199999A0000000000000000411EBF447FFFFFFF415079549E6666660000000000000000411EBF41199999994150794F080000000000000000000000411EBF45E66666664150794B5B3333330000000000000000411EBF54B33333324150794574CCCCCD0000000000000000411EBF587FFFFFFF41507940B4CCCCCD0000000000000000411EBF9019999999415079280E6666660000000000000000411EBFA2E66666664150791CE4CCCCCD0000000000000000411EBFA4E6666666415079195199999A0000000000000000411EBFAA4CCCCCCC41507916EE6666660000000000000000411EBFAA199999994150791004CCCCCD0000000000000000411EBFA6199999994150790B6E6666660000000000000000411EBF0F4CCCCCCC4150790C9E6666660000000000000000411EBD344CCCCCCC4150790CA199999A0000000000000000411EBCB4B33333324150790D6199999A0000000000000000411EBB2CB33333324150790D7B3333330000000000000000411EBA5E4CCCCCCC4150790ED80000000000000000000000411EB9E97FFFFFFF4150790F54CCCCCD0000000000000000411EB98E7FFFFFFF4150790FF4CCCCCD0000000000000000411EB8697FFFFFFF4150790FF80000000000000000000000411EB7DFE666666641507910F4CCCCCD0000000000000000411EB706E666666641507911D4CCCCCD0000000000000000411EB5FE1999999941507911F4CCCCCD0000000000000000411EB5FE1999999941507913DE6666660000000000000000411EB5FA1999999941507913E199999A0000000000000000411EB5FA19999999415079201E6666660000000000000000411EB5F619999999415079202199999A0000000000000000411EB5F6199999994150792C9E6666660000000000000000411EB5F2199999994150792CA199999A0000000000000000411EB5F21999999941507938DE6666660000000000000000411EB5EE1999999941507938E199999A0000000000000000411EB5EE19999999415079451E6666660000000000000000411EB5EA19999999415079452199999A0000000000000000411EB5EA19999999415079515E6666660000000000000000411EB5E619999999415079516199999A0000000000000000411EB5E619999999415079565E6666660000000000000000411EB5E219999999415079566199999A0000000000000000411EB5E21999999941507956DE6666660000000000000000411EB5DE1999999941507956E199999A0000000000000000411EB5DE19999999415079575E6666660000000000000000411EB5DA19999999415079576199999A0000000000000000411EB5DA1999999941507957DE6666660000000000000000411EB5D61999999941507957E199999A0000000000000000411EB5D619999999415079585E6666660000000000000000411EB5D219999999415079586199999A0000000000000000411EB5D21999999941507958DE6666660000000000000000411EB5CE1999999941507958E199999A0000000000000000411EB5CE19999999415079595E6666660000000000000000411EB5CA19999999415079596199999A0000000000000000411EB5CA1999999941507959DE6666660000000000000000411EB5C61999999941507959E199999A0000000000000000411EB5C6199999994150795A5E6666660000000000000000411EB5C2199999994150795A6199999A0000000000000000411EB5C2199999994150795ADE6666660000000000000000411EB5BE199999994150795AE199999A0000000000000000411EB5BE199999994150795B5E6666660000000000000000411EB5BA199999994150795B6199999A0000000000000000411EB5BA199999994150795BDE6666660000000000000000411EB5B6199999994150795BE199999A0000000000000000411EB5B6199999994150795C5E6666660000000000000000411EB5B2199999994150795C6199999A0000000000000000411EB5B2199999994150795CDE6666660000000000000000411EB5AE199999994150795CE199999A0000000000000000411EB5AE199999994150795D5E6666660000000000000000411EB5AA199999994150795D6199999A0000000000000000411EB5AA199999994150795DDE6666660000000000000000411EB5A6199999994150795DE199999A0000000000000000411EB5A6199999994150795E5E6666660000000000000000411EB5A2199999994150795E6199999A0000000000000000411EB5A2199999994150795EDE6666660000000000000000411EB59E199999994150795EE199999A0000000000000000411EB59E199999994150795F5E6666660000000000000000411EB59A199999994150795F6199999A0000000000000000411EB59A199999994150795FDE6666660000000000000000411EB596199999994150795FE199999A0000000000000000411EB59619999999415079605E6666660000000000000000411EB58E1999999941507960A199999A0000000000000000411EB58E1999999941507960DE6666660000000000000000411EB58A1999999941507960E199999A0000000000000000411EB58A19999999415079611E6666660000000000000000411EB58619999999415079612199999A0000000000000000411EB58619999999415079615E6666660000000000000000411EB58219999999415079616199999A0000000000000000411EB58219999999415079619E6666660000000000000000411EB57E1999999941507961A199999A0000000000000000411EB57E1999999941507961DE6666660000000000000000411EB57A1999999941507961E199999A0000000000000000411EB57A19999999415079621E6666660000000000000000411EB57619999999415079622199999A0000000000000000411EB57619999999415079625E6666660000000000000000411EB56E19999999415079626199999A0000000000000000411EB56A1999999941507962DE6666660000000000000000411EB5661999999941507962E199999A0000000000000000411EB56619999999415079631E6666660000000000000000411EB56219999999415079632199999A0000000000000000411EB56219999999415079635E6666660000000000000000411EB55E19999999415079636199999A0000000000000000411EB55E19999999415079639E6666660000000000000000411EB55A1999999941507963A199999A0000000000000000411EB55A1999999941507963DE6666660000000000000000411EB5561999999941507963E199999A0000000000000000411EB55619999999415079641E6666660000000000000000411EB55219999999415079642199999A0000000000000000411EB55219999999415079645E6666660000000000000000411EB54E19999999415079646199999A0000000000000000411EB54E19999999415079649E6666660000000000000000411EB5461999999941507964A199999A0000000000000000411EB54219999999415079651E6666660000000000000000411EB53E19999999415079652199999A0000000000000000411EB53E19999999415079655E6666660000000000000000411EB53A19999999415079656199999A0000000000000000411EB53A19999999415079659E6666660000000000000000411EB5361999999941507965A199999A0000000000000000411EB5361999999941507965DE6666660000000000000000411EB5321999999941507965E199999A0000000000000000411EB53219999999415079661E6666660000000000000000411EB52E19999999415079662199999A0000000000000000411EB52E19999999415079665E6666660000000000000000411EB52A19999999415079666199999A0000000000000000411EB52A19999999415079669E6666660000000000000000411EB5261999999941507966A199999A0000000000000000411EB5261999999941507966DE6666660000000000000000411EB51E1999999941507966E199999A0000000000000000411EB51A19999999415079675E6666660000000000000000411EB51619999999415079676199999A0000000000000000411EB51619999999415079679E6666660000000000000000411EB5121999999941507967A199999A0000000000000000411EB5121999999941507967DE6666660000000000000000411EB50E1999999941507967E199999A0000000000000000411EB50E19999999415079681E6666660000000000000000411EB50A19999999415079682199999A0000000000000000411EB50A19999999415079685E6666660000000000000000411EB50619999999415079686199999A0000000000000000411EB50619999999415079689E6666660000000000000000411EB5021999999941507968A199999A0000000000000000411EB5021999999941507968DE6666660000000000000000411EB4FE1999999941507968E199999A0000000000000000411EB4FE19999999415079691E6666660000000000000000411EB4F619999999415079692199999A0000000000000000411EB4F219999999415079699E6666660000000000000000411EB4EE1999999941507969A199999A0000000000000000411EB4EE1999999941507969DE6666660000000000000000411EB4EA1999999941507969E199999A0000000000000000411EB4EA199999994150796A1E6666660000000000000000411EB4E6199999994150796A2199999A0000000000000000411EB4E6199999994150796A5E6666660000000000000000411EB4E2199999994150796A6199999A0000000000000000411EB4E2199999994150796A9E6666660000000000000000411EB4DE199999994150796AA199999A0000000000000000411EB4DE199999994150796ADE6666660000000000000000411EB4DA199999994150796AE199999A0000000000000000411EB4DA199999994150796B1E6666660000000000000000411EB4D6199999994150796B2199999A0000000000000000411EB4D6199999994150796B5E6666660000000000000000411EB4CE199999994150796B6199999A0000000000000000411EB4CA199999994150796BDE6666660000000000000000411EB4C6199999994150796BE199999A0000000000000000411EB4C6199999994150796C1E6666660000000000000000411EB4C2199999994150796C2199999A0000000000000000411EB4C2199999994150796C5E6666660000000000000000411EB4B2199999994150796CA199999A0000000000000000411EB4B2199999994150796CDE6666660000000000000000411EB4AA199999994150796CE199999A0000000000000000411EB4A6199999994150796D5E6666660000000000000000411EB496199999994150796DA199999A0000000000000000411EB4814CCCCCCC41507975180000000000000000000000411EB4814CCCCCCC41507975FE6666660000000000000000411EB4BAB333333241507989DB3333330000000000000000411EB4BCE66666664150798C3E6666660000000000000000411EB4B74CCCCCCC4150798F6E6666660000000000000000411EB5EE199999994150798F7199999A0000000000000000411EB63E199999994150798FE199999A0000000000000000411EB6D3B3333332415079901E6666660000000000000000411EBA0BB3333332415079902199999A0000000000000000411EBAB619999999415079913B3333330000000000000000411EBBCCE6666666415079927E6666660000000000000000411EBC61E666666641507993B80000000000000000000000";
    std::istringstream sa(a);
    std::istringstream sb(b);
    geos::io::WKBReader reader;
    
    std::unique_ptr<geos::geom::Geometry> ga = reader.readHEX(sa);
    assert(ga->isValid());
    assert(ga->getGeometryTypeId() == geos::geom::GEOS_POLYGON);

    std::unique_ptr<geos::geom::Geometry> gb = reader.readHEX(sb);
    assert(gb->isValid());
    assert(gb->getGeometryTypeId() == geos::geom::GEOS_POLYGON);

    std::unique_ptr<geos::geom::Geometry> gc = ga->Union(gb.get());
    assert(gc->isValid());
    geos::geom::GeometryTypeId type = gc->getGeometryTypeId();
    std::cout << type << std::endl;
    assert(type == geos::geom::GEOS_POLYGON);
}

Expected: result geometry is a Polygon

Actual: result is a GeometryCollection which contains the expected Polygon as well as an extraneous LineString consisting of two points.

Attachments (1)

geos-1031-polygon-overlap.png (19.4 KB ) - added by mdavis 3 years ago.
Shows Polygon A extending slightly outside Polygon B, resulting in a topology collapse during union

Download all attachments as: .zip

Change History (6)

comment:1 by pramsey, 3 years ago

Milestone: 3.10.0

comment:2 by pramsey, 3 years ago

Have a look at OverlayNG.setStrictMode(). If you turn on strict mode, the results of overlays will only include components of a single dimensionality. Unfortunately (?) the results of the standard methods on Geometry have to match up to the old behaviour for legacy reasons, so strict mode is turned off by default.

comment:3 by pramsey, 3 years ago

Resolution: invalid
Status: newclosed

in reply to:  2 comment:4 by brownjt, 3 years ago

Replying to pramsey:

Have a look at OverlayNG.setStrictMode(). If you turn on strict mode, the results of overlays will only include components of a single dimensionality. Unfortunately (?) the results of the standard methods on Geometry have to match up to the old behaviour for legacy reasons, so strict mode is turned off by default.

I don't understand how this is invalid. The issue is not with the dimensionality of the result. There should be only one resulting geometry from the union not two. It has been some time since I looked at this but I believe the extra line string actually has duplicate points that are already present on the resulting polygon. Why is it generating these extra points?

comment:5 by mdavis, 3 years ago

The result is reflecting the fact that the vertices of the two polygons are slightly different to each other. In fact polygon A has a vertex which creates a triangle slightly outside polygon B. The difference is so small that the triangle collapses to a line. (See attached image).

The overlay algorithm is able to compute geometry for these situations, and optionally provide it (as a way of seeing where collapses have occurred). As Paul said, for backwards compatibility reasons by default the collapses are returned in the result.

The reason the ticket is marked as invalid is because this is expected behaviour.

Last edited 3 years ago by mdavis (previous) (diff)

by mdavis, 3 years ago

Shows Polygon A extending slightly outside Polygon B, resulting in a topology collapse during union

Note: See TracTickets for help on using tickets.