美文网首页GeoTools
GeoTools常见函数用法

GeoTools常见函数用法

作者: WebGiser | 来源:发表于2020-08-07 14:59 被阅读0次
GeoTools is an open source Java library that provides tools for geospatial data

参考网址:http://docs.geotools.org/stable/userguide/library/jts/geometry.html

maven引入geotools依赖
   <repositories>
        <repository>
            <id>osgeo</id>
            <name>Open Source Geospatial Foundation Repository</name>
            <url>http://download.osgeo.org/webdav/geotools/</url>
        </repository>
    </repositories>

        <dependency>
            <groupId>org.geotools</groupId>
            <artifactId>gt-main</artifactId>
            <version>23-SNAPSHOT</version>
            <exclusions>
                <exclusion>
                    <groupId>javax</groupId>
                    <artifactId>javaee-api</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
JTS创建点线面
#创建点
GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
Coordinate coord = new Coordinate(1, 1);
Point point = geometryFactory.createPoint(coord);

GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
WKTReader reader = new WKTReader(geometryFactory);
Point point = (Point) reader.read("POINT (1 1)");


#创建线
GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
Coordinate[] coords  = new Coordinate[] {new Coordinate(0, 2), new Coordinate(2, 0), new Coordinate(8, 6) };
LineString line = geometryFactory.createLineString(coordinates);

GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
WKTReader reader = new WKTReader(geometryFactory);
LineString line = (LineString) reader.read("LINESTRING(0 2, 2 0, 8 6)");


#创建面
GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
Coordinate[] coords  = new Coordinate[] {new Coordinate(4, 0), new Coordinate(2, 2), new Coordinate(4, 4), new Coordinate(6, 2), new Coordinate(4, 0) };
LinearRing ring = geometryFactory.createLinearRing(coords);
LinearRing holes[] = null; // use LinearRing[] to represent holes
Polygon polygon = geometryFactory.createPolygon(ring, holes);

GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory( null );
WKTReader reader = new WKTReader( geometryFactory );
Polygon polygon = (Polygon) reader.read("POLYGON((20 10, 30 0, 40 10, 30 20, 20 10))");
Geometry之间的空间关系
image.png
1、点面包含分析

用途:判断一个面是否包含一个点,即一个点是否在一个面内。点、面皆为wkt字符串格式。
关键代码:

              import org.geotools.geometry.jts.JTSFactoryFinder;
              import org.locationtech.jts.geom.Geometry;
              import org.locationtech.jts.io.ParseException;
              import org.locationtech.jts.io.WKTReader;

                WKTReader reader = new WKTReader(JTSFactoryFinder.getGeometryFactory());
                String wktPoly = polygon;
                Geometry poly = reader.read(wktPoly);

               String wktPoint = "POINT("+item.get("lng")+" "+item.get("lat")+")";
               Geometry point = reader.read(wktPoint);
               boolean flag = poly.contains(point);

相关文章

  • GeoTools常见函数用法

    GeoTools is an open source Java library that provides too...

  • Excel常见函数常见用法

    Excel 常用函数 在Excel函数中 出现 A:A 表示A列,出现A1 表示 A1这个单元格。 1、SUM 2...

  • Kotlin 作用域函数

    目录 作用域函数分析 常见作用域函数with,apply,also,let,run,with 作用域函数用法 1....

  • 常见损失函数用法

    损失函数(loss function)又叫做代价函数(cost function),是用来评估模型的预测值与真实值...

  • matplotlib常见函数用法

    1.subplot matplotlib 中的subplot的用法 - 学弟1 - 博客园 Python Matp...

  • Python3 中逗号的特殊用法

    常见用法: 1. 作为参数或变量的分隔符 不常见用法: 2. 在print函数中的应用,使得输出不换行 3. 将变...

  • 哈希算法

    哈希算法 什么是hash函数?常见的hash算法hashlib的用法hash算法的用途 什么是hash函数? 哈希...

  • geotools学习(九)函数

    函数教程 向GeoTools添加函数是扩展该库的非常有用的介绍。这通常用于在样式化时生成值,否则无法使用表达式完成...

  • jQuery中常见函数用法

    .val().attr().removeAttr().prop().css().addClass().remove...

  • python序列

    1、列表 列表的结构就是我们平常见的数组,常见用法如下 直接创建 aa=[] 使用list函数 list('hel...

网友评论

    本文标题:GeoTools常见函数用法

    本文链接:https://www.haomeiwen.com/subject/leufdktx.html