版本
org.locationtech.jts:jts-core:1.19.0
链接: github
代码
public class GeometryLineMerger {
private static final GeometryFactory geometryFactory = new GeometryFactory();
private static final Logger LOGGER = LoggerFactory.getLogger(GeometryConvexHull.class);
private final WKTReader wktReader = new WKTReader();
private ArrayList<LineString> lineStrings = new ArrayList<>();
public static void main(String[] args) {
GeometryLineMerger geometryLineMerger = new GeometryLineMerger();
geometryLineMerger.init();
geometryLineMerger.test00();
}
/**
* 初始化数据
*/
public void init() {
lineStrings.add(geometryFactory.createLineString(new Coordinate[]{new Coordinate(14,8), new Coordinate(3, 8)}));
lineStrings.add(geometryFactory.createLineString(new Coordinate[]{new Coordinate(3,8), new Coordinate(8, 12)}));
lineStrings.add(geometryFactory.createLineString(new Coordinate[]{new Coordinate(8,12), new Coordinate(2, 10)}));
lineStrings.add(geometryFactory.createLineString(new Coordinate[]{new Coordinate(2,10), new Coordinate(0, 2)}));
lineStrings.add(geometryFactory.createLineString(new Coordinate[]{new Coordinate(0,2), new Coordinate(14, 6)}));
lineStrings.add(geometryFactory.createLineString(new Coordinate[]{new Coordinate(20, 8), new Coordinate(14,6)}));
lineStrings.add(geometryFactory.createLineString(new Coordinate[]{new Coordinate(20,8), new Coordinate(20, 12)}));
}
public void test00() {
LineMerger lineMerger = new LineMerger();
lineMerger.add(lineStrings);
Collection<?> collection = lineMerger.getMergedLineStrings();
LOGGER.info(collection.toString());
}
}
20:09:11.046 [main] INFO pers.stu.buff.GeometryConvexHull - [LINESTRING (14 8, 3 8, 8 12, 2 10, 0 2, 14 6, 20 8, 20 12)]