Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SEDONA-639] Fix GeometrySplitter accuracy issues when splitting LineStrings #1542

Merged
merged 1 commit into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -148,19 +148,12 @@ private MultiLineString splitLinesByPoints(Geometry lines, Geometry points) {
}

private MultiLineString splitLinesByLines(Geometry inputLines, Geometry blade) {
// compute the intersection of inputLines and blade
// and pass back to splitLines to handle as points
Geometry intersectionWithBlade = inputLines.intersection(blade);

if (intersectionWithBlade.isEmpty()) {
// blade and inputLines are disjoint so just return the input as a multilinestring
return (MultiLineString) ensureMultiGeometryOfDimensionN(inputLines, 1);
} else if (intersectionWithBlade.getDimension() != 0) {
logger.warn("Colinear sections detected between source and blade geometry. Returned null.");
return null;
Geometry diff = inputLines.difference(blade);
if (diff instanceof MultiLineString) {
return (MultiLineString) diff;
} else {
return geometryFactory.createMultiLineString(new LineString[] {(LineString) inputLines});
}

return splitLines(inputLines, intersectionWithBlade);
}

private MultiPolygon splitPolygonsByLines(Geometry polygons, Geometry blade) {
Expand Down Expand Up @@ -197,6 +190,7 @@ private void splitLineStringAtCoordinates(
Iterator<Coordinate> coordIterator =
getIteratorForSegmentDirection(pointCoords, lineBuilder.getLastCoordinate(), endCoord);

// line.getPrecisionModel()
applyCoordsToLineSegment(lineBuilder, coordIterator, endCoord);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import org.geotools.referencing.operation.projection.ProjectionException;
import org.junit.Test;
import org.locationtech.jts.geom.*;
import org.locationtech.jts.geom.prep.PreparedGeometry;
import org.locationtech.jts.geom.prep.PreparedGeometryFactory;
import org.locationtech.jts.io.ParseException;
import org.locationtech.jts.io.WKTReader;
import org.locationtech.jts.io.WKTWriter;
Expand Down Expand Up @@ -305,6 +307,41 @@ public void splitLineStringByPolygon() {
assertEquals(actualResult, expectedResult);
}

@Test
public void splitLineStringFpPrecisionIssue() {
LineString lineString =
GEOMETRY_FACTORY.createLineString(
coordArray(
-8.961173822708158, -3.93776773106963, -8.08908227533288, -3.8845245068873444));
Polygon polygon =
GEOMETRY_FACTORY.createPolygon(
coordArray(
-6.318936372442209, -6.44985859539768,
-8.669092633645995, -3.0659222341103956,
-6.264600073171498, -3.075347218794894,
-5.3654318906014495, -3.1019726170919877,
-5.488002156793005, -5.892626167859213,
-6.318936372442209, -6.44985859539768));

Geometry result = Functions.split(lineString, polygon);
assertEquals(2, result.getNumGeometries());
assertEquals(lineString.getLength(), result.getLength(), 1e-6);
}

@Test
public void tempTest() {
LineString lineString =
GEOMETRY_FACTORY.createLineString(
coordArray(
-8.961173822708158, -3.93776773106963, -8.08908227533288, -3.8845245068873444));
Point point =
GEOMETRY_FACTORY.createPoint(new Coordinate(-8.100103048843774, -3.885197350829553));
PreparedGeometryFactory factory = new PreparedGeometryFactory();
PreparedGeometry prepLineString = factory.create(lineString);
boolean intersects = prepLineString.intersects(point);
System.out.println(intersects);
}

@Test
public void splitPolygonByLineString() {
Polygon polygon =
Expand Down
Loading