Skip to content
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 @@ -434,10 +434,10 @@ public static Coordinate[] removeRepeatedPoints(Coordinate[] coord) {
* @see Coordinate#isValid()
*/
public static boolean hasRepeatedOrInvalidPoints(Coordinate[] coord) {
for (int i = 1; i < coord.length; i++) {
for (int i = 0; i < coord.length; i++) {
if (! coord[i].isValid())
return true;
if (coord[i - 1].equals(coord[i])) {
if (i > 0 && coord[i - 1].equals(coord[i])) {
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,18 @@ public void testOrientCCW() {
checkOrient("POLYGON ((9 7, 5 9, 1 4, 5 4, 4 1, 8 1, 9 7))");
}

public void testRemoveInvalidStartPoint() {
checkRemoveInvalidPoints("LINESTRING (NaN 0, 1 1, 2 2)",
"LINESTRING (1 1, 2 2)");
}

public void testRemoveInvalidPoints() {
checkRemoveInvalidPoints("LINESTRING (Nan 0, 1 1, Nan Nan, 2 2, 3 NaN)",
"LINESTRING (1 1, 2 2)");
}

//================================================

private void checkOrient(String wkt) {
Coordinate[] pts = read(wkt).getCoordinates();
//-- orient CW
Expand Down Expand Up @@ -240,4 +252,14 @@ private static Coordinate[] createCircularString(Coordinate center, double radiu
return sequence;
}

private void checkRemoveInvalidPoints(String wkt, String wktExpected) {
Coordinate[] pts = read(wkt).getCoordinates();

assertTrue(CoordinateArrays.hasRepeatedOrInvalidPoints(pts));

Coordinate[] ptsFix = CoordinateArrays.removeRepeatedOrInvalidPoints(pts);
Coordinate[] ptsExpected = read(wktExpected).getCoordinates();
assertTrue(CoordinateArrays.equals(ptsFix, ptsExpected));
}

}