• java 利用geotools包对wkt格式数据进行操作


    引入相关pom依赖,我这边是引用全部的。利用jar包的方式引用过来的。

    
        org.geotools
        gt-shapefile
        19.2
        system
        ${project.basedir}/src/main/resources/lib/gt-shapefile-19.2.jar
    
    
        org.ejml
        ejml-ddense
        0.39
        system
        ${project.basedir}/src/main/resources/lib/ejml-ddense-0.32.jar
    
    
        org.ejml
        ejml-core
        0.39
        system
        ${project.basedir}/src/main/resources/lib/ejml-core-0.39.jar
    
    
        org.geotools
        gt-opengis
        19.2
        system
        ${project.basedir}/src/main/resources/lib/gt-opengis-19.2.jar
    
    
    
        org.geotools
        gt-data
        19.2
        system
        ${project.basedir}/src/main/resources/lib/gt-data-19.2.jar
    
    
    
        org.geotools
        gt-api
        19.2
        system
        ${project.basedir}/src/main/resources/lib/gt-api-19.2.jar
    
    
    
        org.geotools
        gt-main
        19.2
        system
        ${project.basedir}/src/main/resources/lib/gt-main-19.2.jar
    
    
    
        org.geotools
        gt-metadata
        19.2
        system
        ${project.basedir}/src/main/resources/lib/gt-metadata-19.2.jar
    
    
    
        org.geotools
        gt-referencing
        19.2
        system
        ${project.basedir}/src/main/resources/lib/gt-referencing-19.2.jar
    
    
    
        org.geotools
        gt-geojson
        19.2
        system
        ${project.basedir}/src/main/resources/lib/gt-geojson-19.2.jar
    
    
    
        com.vividsolutions
        jts
        1.13
        system
        ${project.basedir}/src/main/resources/lib/jts-1.13.jar
    

    相关资源包可到https://download.csdn.net/download/saygood999/86539069进行下载

    1、判断点是否在面内

     WKTReader2 wktReader = new WKTReader2();
     Point point = new GeometryFactory().createPoint(new Coordinate(110.00741191345466,31.08890400396027));
    
     Geometry geometry = wktReader.read("MULTIPOLYGON(((110.00741191345466 31.08890400396027,112.10423570721355 31.08890400396027,112.10423570721355 35.14276333856076,110.00741191345466 35.14276333856076,110.00741191345466 31.08890400396027)))");
     StringWriter writer = new StringWriter();
     System.out.println(geometry.contains(point));

    如果单纯的contains其实并不能满足正确的判断。这个方法,我发现了一个问题,如果在面的最边缘上和面进行相交与一点。这个方法是返回false的。

    所以就要加上另个判断 geometry.intersects(point)相交

     

    System.out.println(geometry.contains(point) || geometry.intersects(point));

    意思满足两者任何一个就行。

    2、wkb格式数据转换成geojson

     WKTReader2 wktReader = new WKTReader2();
     
     Geometry geometry = wktReader.read("MULTIPOLYGON(((110.00741191345466 31.08890400396027,112.10423570721355 31.08890400396027,112.10423570721355 35.14276333856076,110.00741191345466 35.14276333856076,110.00741191345466 31.08890400396027)))");
     StringWriter writer = new StringWriter();
    
     GeometryJSON geometryJSON = new GeometryJSON();
     geometryJSON.write(geometry,writer);
     System.out.println(writer.toString());

    类似还有很多的方法。比较判断面积大小,其实搞过postgis的,知道函数的。在geotools上都能找到对应的方法。postgis函数推荐看这篇postgresql gis常用函数介绍_王威振的csdn的博客-CSDN博客_postgresql st函数

    geotools学习文档

    org.locationtech.jts:jts-core 1.19.0 API

  • 相关阅读:
    AIGC Midjourney 机器人绘画案例演示
    基于Java的国内外重大新闻展示平台的设计与实现
    TAPD项目管理:工作流自动化最佳实践
    在 Ubuntu 新装系统中安装 ruby 的几点注意
    docker简单实战
    DeFi分析师:如何构建加密货币分析研究框架?
    LAL v0.34.3发布,G711音频来了,Web UI也来了
    Java —— 抽象类和接口
    【数通 | BGP】使用eNSP进行IBGP的简单配置
    第三方支付“进件”是什么意思
  • 原文地址:https://blog.csdn.net/saygood999/article/details/126866572