版本
org.locationtech.jts:jts-core:1.19.0
链接: github
代码
package pers.stu.densifier;
import org.locationtech.jts.densify.Densifier;
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;
/**
* 插入额外的点
* @author LiHan
* 2023-11-15 15:11:49
*/
public class DensifierUse {
private static final Logger LOGGER = LoggerFactory.getLogger(DensifierUse.class);
private final GeometryFactory geometryFactory = new GeometryFactory();
public static void main(String[] args) {
DensifierUse densifierUse = new DensifierUse();
densifierUse.test00();
}
public void test00() {
Coordinate[] coordinates = new Coordinate[] {
new Coordinate(2, 9), new Coordinate(11, 9)
};
LineString lineString = geometryFactory.createLineString(coordinates);
// 添加间距点
Geometry geometry = Densifier.densify(lineString, 0.5);
LOGGER.info(geometry.toText());
LOGGER.info(GeoGebraUtil.compare(geometry));
}
}
17:48:06.105 [main] INFO pers.stu.densifier.DensifierUse - LINESTRING (2 9, 2.5 9, 3 9, 3.5 9, 4 9, 4.5 9, 5 9, 5.5 9, 6 9, 6.5 9, 7 9, 7.5 9, 8 9, 8.5 9, 9 9, 9.5 9, 10 9, 10.5 9, 11 9)