JTS: 13 Polygonizer 多线合成面

这里写目录标题

版本

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 edge
            lines.add(wktReader.read("LINESTRING (185 221, 100 100)")); //dangling edge
            lines.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 - []
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值