I am seeing some behavior that I do not expect. When performing a
coordinate-sequence-filter on the result of an intersection, one of the
original geometries is (unexpectedly) modified.
That is, let c = a.intersection(b), then modify c, and a is modified (given
the "right" -- the default -- GeometryFactory to create a). It turns out
that a and c share some coordinates (with respect to ==).
Am I missing something?
Below is the code to reproduce the results.
Tests were run with JTS version 1.13 (from the maven repository).
======== Test Code ==================
Let:
/**
* Intersect two geometries, created with the given geometry factories,
and modify the result.
*/
private void testOverFactory(GeometryFactory fa, GeometryFactory fb) {
Geometry a = fa.toGeometry(new Envelope(1, 3, 1, 2));
Geometry b = fb.toGeometry(new Envelope(0, 2, 0, 3));
Geometry c = a.intersection(b);
System.out.println(a);
shiftGeomByX(c, 1); // modify
System.out.println(a);
}
/**
* Shift the coordinates of a geometry by xShift (adapted from spatial4j).
*/
private static void shiftGeomByX(Geometry geom, final int xShift) {
geom.apply(new CoordinateSequenceFilter() {
public void filter(CoordinateSequence seq, int i) {
seq.setOrdinate(i, CoordinateSequence.X, seq.getX(i) +
xShift);
}
public boolean isDone() { return false; }
public boolean isGeometryChanged() { return true; }
});
}
Let:
GeometryFactory f1 = new GeometryFactory();
GeometryFactory f2 = new GeometryFactory(new
PackedCoordinateSequenceFactory());
====== Test Results =====================
The output of each of:
testOverFactory(f1, f1);
testOverFactory(f1, f2);
is
POLYGON ((1 1, 1 2, 3 2, 3 1, 1 1))
POLYGON ((1 1, 2 2, 3 2, 3 1, 2 1)).
That is, the geometry upon which "intersection()" is invoked (a) is
affected by a modification of the result (c). (And in this case, all but
the first coordinate of 'a' and 'c' are identical (==).
Now, using a different GeometryFactory to create 'a' gives the "expected"
behavior.
The output of each of:
testOverFactory(f2, f1);
testOverFactory(f2, f2);
POLYGON ((1 1, 1 2, 3 2, 3 1, 1 1))
POLYGON ((1 1, 1 2, 3 2, 3 1, 1 1)).
That is, the geometry upon which "intersection()" is invoked is not
affected by a modification of the result.
(Let me know if this doesn't make sense)
------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
_______________________________________________
Jts-topo-suite-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jts-topo-suite-user