Martin

Did this get fixed in the trunk?
Thanks.

Jim

From: Martin Davis [mailto:[email protected]]
Sent: 14 June 2015 22:06
To: Kay, Jim
Cc: [email protected]
Subject: Re: [Jts-topo-suite-user] Geometry Union Fail with Polygon createdfrom 
PackedCoordinateSequence

Hmm, that's a bit of a shocker...  amazing this bug hasn't surfaced before.

The problem is that Translater implements CoordinateFilter, which is not able 
to mutate non-Coordinate based CoordinateSequences.

The fix may be simple. I'm thinking about creating a MutatingCoordinateFilter 
which implements CoordinateSequenceFilter.  With any luck this can just be 
dropped in and will fix the problem.

An alternative is to change the semantics of CoordinateFilter to force 
mutations into the source geometry in a way which works with general 
CoordinateSequences.  This might be a bit slower, however, since it will have 
to do a lot of checking to see if the coordinate should be updated, or else 
update even if the Coordinate was not modified.  Better I think to make the 
ability to be mutated explicit.

On Fri, Jun 12, 2015 at 7:07 AM, Kay, Jim 
<[email protected]<mailto:[email protected]>> wrote:
I have an incorrect from the union of two Polygons.
The first Polygon (g0) is created from a PackedCoordinateSequence.
The second Polygon (g1) is created from a CoordinateArray.

The two Polygons are nearly on top of each other.
During the unioning process, 'OverlayOp.overlayOp' fails and so the code 
defaults to 'SnapOverlayOp.overlayOp'.
In the subsequent code the removal of common bits using 
'removeCommonBits(Geometry geom)' fails to successfully apply the translation 
to the geometry created from (g0) PackedCoordinateSequence.
Subsequently the code unions the unshifted g0 geometry with the shifted g1 
geometry, incorrectly producing a MultiPolygon.

Java test code attached (with plotting; please maximise Window)

I have copied some of the relevant method calls below.

Jim Kay

------------------------------------------------------------------------------------------

SnapIfNeededOverlayOp -> getResultGeometry(int opCode)

Normal:
result = OverlayOp.overlayOp(geom[0], geom[1], opCode);

Fails:
savedException = (com.vividsolutions.jts.geom.TopologyException) 
com.vividsolutions.jts.geom.TopologyException: found non-noded intersection 
between LINESTRING ( -0.08528230009449685 4.82017814227853, -0.110460580710986 
4.81977663231897 ) and LINESTRING ( -0.0909282486242289 4.820088108149497, 
-0.090682719052808 4.82011418579351 ) [ (-0.09092824862422651, 
4.820088108149497, NaN) ]

If fails the alternative is:
result = SnapOverlayOp.overlayOp(geom[0], geom[1], opCode);

SnapOverlayOp.overlayOp(Geometry g0, Geometry g1, int opCode)
   return op.getResultGeometry(opCode);
   public Geometry getResultGeometry(int opCode)
      Geometry[] prepGeom = snap(geom);
      private Geometry[] snap(Geometry[] geom)
         Geometry[] remGeom = removeCommonBits(geom);
         private Geometry[] removeCommonBits(Geometry[] geom)
            cbr commonCoord identified (0.0, 4.75)
            remGeom[0] = cbr.removeCommonBits((Geometry) geom[0].clone());
            public Geometry removeCommonBits(Geometry geom) // for g0
               Translater trans = new Translater(invCoord); // setup (-0.0, 
-4.75)
               geom.apply(trans);
               geom.geometryChanged();
               return geom;              //  NO CHANGE IN COORDINATE VALUES FOR 
g0 from PackedCoordinateSequence

            remGeom[1] = cbr.removeCommonBits((Geometry) geom[1].clone());
            public Geometry removeCommonBits(Geometry geom) // for g1
               Translater trans = new Translater(invCoord); // setup (-0.0, 
-4.75)
               geom.apply(trans);
               geom.geometryChanged();
               return geom;              // OK y values shifted down by 4.75 
FOR g1


g0 created from PackedCoordinateSequence
POLYGON ((0.0100573988512497 4.78384542541783, 0.0254790503435339 
4.7853680160678, 0.0257229583365779 4.8203671661845, -0.0432753661791916 
4.82084801337078, -0.110460580710986 4.81977663231897, -0.125859513580305 
4.81803925397127, -0.125615605587261 4.78304010385457, 0.0100573988512497 
4.78384542541783))

g1 created from CoordinateArray
POLYGON ((-0.0852823000943891 4.820178142278531, -0.0432753661791916 
4.82084801337078, -0.034111552138555 4.820784151034586, -0.0234947209409801 
4.82090988483611, 0.0455036035747894 4.82042903764982, 0.0452596955817454 
4.78542988753313, 0.0344169517745771 4.78443089375864, -0.101266578492074 
4.78396502078076, -0.110216672717942 4.78477748220227, -0.110460580710986 
4.81977663231897, -0.0909282486242289 4.820088108149497, -0.090682719052808 
4.82011418579351, -0.0852823000943891 4.820178142278531))

Incorrect result
MULTIPOLYGON (((0.0100573988512497 9.53384542541783, -0.125615605587261 
9.533040103854571, -0.125859513580305 9.568039253971271, -0.110460580710986 
9.56977663231897, -0.0432753661791916 9.57084801337078, 0.0257229583365779 
9.5703671661845, 0.0254790503435339 9.5353680160678, 0.0100573988512497 
9.53384542541783)), ((-0.0852823000943891 4.820178142278531, 
-0.0432753661791916 4.82084801337078, -0.034111552138555 4.820784151034586, 
-0.0234947209409801 4.82090988483611, 0.0455036035747894 4.82042903764982, 
0.0452596955817454 4.78542988753313, 0.0344169517745771 4.78443089375864, 
-0.101266578492074 4.78396502078076, -0.110216672717942 4.78477748220227, 
-0.110460580710986 4.81977663231897, -0.0909282486242289 4.820088108149497, 
-0.090682719052808 4.82011418579351, -0.0852823000943891 4.820178142278531)))

Correct result
POLYGON ((0.0153233378632719 4.784365335331955, 0.0100573988512497 
4.78384542541783, -0.125615605587261 4.78304010385457, -0.125859513580305 
4.81803925397127, -0.110460580710986 4.81977663231897, -0.0909282486242289 
4.820088108149497, -0.090682719052808 4.82011418579351, -0.0852823000943891 
4.820178142278531, -0.0432753661791916 4.82084801337078, -0.034111552138555 
4.820784151034586, -0.0234947209409801 4.82090988483611, 0.0455036035747894 
4.82042903764982, 0.0452596955817454 4.78542988753313, 0.0344169517745771 
4.78443089375864, 0.0153233378632719 4.784365335331955))


------------------------------------------------------------------------------

_______________________________________________
Jts-topo-suite-user mailing list
[email protected]<mailto:[email protected]>
https://lists.sourceforge.net/lists/listinfo/jts-topo-suite-user

------------------------------------------------------------------------------
_______________________________________________
Jts-topo-suite-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jts-topo-suite-user

Reply via email to