Repository navigation
Description
ST_AddMeasure returns end measure 5 instead of 7 on a bent line and 4 instead of 20 on two length-10 components.
Expected behavior
ST_AddMeasure should interpolate between the start and end measures, giving [0,3,7] for segments 3 and 4 and [0,10,10,20] for two length-10 components (OGC 06-103r4, sections 6.1.7-6.1.9).
Actual behavior
We get [0,3,5] and [0,2,2,4], and it exits 1 with AssertionError: 4 incorrect measures.
Steps to reproduce
Build with a tested JDK and Maven 3.9.11.
git clone https://github.com/apache/sedona.git sedona
cd sedona
git checkout --detach e688be7fc8322d7de772ec9c0a0adf3f37a3b4ec
export MAVEN_OPTS='-Xmx2048m -XX:MaxMetaspaceSize=512m -XX:ActiveProcessorCount=3'
mvn -B -T 2 -pl common -am package \
-Dmaven.test.skip=true -Dmaven.javadoc.skip=true -Dspotless.skip=true \
-Dmaven.repo.local="$PWD/.m2-repro"
mvn -B -pl common dependency:build-classpath \
-Dmaven.repo.local="$PWD/.m2-repro" -Dmdep.outputFile="$PWD/common.cp"Save as Repro.java in the source root. Reproducer code is CC0-1.0.
import org.apache.sedona.common.Constructors;
import org.apache.sedona.common.Functions;
import org.locationtech.jts.geom.Geometry;
public class Repro {
public static void main(String[] args) throws Exception {
String[] inputs = {
"LINESTRING (0 0, 3 0, 3 4)",
"MULTILINESTRING ((0 0, 10 0), (0 1, 10 1))"
};
double[][] expected = {{0, 3, 7}, {0, 10, 10, 20}};
double[] end = {7, 20};
int failures = 0;
for (int t = 0; t < inputs.length; t++) {
Geometry input = Constructors.geomFromWKT(inputs[t], 0);
Geometry result = Functions.addMeasure(input, 0, end[t]);
System.out.println(inputs[t] + " -> " + Functions.asWKT(result));
for (int i = 0; i < expected[t].length; i++) {
double actual = result.getCoordinates()[i].getM();
if (actual != expected[t][i]) {
System.out.println("FAIL vertex " + i + ": expected M=" + expected[t][i] + ", actual=" + actual);
failures++;
}
}
}
if (failures != 0) throw new AssertionError(failures + " incorrect measures");
}
}Then run.
CP="$PWD/common/target/sedona-common-2.0.0-SNAPSHOT.jar:$(cat common.cp)"
mkdir -p repro-classes
javac -proc:none -cp "$CP" -d repro-classes Repro.java
java -Xmx256m -cp "repro-classes:$CP" ReproGeomUtils.java:590-595 uses distance from the first vertex instead of cumulative segment length, and the MultiLineString overload at line 620 uses coordinate count as component length. Happy to send a fix.
Sedona version
2.0.0-SNAPSHOT, commit e688be7fc8322d7de772ec9c0a0adf3f37a3b4ec.
API type
Java, org.apache.sedona.common.
JRE version
Temurin 17.0.20.1+1 and 11.0.32.1+1.
Environment
Linux x86_64, JTS core 1.20.0, WKT IO 1.21.0-datasyslab-2.
Existing issues
- I searched the existing issues and did not find a duplicate.
— ChipLab
Activity
[GH-3464] Interpolate ST_AddMeasure using cumulative lengths (#3465)