org.locationtech.jts:jts-core:1.19.0
链接: github
将一组geometry几何分解成一组最大长度的linestring,其中重叠的部分只出现一次
package pers.stu.dissolve;
import org.locationtech.jts.dissolve.LineDissolver;
import org.locationtech.jts.geom.Coordinate;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.GeometryFactory;
import org.locationtech.jts.geom.LineString;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import pers.stu.util.GeoGebraUtil;
/**
*
*/
public class LineDissolverUse {
private static final Logger LOGGER = LoggerFactory.getLogger(LineDissolverUse.class);
private final GeometryFactory geometryFactory = new GeometryFactory();
public static void main(String[] args) {
LineDissolverUse lineDissolverUse = new LineDissolverUse();
lineDissolverUse.test00();
}
public void test00() {
Coordinate[] coordinate1 = new Coordinate[] {
new Coordinate(1.5, 9), new Coordinate(4.5, 9), new Coordinate(7, 11.5)
};
Coordinate[] coordinate2 = new Coordinate[] {
new Coordinate(1.5, 9), new Coordinate(4.5, 9), new Coordinate(7, 9)
};
Coordinate[] coordinate3 = new Coordinate[] {
new Coordinate(4.5, 9), new Coordinate(7, 11.5), new Coordinate(7, 9), new Coordinate(10, 9)
};
LineString lineString1 = geometryFactory.createLineString(coordinate1);
LineString lineString2 = geometryFactory.createLineString(coordinate2);
LineString lineString3 = geometryFactory.createLineString(coordinate3);
LineDissolver lineDissolver = new LineDissolver();
lineDissolver.add(lineString1);
lineDissolver.add(lineString2);
lineDissolver.add(lineString3);
Geometry geometry = lineDissolver.getResult();
LOGGER.info(geometry.toText());
LOGGER.info(GeoGebraUtil.compare(geometry));
}