我正在尝试将 GeoJSON 坐标拆分为单独的纬度和经度值,以达到所需的格式(如所需输出中所示)。
我有一个 GeoJSON 文件,通过它我只提取坐标值。这些坐标值存储为字符串变量,如下所示 GeoJSON : ":[[[7.365046,46.948655],[7.365046,46.949254],[7.367558,46.949254],[7.367558,46.948655],[7.365046,46.948655]]]}}:如何从给定的字符串中分别提取纬度和经度的特定值。从 GeoJSON 文件中提取坐标的代码片段如下所示:
String GeoJSON = GeoJSONFromFile().split("coordinates")[1];
System.out.println("GeoJSON : " + GeoJSON );
//Splitting within the brackets
String delims = "\\[(.*?)\\]";
String[] tokens = GeoJSON.split(delims);
GeoJSON = GeoJSON.split("}")[0];
我想要实现的预期输出如下:
\"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"
" ]
最终结果应单独包含坐标,如上述格式所示。
侃侃尔雅
相关分类