欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

gis地理数据处理:geotools将多个线段生成buffer并融合成多边形

程序员文章站 2022-03-26 17:07:46
一、Maven配置 2.11 2.4.0 org.locationtech.geomesa geomesa-hbase-dat...

目录

一、Maven配置

二、处理代码

三、地图效果


一、Maven配置

    <scala.abi.version>2.11</scala.abi.version>
    <geomesa.version>2.4.0</geomesa.version>
 
   <dependency>
      <groupId>org.locationtech.geomesa</groupId>
      <artifactId>geomesa-hbase-datastore_${scala.abi.version}</artifactId>
      <version>${geomesa.version}</version>
    </dependency>

    <repository>
      <id>locationtech-releases</id>
      <url>https://repo.locationtech.org/content/groups/releases</url>
      <snapshots>
        <enabled>false</enabled>
      </snapshots>
    </repository>
    <repository>
      <id>locationtech-snapshots</id>
      <url>https://repo.locationtech.org/content/groups/snapshots</url>
      <releases>
        <enabled>false</enabled>
      </releases>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
    </repository>

二、处理代码

import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.geom.GeometryFactory;
import org.locationtech.jts.io.ParseException;
import org.locationtech.jts.io.WKTReader;

public class GeometryTest01 {

    // buffer宽度 1.5公里
    private static Double distance = 1500 * 180 / Math.PI / 6371000;
    private static GeometryFactory geoFactory = new GeometryFactory();
    private static WKTReader reader = new WKTReader(geoFactory);

    public static void main(String[] args) throws ParseException {
        f_union();
    }

    public static void f_union() throws ParseException {
        // 两个线段
        String str1 = "LINESTRING(113.688981667 22.61498, 113.689011667 22.6149866667, 113.688981667 22.614985, 113.688991667 22.6149766667, 113.69128 22.616805, 113.746255 22.4975966667, 113.789338333 22.3372516667, 113.770898333 22.1838533333, 113.709931667 22.0802833333, 113.673565 22.0621, 113.536036667 21.98489, 113.39763 21.8900583333, 113.248798333 21.7979866667, 113.207843333 21.7755133333, 113.090306667 21.6998983333, 112.988045 21.6315416667, 112.768438333 21.496895, 112.622081667 21.4221966667, 112.473598333 21.33924, 112.32492 21.2585733333, 112.168205 21.1670616667, 112.021435 21.08913, 111.835261667 20.9901616667, 110.897375 20.4682033333, 110.897375 20.4682033333, 110.793323333 20.340715, 110.659855 20.2441883333, 110.539191667 20.23236, 110.468091667 20.2121433333, 110.299535 20.1262216667, 110.2734 20.0382716667, 110.273336667 20.0385166667, 110.273316667 20.03853, 110.273306667 20.038535, 110.273055 20.0380033333, 110.274758333 20.0366533333, 110.281945 20.0326566667, 110.281928333 20.0326266667, 110.281935 20.0326566667, 110.281936667 20.0326616667, 110.281956667 20.0326516667, 110.281931667 20.032635, 110.281941667 20.0326466667, 110.281955 20.0326133333, 110.281975 20.0326316667, 110.281965 20.0326383333, 110.28195 20.0326116667, 110.281933333 20.0326466667, 110.281958333 20.032655, 110.281961667 20.032635, 110.281946667 20.0326566667, 110.281946667 20.0326316667, 110.281945 20.0326233333, 110.281946667 20.0326783333)";
        String str2 = "LINESTRING(113.688161667 22.6192766667, 113.688031667 22.6192866667, 113.688125 22.6191733333, 113.688006667 22.619195, 113.688218333 22.6191283333, 113.688085 22.6190616667, 113.687915 22.6192783333, 113.688 22.619175, 113.68795 22.619335, 113.688051667 22.6191816667, 113.688021667 22.6192716667, 113.687996667 22.6192, 113.688008333 22.6192233333, 113.688001667 22.6192566667, 113.68811 22.6192116667, 113.688071667 22.6192066667, 113.688045 22.6192466667, 113.689083333 22.6198733333, 113.689223333 22.6195833333, 113.742886667 22.50616, 113.782196667 22.3676283333, 113.792836667 22.234285, 113.725441667 22.0944216667, 113.584236667 22.00817, 113.441858333 21.90201, 113.295108333 21.794535, 113.138406667 21.700045, 112.977628333 21.6150483333, 112.485223333 21.3535083333, 112.30502 21.260925, 112.099031667 21.1439616667, 112.099031667 21.1439616667, 110.85487 20.413765, 110.608781667 20.2427466667, 110.449401667 20.224315, 110.290833333 20.1923183333, 110.268248333 20.08827, 110.279385 20.0781566667, 110.280836667 20.0775716667, 110.279198333 20.0777183333, 110.279251667 20.0775166667, 110.279231667 20.07743, 110.27931 20.0772066667)";
        // 字符串转Geometry类型
        Geometry geometry1 = reader.read(str1);
        Geometry geometry2 = reader.read(str2);
        // 线段扩充buffer成多边形
        Geometry polygon1 = geometry1.buffer(distance);
        Geometry polygon2 = geometry2.buffer(distance);
        // 多边形融合
        Geometry union = polygon1.union(polygon2);;
        // 输出融合的多边形
        System.out.println(union);
    }
}

三、地图效果

图一和图二是两根不同的相似线段,图三为两根线段扩充buffer之后融合的效果

gis地理数据处理:geotools将多个线段生成buffer并融合成多边形gis地理数据处理:geotools将多个线段生成buffer并融合成多边形gis地理数据处理:geotools将多个线段生成buffer并融合成多边形

 

本文地址:https://blog.csdn.net/qq262593421/article/details/109165410