第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 Java 將 GeoJSON 坐標中的緯度和經(jīng)度值分別提取為所需的格式

使用 Java 將 GeoJSON 坐標中的緯度和經(jīng)度值分別提取為所需的格式

四季花海 2023-10-19 21:51:18
我正在嘗試將 GeoJSON 坐標拆分為單獨的緯度和經(jīng)度值,以達到所需的格式(如所需輸出中所示)。我有一個 GeoJSON 文件,通過它我只提取坐標值。這些坐標值存儲為字符串變量,如下所示 GeoJSON : ":[[[7.365046,46.948655],[7.365046,46.949254],[7.367558,46.949254],[7.367558,46.948655],[7.365046,46.948655]]]}}:如何從給定的字符串中分別提取緯度和經(jīng)度的特定值。從 GeoJSON 文件中提取坐標的代碼片段如下所示:String GeoJSON = GeoJSONFromFile().split("coordinates")[1];System.out.println("GeoJSON : " + GeoJSON );//Splitting within the bracketsString delims = "\\[(.*?)\\]";String[] tokens = GeoJSON.split(delims);GeoJSON = GeoJSON.split("}")[0];我想要實現(xiàn)的預(yù)期輸出如下:\"points\": [\n" +"            {\n" +"              \"@type\": \"Point\",\n" +"              \"lat\": 46.948655,\n" +"              \"lon\": 7.365046\n" +"            },\n" +"            {\n" +"              \"@type\": \"Point\",\n" +"              \"lat\": 46.949254,\n" +"              \"lon\": 7.365046\n" +"            },\n" +"            {\n" +"              \"@type\": \"Point\",\n" +"              \"lat\": 46.949254,\n" +"              \"lon\": 7.367558\n" +"            },\n" +"            {\n" +"              \"@type\": \"Point\",\n" +"              \"lat\": 46.948655,\n" +"              \"lon\": 7.367558\n" +"            },\n" +"            {\n" +"              \"@type\": \"Point\",\n" +"              \"lat\": 46.948655,\n" +"              \"lon\": 7.365046\n" +"            }\n" "          ]最終結(jié)果應(yīng)單獨包含坐標,如上述格式所示。
查看完整描述

1 回答

?
侃侃爾雅

TA貢獻1801條經(jīng)驗 獲得超16個贊

我猜想類似的表達:

(?::\[\[)?\[([-+]?\d+\.\d+)\s*,\s*([-+]?\d+\.\d+)\]\s*,?(?:\]\]}})?

使用$1and?$2as?latand進行適當(dāng)?shù)奶鎿Qlon,例如:

{\n"@type":?"point",\n"lat":"$1",\n"lon":"$2"\n},\n

可能在某種程度上有效,但不完全有效。

演示

測試

import java.util.regex.Matcher;

import java.util.regex.Pattern;



public class RegularExpression{


? ? public static void main(String[] args){


? ? ? ? final String regex = "(?::\\[\\[)?\\[([-+]?\\d+\\.\\d+)\\s*,\\s*([-+]?\\d+\\.\\d+)\\]\\s*,?(?:\\]\\]\\}})?";

? ? ? ? final String string = ":[[[7.365046,46.948655],[7.365046,46.949254],[7.367558,46.949254],[7.367558,46.948655],[7.365046,46.948655]]]}}";

? ? ? ? final String subst = "{\"@type\": \"point\",\"lat\":\"$1\",\"lon\":\"$2\"},";


? ? ? ? final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);

? ? ? ? final Matcher matcher = pattern.matcher(string);


? ? ? ? final String result = matcher.replaceAll(subst);


? ? ? ? System.out.println(result);


? ? }

}

輸出

{"@type": "點","lat":"7.365046","lon":"46.948655"},{"@type": "點","lat":"7.365046","lon":" 46.949254"},{"@type": "點","lat":"7.367558","lon":"46.949254"},{"@type": "點","lat":"7.367558","經(jīng)度":"46.948655"},{"@type": "點","緯度":"7.365046","經(jīng)度":"46.948655"},

正則表達式電路

jex.im可視化正則表達式:

https://img1.sycdn.imooc.com/653134a00001fca718720195.jpg

查看完整回答
反對 回復(fù) 2023-10-19
  • 1 回答
  • 0 關(guān)注
  • 450 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號