亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

根據線路獲取線路的輻射區

標簽:
Java MySQL Oracle

项目中需要通过一条线路,计算一个在辐射范围内包含该线路的图形。使用JTS包计算缓冲区即可得到。

1.引入依赖

<!-- jts依赖-->
<dependency>
        <groupId>com.vividsolutions</groupId>
        <artifactId>jts-core</artifactId>
        <version>1.14.0</version>
</dependency>
<!--解析字符串-->
<dependency>
        <groupId>cn.hutool</groupId>
        <artifactId>hutool-all</artifactId>
        <version>5.7.1</version>
</dependency>

2.调用buffer方法获得结果

import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.LineString;

import java.util.List;

/**
 * 获取缓冲区
 */
public class Mytest {
    public static void main(String[] args) {
        String position = "[113.2136306762695,23.2724609375],[113.2136001586914,23.27313613891602],[113.2136001586914,23.27411651611328],[113.2136154174805,23.27562141418457],[113.2136154174805,23.27562141418457],[113.2136459350586,23.27606582641602],[113.2136459350586,23.27606582641602],[113.2151107788086,23.27617835998535],[113.2151107788086,23.27617835998535],[113.2170639038086,23.27627754211426],[113.2213287353516,23.27650451660156],[113.2219467163086,23.27655601501465]";
        JSONObject jsonObject = JSONUtil.parseObj("{\"type\":\"LineString\",\"coordinates\":["+ position +"]}");
        JSONArray jsonArray = jsonObject.getJSONArray("coordinates");
        Coordinate coorArr[] = new Coordinate[jsonArray.size()];
        //封装数据
        for (int i = 0; i < jsonArray.size(); i++){
            String pointArr[] = jsonArray.get(i).toString().replace("[", "").replace("]", "").split(",");
            if (pointArr != null && pointArr.length == 2){
                Coordinate coord = new Coordinate(Double.parseDouble(pointArr[0]),Double.parseDouble(pointArr[1]));
                coorArr[i]=coord;
            }
        }
        GeometryFactory geoFac = new GeometryFactory();
        LineString createLineString = geoFac.createLineString(coorArr);
        // 距离转换角度 = meter / (2*Math.PI*6371004)*360 
        //线路附近100米范围
        Geometry buffer = createLineString.buffer(100 / (2*Math.PI*6371004)*360);
        
        //将结果封装返回
        String subBetween = StrUtil.subBetween(buffer.toString(),"((", "))");
        List<String> split = StrUtil.split(subBetween, ", ");
        String result = "";
        for (String item: split) {
            List<String> split1 = StrUtil.split(item, " ");
            String temp  = "["+ split1.get(0) +"," + split1.get(1) +"]" +",";
            result = result + temp;
        }
        System.out.println(result);

    }
}

3.效果

在这里插入图片描述

4.参考资料

點擊查看更多內容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優質文章

正在加載中
JAVA開發工程師
手記
粉絲
17
獲贊與收藏
99

關注作者,訂閱最新文章

閱讀免費教程

  • 推薦
  • 評論
  • 收藏
  • 共同學習,寫下你的評論
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

舉報

0/150
提交
取消