Opened 8 years ago

Closed 8 years ago

#752 closed defect (duplicate)

TopologyException while comparing collections

Reported by: sirsigurd Owned by: geos-devel@…
Priority: major Milestone: 3.5.1
Component: Default Version: 3.5.0
Severity: Unassigned Keywords:
Cc: fedoseev.sergey@…

Description

code to reproduce

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>

#include "geos_c.h"

void
log_and_exit(const char *fmt, ...) {
	va_list ap;

        fprintf( stdout, "ERROR: ");

	va_start (ap, fmt);
        vfprintf( stdout, fmt, ap);
        va_end(ap);
        fprintf( stdout, "\n" );
	exit(1);
}

void main() {
    initGEOS(NULL, log_and_exit);
    GEOSGeometry* pol1 = GEOSGeomFromWKT(
      "POLYGON ("
        "(0 0, 0 4, 4 4, 4 0, 0 0)"
      ")");
    GEOSGeometry* pol2 = GEOSGeomFromWKT(
      "POLYGON ("
        "(3 3, 3 4, 4 4, 4 3, 3 3)"
      ")");
    GEOSGeometry* polys[] = {pol1, pol2};
    GEOSGeometry* coll = GEOSGeom_createCollection(GEOS_GEOMETRYCOLLECTION, polys, 2);

    printf("polygon1 is valid: %d\n", GEOSisValid(pol1));
    printf("polygon2 is valid: %d\n", GEOSisValid(pol2));
    printf("collection is valid: %d\n", GEOSisValid(coll));
    printf("collection relate to itself: %d\n", GEOSEquals(coll, coll));
}

output

polygon1 is valid: 1
polygon2 is valid: 1
collection is valid: 1
ERROR: TopologyException: side location conflict at 3 4

Change History (9)

comment:1 by strk, 8 years ago

Milestone: 3.5.1

Martin Davis pointed out that in JTS such operation would raise an IllegalArgumentException as any relate operation does not support GeometryCollection inputs.

I went digging and found the behavior mismatch being introduced by Paul with r2252. The commit log doesn't reference any ticket so I don't know what the rationale for that was. Paul ?

comment:2 by strk, 8 years ago

I've added this test (disabled) to the testsuite with r4113.

comment:3 by strk, 8 years ago

NOTE: the two polygons in the collection are overlapping so I guess it could make sense for topology builder to fail.

I confirm JTS would also fail when dropping the geometrycollection input check: Exception in thread "AWT-EventQueue-0" com.vividsolutions.jts.geom.TopologyException: side location conflict [ (3.0, 4.0, NaN) ]

comment:4 by strk, 8 years ago

So I guess the correct handling of this would be reverting r4113 to re-introduce the guard against GeometryCollection input, but I'd hear from Paul first, as he must have had a good reason to remove those checks...

comment:5 by strk, 8 years ago

Sorry, of course I meant reverting r2252

comment:6 by sirsigurd, 8 years ago

Cc: fedoseev.sergey@… added

in reply to:  3 comment:7 by sirsigurd, 8 years ago

Replying to strk:

NOTE: the two polygons in the collection are overlapping so I guess it could make sense for topology builder to fail.

If change first polygon to (0 0, 0 5, 5 5, 5 0, 0 0) polygons in the collection are still overlapping, but there is no fail.

It seems there is the quick fix for this problem: to use unary union of collection instead of collection itself.

comment:8 by strk, 8 years ago

I just spotted a previous discussion about this: #725. Indeed running a UnaryUnion might be generally acceptable. What do you think, Dr.JTS ?

comment:9 by strk, 8 years ago

Resolution: duplicate
Status: newclosed

Actually, let's discuss this in #725, I'm closing this as a duplicate.

Note: See TracTickets for help on using tickets.