这里写目录标题
- 版本
- 代码
版本
org.locationtech.jts:jts-core:1.19.0
链接: github
代码
线段
生成之后的面
public class GeometryPolygonization {private static final GeometryFactory geometryFactory = new GeometryFactory();private static final Logger LOGGER = LoggerFactory.getLogger(GeometryConvexHull.class);private final WKTReader wktReader = new WKTReader();public static void main(String[] args) {GeometryPolygonization geometryPolygonization = new GeometryPolygonization();geometryPolygonization.init();}/*** 初始化*/public void init() {Polygonizer polygonizer = new Polygonizer();Collection<Geometry> lines = new ArrayList<>();try {lines.add(wktReader.read("LINESTRING (0 0 , 10 10)")); // isolated edgelines.add(wktReader.read("LINESTRING (185 221, 100 100)")); //dangling edgelines.add(wktReader.read("LINESTRING (185 221, 88 275, 180 316)"));lines.add(wktReader.read("LINESTRING (185 221, 292 281, 180 316)"));lines.add(wktReader.read("LINESTRING (189 98, 83 187, 185 221)"));lines.add(wktReader.read("LINESTRING (189 98, 325 168, 185 221)"));polygonizer.add(lines);// for (Geometry geometry : lines) {
// LOGGER.info("线条转换:{}", GeoGebraUtil.compare(geometry));
// }// 获取合并完成的面Collection<?> polys = polygonizer.getPolygons();// 获取多余的线条Collection<?> dangles = polygonizer.getDangles();// 暂时还不知到什么意思Collection<?> cuts = polygonizer.getCutEdges();LOGGER.info(polys.toString());LOGGER.info(dangles.toString());LOGGER.info(cuts.toString());// for (Object o : polys) {
// Geometry geometry = (Geometry) o;
// LOGGER.info(GeoGebraUtil.compare(geometry));
// }} catch (ParseException e) {throw new RuntimeException(e);}}
}
15:42:47.258 [main] INFO pers.stu.buff.GeometryConvexHull - [POLYGON ((189 98, 83 187, 185 221, 325 168, 189 98)), POLYGON ((185 221, 88 275, 180 316, 292 281, 185 221))]
15:42:47.259 [main] INFO pers.stu.buff.GeometryConvexHull - [LINESTRING (185 221, 100 100), LINESTRING (0 0, 10 10)]
15:42:47.260 [main] INFO pers.stu.buff.GeometryConvexHull - []