Opened 18 years ago

Closed 16 years ago

Last modified 15 years ago

#87 closed defect (worksforme)

Strange result of isValid() for LinearRing

Reported by: mloskot Owned by: mateusz@…
Priority: major Milestone:
Component: Core Version: main
Severity: Significant Keywords: imported, phpbugtracker
Cc:

Description (last modified by mloskot)

I'm getting strange result of isValid() call for non-empty, simple and closed LinearRing.

Here is a code of one of my tests for LinearRing:

// 1. Create non-empty sequence of coordiantes
CoordinateArraySequence* pseq = new CoordinateArraySequence();
ensure( "sequence is null pointer.", pseq != 0 );

// 2. Add 4 points to get closed ring
pseq->add(Coordinate(0, 0, 0));
pseq->add(Coordinate(5, 5, 5));
pseq->add(Coordinate(10, 10, 10));
pseq->add(Coordinate(0, 0, 0)); // <--- 1

ensure_equals( pseq->size(), 4 );

// 3. Create non-empty linearring instance
geos::geom::LinearRing ring(pseq, &amp;factory_);

// 4. Simple tests
ensure( !ring.isEmpty() );
ensure( ring.isClosed() );
ensure( ring.isRing() );
ensure( ring.isSimple() );

// 5. THIS TEST FAILS
ensure( ring.isValid() ); // <--- 2

From my point of view, the code above seems to be valid. I add 4 points with first point repeated 1 at the end to get closed ring. Next, I create LinearRing instance and all tests pass besides isValid() in line 2.

I debugged step by step and what I revealed - and what seems to be quite strange for me - it that checkValid() operation called in IsValidOp::isValid() returns validError.

The error id is eRingSelfIntersection and the messge is "Ring Self-intersection".

In my opinion, the problem is in checkValid() function which validates LinearRing object incorrectly. I suppose that checkValid() recognizes first and last point of LinearRing as self-intersection.

I did a test with not adding the last repeated point in line 1 but then LinearRing ctor throws exception because isClosed() returns false.

Summary: The IsValidOp::checkValid(const Geometry *g) function needs to be checked for LinearRing geometries.

Change History (6)

comment:1 by woodbri@…, 18 years ago

I think your test case is bad.

/ 2. Add 4 points to get closed ring
pseq->add(Coordinate(0, 0, 0));
pseq->add(Coordinate(5, 5, 5));
pseq->add(Coordinate(10, 10, 10));
pseq->add(Coordinate(0, 0, 0)); // <--- [1]

The points (0,0,0), (5,5,5), (10,10,10) are all in a straight line (ie: they are co-linear) and then you return to the start point which falls on  top of the first two segments so you have a case of a collapsed ring where all the point of the ring fall on a single line in space.

This is indeed self intersecting. and isValid() should report it as false.


comment:2 by mateusz@…, 18 years ago

Resolution: nonenot a bug
Steve, you're right. My mistake.
I'm closing this bug with "Not a bug" resolution.

I'm going to use this example to test isValid() for self-intersecting LinearRing :-)

comment:3 by mloskot, 16 years ago

Description: modified (diff)
Milestone: imported
Reporter: changed from mateusz@… to mloskot
Resolution: not a bug
Status: closedreopened

comment:4 by mloskot, 16 years ago

Resolution: worksforme
Status: reopenedclosed
Version: 3.0.0svn-trunk

comment:5 by mloskot, 16 years ago

Milestone: 3.0.0
Priority: 3major

comment:6 by (none), 15 years ago

Milestone: 3.0.0

Milestone 3.0.0 deleted

Note: See TracTickets for help on using tickets.