1、单个类型转换

一次只能转换出一个 Geometry

geojson中只有一个 Feature 的情况

  1. import com.fasterxml.jackson.core.JsonProcessingException;
  2. import lombok.Data;
  3. import org.locationtech.jts.geom.*;
  4. import org.locationtech.jts.io.ParseException;
  5. import org.locationtech.jts.io.WKTReader;
  6. import java.util.List;
  7. import java.util.Map;
  8. /**
  9. * Created on 2021/9/10--20:08.
  10. *
  11. * @author fengyuhao
  12. * @Description GeoJson 转 Geometry
  13. */
  14. public class GeoJsonToGeometry {
  15. private static final int SRID = 4326;
  16. private static final String TYPES = "Point,LineString,Polygon,MultiPoint,MultiLineString,MultiPolygon";
  17. /**
  18. * 将 GeoJson 转换为对应的 Geometry 类型,默认 srid = 4326
  19. * @param geoJson geoJson
  20. */
  21. public static GeoJson getGeometryByGeoJson(String geoJson,String type) throws Exception {
  22. return getGeometryByGeoJson(geoJson,type,SRID);
  23. }
  24. /**
  25. * 支持转换所有类型,将 GeoJson 转换为对应的 Geometry 类型,默认 srid = 4326
  26. * @param geoJson geoJson
  27. */
  28. public static GeoJson getGeometryByGeoJson(String geoJson) throws Exception {
  29. return getGeometryByGeoJson(geoJson,TYPES,SRID);
  30. }
  31. /**
  32. * 支持转换所有类型,将 GeoJson 转换为对应的 Geometry 类型
  33. * @param geoJson geoJson
  34. */
  35. public static GeoJson getGeometryByGeoJson(String geoJson,int srid) throws Exception {
  36. return getGeometryByGeoJson(geoJson,TYPES,srid);
  37. }
  38. /**
  39. * 将 GeoJson 转换为对应的 Geometry 类型
  40. * @param geoJson geoJson
  41. * @param srid SRID
  42. */
  43. public static GeoJson getGeometryByGeoJson(String geoJson,String type,int srid) throws Exception {
  44. List<Map<String, Object>> list = null;
  45. try {
  46. list = (List<Map<String, Object>>) OtherUtil.OBJECT_MAPPER.readValue(geoJson, Map.class).get("features");
  47. } catch (JsonProcessingException e) {
  48. e.printStackTrace();
  49. }
  50. if (list == null) {
  51. throw new Exception("Json 转换异常");
  52. }
  53. // 获取属性信息
  54. Map<String, Object> properties = (Map<String, Object>)list.get(0).get("properties");
  55. GeoJson geo = getProperties(properties);
  56. // 获取 geometry
  57. Map<String, Object> geometry = (Map<String, Object>)list.get(0).get("geometry");
  58. if(!type.toUpperCase().contains(geometry.get("type").toString().toUpperCase())){
  59. throw new Exception("不支持的 Geometry 类型");
  60. }
  61. switch (geometry.get("type").toString().toUpperCase()) {
  62. case "POINT":
  63. geo.setGeom(getPoint((List<Double>) geometry.get("coordinates"),srid));
  64. break;
  65. case "LINESTRING":
  66. geo.setGeom(getLineString((List<Object>) geometry.get("coordinates"),srid));
  67. break;
  68. case "POLYGON":
  69. geo.setGeom(getPolygon((List<Object>) geometry.get("coordinates"),srid));
  70. break;
  71. case "MULTIPOINT":
  72. geo.setGeom(getMultiPoint((List<Object>) geometry.get("coordinates"),srid));
  73. break;
  74. case "MULTILINESTRING":
  75. geo.setGeom(getMultiLineString((List<Object>) geometry.get("coordinates"),srid));
  76. break;
  77. case "MULTIPOLYGON":
  78. geo.setGeom(getMultiPolygon((List<Object>) geometry.get("coordinates"),srid));
  79. break;
  80. default:
  81. throw new Exception("不支持的 Geometry 类型");
  82. }
  83. return geo;
  84. }
  85. /**
  86. * [[
  87. * [122.19794471743876,30.241048024596722],[122.19349009648414,30.235207526854044],
  88. * [122.20655698914918,30.23401962566707],[122.19794471743876,30.241048024596722]
  89. * ]]
  90. * POLYGON((-71.1776585052917 42.3902909739571,-71.1776820268866 42.3903701743239,
  91. * -71.1775826583081 42.3903033653531,-71.1776585052917 42.3902909739571))
  92. */
  93. private static Polygon getPolygon(List<Object> coordinates,int srid) throws ParseException {
  94. coordinates = (List<Object>)coordinates.get(0);
  95. StringBuilder str = new StringBuilder();
  96. str.append("POLYGON((");
  97. List<Double> coordinate;
  98. for(Object obj : coordinates){
  99. coordinate = (List<Double>) obj;
  100. str.append(coordinate.get(0)).append(" ").append(coordinate.get(1)).append(",");
  101. }
  102. str.deleteCharAt(str.length() - 1).append("))");
  103. Polygon polygon = (Polygon) new WKTReader().read(str.toString());
  104. polygon.setSRID(srid);
  105. return polygon;
  106. }
  107. /**
  108. * [[119.001,34.001],[120.001,35.001]]
  109. * LINESTRING(1 2, 3 4)
  110. */
  111. private static LineString getLineString(List<Object> coordinates,int srid) throws ParseException {
  112. StringBuilder str = new StringBuilder();
  113. List<Double> coordinate;
  114. str.append("LINESTRING(");
  115. for(Object obj : coordinates){
  116. coordinate = (List<Double>) obj;
  117. str.append(coordinate.get(0)).append(" ").append(coordinate.get(1)).append(",");
  118. }
  119. str.deleteCharAt(str.length() - 1).append(")");
  120. LineString lineString = (LineString) new WKTReader().read(str.toString());
  121. lineString.setSRID(srid);
  122. return lineString;
  123. }
  124. /**
  125. * [119,34]
  126. * POINT(1 2)
  127. */
  128. private static Point getPoint(List<Double> coordinates,int srid) throws ParseException {
  129. Point point = (Point) new WKTReader().read("POINT("+coordinates.get(0)+" "+coordinates.get(1)+")");
  130. point.setSRID(srid);
  131. return point;
  132. }
  133. /**
  134. * [ [122.19794471743876,30.241048024596722],[122,30] ]
  135. * MULTIPOINT(1 2, 3 4)
  136. */
  137. private static MultiPoint getMultiPoint(List<Object> coordinates,int srid) throws ParseException {
  138. StringBuilder str = new StringBuilder();
  139. List<Double> coordinate;
  140. str.append("MultiPoint(");
  141. for(Object obj : coordinates){
  142. coordinate = (List<Double>) obj;
  143. str.append(coordinate.get(0)).append(" ").append(coordinate.get(1)).append(",");
  144. }
  145. str.deleteCharAt(str.length() - 1).append(")");
  146. MultiPoint multiPoint = (MultiPoint) new WKTReader().read(str.toString());
  147. multiPoint.setSRID(srid);
  148. return multiPoint;
  149. }
  150. /**
  151. * [
  152. * [[119,35],[120,35]],
  153. * [[119,34],[122,34]]
  154. * ]
  155. * MULTILINESTRING((1 2, 3 4), (4 5, 6 7))
  156. */
  157. private static MultiLineString getMultiLineString(List<Object> coordinates,int srid) throws ParseException {
  158. StringBuilder str = new StringBuilder();
  159. str.append("MULTILINESTRING(");
  160. List<Double> coordinate;
  161. for(Object obj : coordinates){
  162. str.append("(");
  163. for(Object data : (List<Object>)obj){
  164. coordinate = (List<Double>) data;
  165. str.append(coordinate.get(0)).append(" ").append(coordinate.get(1)).append(",");
  166. }
  167. str.deleteCharAt(str.length() - 1).append("),");
  168. }
  169. str.deleteCharAt(str.length() -1).append(")");
  170. MultiLineString multiLineString = (MultiLineString) new WKTReader().read(str.toString());
  171. multiLineString.setSRID(srid);
  172. return multiLineString;
  173. }
  174. /**
  175. * [
  176. * [[ [122,30],[123,30],[122,31],[122,30] ]],
  177. * [[ [122,33],[123,33],[122.5,34],[122,33] ]]
  178. * ]
  179. * MULTIPOLYGON((
  180. * (0 0 1,20 0 1,20 20 1,0 20 1,0 0 1),
  181. * (5 5 3,5 7 3,7 7 3,7 5 3,5 5 3)
  182. * ))
  183. */
  184. private static MultiPolygon getMultiPolygon(List<Object> coordinates,int srid) throws ParseException {
  185. StringBuilder str = new StringBuilder();
  186. str.append("MULTIPOLYGON((");
  187. List<Double> coordinate;
  188. for(Object obj1 : coordinates){
  189. for(Object obj2 :(List<Object>)obj1){
  190. str.append("(");
  191. for(Object obj3 : (List<Object>)obj2){
  192. coordinate = (List<Double>) obj3;
  193. str.append(coordinate.get(0)).append(" ").append(coordinate.get(1)).append(",");
  194. }
  195. str.deleteCharAt(str.length() - 1).append("),");
  196. }
  197. }
  198. str.deleteCharAt(str.length() - 1).append("))");
  199. MultiPolygon multiPolygon = (MultiPolygon) new WKTReader().read(str.toString());
  200. multiPolygon.setSRID(srid);
  201. return multiPolygon;
  202. }
  203. private static GeoJson getProperties(Map<String, Object> properties) {
  204. GeoJson geoJson = new GeoJson();
  205. if(properties == null){
  206. return geoJson;
  207. }
  208. geoJson.setName(properties.getOrDefault("name","").toString());
  209. return geoJson;
  210. }
  211. @Data
  212. public static class GeoJson{
  213. private Geometry geom;
  214. private String name;
  215. }
  216. public static void main(String[] args) throws Exception {
  217. String geoPoint = "{\"type\": \"FeatureCollection\"," +
  218. "\"features\": [{" +
  219. "\"type\": \"Feature\"," +
  220. "\"geometry\": {\"type\": \"Point\"," +
  221. "\"coordinates\": [119,34]}," +
  222. "\"properties\": null" +
  223. "}]" +
  224. "}";
  225. String geoLineString = "{\"type\": \"FeatureCollection\"," +
  226. "\"features\": [{" +
  227. "\"type\": \"Feature\"," +
  228. "\"geometry\": {\"type\": \"LineString\"," +
  229. "\"coordinates\": [[119.001,34.001],[120.001,35.001]]}," +
  230. "\"properties\":{\"name\":\"names\"}" +
  231. "}]" +
  232. "}";
  233. String geoPolygon = "{\"type\":\"FeatureCollection\"," +
  234. "\"features\":[{" +
  235. "\"type\":\"Feature\"," +
  236. "\"geometry\":{\"type\":\"Polygon\"," +
  237. "\"coordinates\":[[ [122.19794471743876,30.241048024596722],[122.19349009648414,30.235207526854044]," +
  238. "[122.20655698914918,30.23401962566707],[122.19794471743876,30.241048024596722] ]]}," +
  239. "\"properties\":{\"name\":\"names\"}" +
  240. "}]" +
  241. "}";
  242. String geoMultiPoint = "{\"type\": \"FeatureCollection\"," +
  243. "\"features\": [{" +
  244. "\"type\": \"Feature\"," +
  245. "\"geometry\": { \"type\": \"MultiPoint\"," +
  246. "\"coordinates\": [[122.19794471743876,30.241048024596722],[122,30]]}," +
  247. "\"properties\": null" +
  248. "}]" +
  249. "}";
  250. String geoMultiLineString = "{\"type\":\"FeatureCollection\"," +
  251. "\"features\":[{" +
  252. "\"type\":\"Feature\"," +
  253. "\"geometry\":{\"type\":\"MultiLineString\"," +
  254. "\"coordinates\":[[[119,35],[120,35]],[[119,34],[122,34]]]}," +
  255. "\"properties\":null" +
  256. "}]" +
  257. "}";
  258. String geoMultiPolygon = "{\"type\":\"FeatureCollection\"," +
  259. "\"features\":[{" +
  260. "\"type\":\"Feature\"," +
  261. "\"geometry\":{\"type\":\"MultiPolygon\"," +
  262. "\"coordinates\":[" +
  263. "[[ [122,30],[123,30],[122,31],[122,30] ]]," +
  264. "[[ [122,33],[123,33],[122.5,34],[122,33] ]]" +
  265. "]" +
  266. "}," +
  267. "\"properties\":{\"id\":\"10\"}" +
  268. "}]" +
  269. "}";
  270. GeoJson geoJson = getGeometryByGeoJson(geoLineString,"Polygon,LineString",4326);
  271. System.out.println(geoJson.getGeom());
  272. }
  273. }

2、多类型转换

geojson 文件中有几个 Feature 就转换出多少 Geometry

  1. package com.zjic.common.utils;
  2. import com.fasterxml.jackson.core.JsonProcessingException;
  3. import lombok.Data;
  4. import org.locationtech.jts.geom.*;
  5. import org.locationtech.jts.io.ParseException;
  6. import org.locationtech.jts.io.WKTReader;
  7. import java.util.ArrayList;
  8. import java.util.HashMap;
  9. import java.util.List;
  10. import java.util.Map;
  11. /**
  12. * Created on 2021/9/10--20:08.
  13. *
  14. * @author fengyuhao
  15. * @Description GeoJson 转 Geometry, 仅支持读取 properties 中的 "name" 属性
  16. */
  17. public class GeoJsonToGeometry {
  18. private static final int SRID = 4326;
  19. private static final String TYPES = "Point,LineString,Polygon,MultiPoint,MultiLineString,MultiPolygon";
  20. /**
  21. * 将 GeoJson 转换为对应的 Geometry 类型,默认 srid = 4326
  22. * @param geoJson geoJson
  23. * @param type geoJson 类型
  24. */
  25. public static List<GeoJson> getGeometryByGeoJson(String geoJson,String type) throws Exception {
  26. return getGeometryByGeoJson(geoJson,type,SRID);
  27. }
  28. /**
  29. * 支持转换所有类型,将 GeoJson 转换为对应的 Geometry 类型,默认 srid = 4326
  30. * @param geoJson geoJson
  31. */
  32. public static List<GeoJson> getGeometryByGeoJson(String geoJson) throws Exception {
  33. return getGeometryByGeoJson(geoJson,TYPES,SRID);
  34. }
  35. /**
  36. * 支持转换所有类型,将 GeoJson 转换为对应的 Geometry 类型
  37. * @param geoJson geoJson
  38. * @param srid srid
  39. */
  40. public static List<GeoJson> getGeometryByGeoJson(String geoJson,int srid) throws Exception {
  41. return getGeometryByGeoJson(geoJson,TYPES,srid);
  42. }
  43. /**
  44. * 将 GeoJson 转换为对应的 Geometry 类型
  45. * @param geoJson geoJson
  46. * @param srid SRID
  47. */
  48. public static List<GeoJson> getGeometryByGeoJson(String geoJson,String type,int srid) throws Exception {
  49. List<Map<String, Object>> list;
  50. try {
  51. list = (List<Map<String, Object>>) CommonUtil.OBJECT_MAPPER.readValue(geoJson, Map.class).get("features");
  52. } catch (JsonProcessingException e) {
  53. throw new Exception("Json 转换异常");
  54. }
  55. if (list == null) {
  56. throw new Exception("Json 转换异常");
  57. }
  58. List<GeoJson> res = new ArrayList<>(list.size()+1);
  59. for(Map<String, Object> data : list){
  60. // 获取属性信息
  61. Map<String, Object> properties = (Map<String, Object>)data.getOrDefault("properties",new HashMap<>());
  62. GeoJson geo = getProperties(properties);
  63. // 获取 geometry
  64. Map<String, Object> geometry = (Map<String, Object>)data.get("geometry");
  65. if(!type.toUpperCase().contains(geometry.get("type").toString().toUpperCase())){
  66. throw new Exception("Geometry 类型错误:期望的类型为"+type);
  67. }
  68. switch (geometry.get("type").toString().toUpperCase()) {
  69. case "POINT":
  70. geo.setGeom(getPoint((List<Double>) geometry.get("coordinates"),srid));
  71. break;
  72. case "LINESTRING":
  73. geo.setGeom(getLineString((List<Object>) geometry.get("coordinates"),srid));
  74. break;
  75. case "POLYGON":
  76. geo.setGeom(getPolygon((List<Object>) geometry.get("coordinates"),srid));
  77. break;
  78. case "MULTIPOINT":
  79. geo.setGeom(getMultiPoint((List<Object>) geometry.get("coordinates"),srid));
  80. break;
  81. case "MULTILINESTRING":
  82. geo.setGeom(getMultiLineString((List<Object>) geometry.get("coordinates"),srid));
  83. break;
  84. case "MULTIPOLYGON":
  85. geo.setGeom(getMultiPolygon((List<Object>) geometry.get("coordinates"),srid));
  86. break;
  87. default:
  88. throw new Exception("不支持的 Geometry 类型");
  89. }
  90. res.add(geo);
  91. }
  92. return res;
  93. }
  94. /**
  95. * [[
  96. * [122.19794471743876,30.241048024596722],[122.19349009648414,30.235207526854044],
  97. * [122.20655698914918,30.23401962566707],[122.19794471743876,30.241048024596722]
  98. * ]]
  99. * POLYGON((-71.1776585052917 42.3902909739571,-71.1776820268866 42.3903701743239,
  100. * -71.1775826583081 42.3903033653531,-71.1776585052917 42.3902909739571))
  101. */
  102. private static Polygon getPolygon(List<Object> coordinates,int srid) throws ParseException {
  103. coordinates = (List<Object>)coordinates.get(0);
  104. StringBuilder str = new StringBuilder();
  105. str.append("POLYGON((");
  106. List<Double> coordinate;
  107. for(Object obj : coordinates){
  108. coordinate = (List<Double>) obj;
  109. str.append(coordinate.get(0)).append(" ").append(coordinate.get(1)).append(",");
  110. }
  111. str.deleteCharAt(str.length() - 1).append("))");
  112. Polygon polygon = (Polygon) new WKTReader().read(str.toString());
  113. polygon.setSRID(srid);
  114. return polygon;
  115. }
  116. /**
  117. * [[119.001,34.001],[120.001,35.001]]
  118. * LINESTRING(1 2, 3 4)
  119. */
  120. private static LineString getLineString(List<Object> coordinates,int srid) throws ParseException {
  121. StringBuilder str = new StringBuilder();
  122. List<Double> coordinate;
  123. str.append("LINESTRING(");
  124. for(Object obj : coordinates){
  125. coordinate = (List<Double>) obj;
  126. str.append(coordinate.get(0)).append(" ").append(coordinate.get(1)).append(",");
  127. }
  128. str.deleteCharAt(str.length() - 1).append(")");
  129. LineString lineString = (LineString) new WKTReader().read(str.toString());
  130. lineString.setSRID(srid);
  131. return lineString;
  132. }
  133. /**
  134. * [119,34]
  135. * POINT(1 2)
  136. */
  137. private static Point getPoint(List<Double> coordinates,int srid) throws ParseException {
  138. Point point = (Point) new WKTReader().read("POINT("+coordinates.get(0)+" "+coordinates.get(1)+")");
  139. point.setSRID(srid);
  140. return point;
  141. }
  142. /**
  143. * [ [122.19794471743876,30.241048024596722],[122,30] ]
  144. * MULTIPOINT(1 2, 3 4)
  145. */
  146. private static MultiPoint getMultiPoint(List<Object> coordinates,int srid) throws ParseException {
  147. StringBuilder str = new StringBuilder();
  148. List<Double> coordinate;
  149. str.append("MultiPoint(");
  150. for(Object obj : coordinates){
  151. coordinate = (List<Double>) obj;
  152. str.append(coordinate.get(0)).append(" ").append(coordinate.get(1)).append(",");
  153. }
  154. str.deleteCharAt(str.length() - 1).append(")");
  155. MultiPoint multiPoint = (MultiPoint) new WKTReader().read(str.toString());
  156. multiPoint.setSRID(srid);
  157. return multiPoint;
  158. }
  159. /**
  160. * [
  161. * [[119,35],[120,35]],
  162. * [[119,34],[122,34]]
  163. * ]
  164. * MULTILINESTRING((1 2, 3 4), (4 5, 6 7))
  165. */
  166. private static MultiLineString getMultiLineString(List<Object> coordinates,int srid) throws ParseException {
  167. StringBuilder str = new StringBuilder();
  168. str.append("MULTILINESTRING(");
  169. List<Double> coordinate;
  170. for(Object obj : coordinates){
  171. str.append("(");
  172. for(Object data : (List<Object>)obj){
  173. coordinate = (List<Double>) data;
  174. str.append(coordinate.get(0)).append(" ").append(coordinate.get(1)).append(",");
  175. }
  176. str.deleteCharAt(str.length() - 1).append("),");
  177. }
  178. str.deleteCharAt(str.length() -1).append(")");
  179. MultiLineString multiLineString = (MultiLineString) new WKTReader().read(str.toString());
  180. multiLineString.setSRID(srid);
  181. return multiLineString;
  182. }
  183. /**
  184. * [
  185. * [[ [122,30],[123,30],[122,31],[122,30] ]],
  186. * [[ [122,33],[123,33],[122.5,34],[122,33] ]]
  187. * ]
  188. * MULTIPOLYGON((
  189. * (0 0 1,20 0 1,20 20 1,0 20 1,0 0 1),
  190. * (5 5 3,5 7 3,7 7 3,7 5 3,5 5 3)
  191. * ))
  192. */
  193. private static MultiPolygon getMultiPolygon(List<Object> coordinates,int srid) throws ParseException {
  194. StringBuilder str = new StringBuilder();
  195. str.append("MULTIPOLYGON((");
  196. List<Double> coordinate;
  197. for(Object obj1 : coordinates){
  198. for(Object obj2 :(List<Object>)obj1){
  199. str.append("(");
  200. for(Object obj3 : (List<Object>)obj2){
  201. coordinate = (List<Double>) obj3;
  202. str.append(coordinate.get(0)).append(" ").append(coordinate.get(1)).append(",");
  203. }
  204. str.deleteCharAt(str.length() - 1).append("),");
  205. }
  206. }
  207. str.deleteCharAt(str.length() - 1).append("))");
  208. MultiPolygon multiPolygon = (MultiPolygon) new WKTReader().read(str.toString());
  209. multiPolygon.setSRID(srid);
  210. return multiPolygon;
  211. }
  212. private static GeoJson getProperties(Map<String, Object> properties) {
  213. GeoJson geoJson = new GeoJson();
  214. if(properties == null){
  215. return geoJson;
  216. }
  217. geoJson.setName(properties.getOrDefault("name","").toString());
  218. return geoJson;
  219. }
  220. @Data
  221. public static class GeoJson{
  222. private Geometry geom;
  223. private String name;
  224. }
  225. public static void main(String[] args) throws Exception {
  226. // String geoPoint = "{\"type\": \"FeatureCollection\"," +
  227. // "\"features\": [{" +
  228. // "\"type\": \"Feature\"," +
  229. // "\"geometry\": {\"type\": \"Point\"," +
  230. // "\"coordinates\": [119,34]}," +
  231. // "\"properties\": null" +
  232. // "}]" +
  233. // "}";
  234. String geoPoints = "{ \"type\": \"FeatureCollection\", \"features\": [ { \"type\": \"Feature\", \"geometry\": { \"type\": \"Point\", \"coordinates\": [ 120.915783542, 30.882011484 ] }, \"properties\": { \"name\": \"魏塘站\", \"gid\": 1 } }, { \"type\": \"Feature\", \"geometry\": { \"type\": \"Point\", \"coordinates\": [ 120.989985292, 30.952577374 ] }, \"properties\": { \"name\": \"红旗塘站\", \"gid\": 2 } }, { \"type\": \"Feature\", \"geometry\": { \"type\": \"Point\", \"coordinates\": [ 120.835532968, 30.997386357 ] }, \"properties\": { \"name\": \"下甸庙站\", \"gid\": 3 } }, { \"type\": \"Feature\", \"geometry\": { \"type\": \"Point\", \"coordinates\": [ 120.954403108, 31.019139073 ] }, \"properties\": { \"name\": \"太浦河站\", \"gid\": 4 } } ] }";
  235. String geoLineString = "{\"type\": \"FeatureCollection\"," +
  236. "\"features\": [{" +
  237. "\"type\": \"Feature\"," +
  238. "\"geometry\": {\"type\": \"LineString\"," +
  239. "\"coordinates\": [[119.001,34.001],[120.001,35.001]]}," +
  240. "\"properties\":{\"name\":\"names\"}" +
  241. "}]" +
  242. "}";
  243. String geoPolygon = "{\"type\":\"FeatureCollection\"," +
  244. "\"features\":[{" +
  245. "\"type\":\"Feature\"," +
  246. "\"geometry\":{\"type\":\"Polygon\"," +
  247. "\"coordinates\":[[ [122.19794471743876,30.241048024596722],[122.19349009648414,30.235207526854044]," +
  248. "[122.20655698914918,30.23401962566707],[122.19794471743876,30.241048024596722] ]]}," +
  249. "\"properties\":{\"name\":\"names\"}" +
  250. "}]" +
  251. "}";
  252. String geoMultiPoint = "{\"type\": \"FeatureCollection\"," +
  253. "\"features\": [{" +
  254. "\"type\": \"Feature\"," +
  255. "\"geometry\": { \"type\": \"MultiPoint\"," +
  256. "\"coordinates\": [[122.19794471743876,30.241048024596722],[122,30]]}," +
  257. "\"properties\": null" +
  258. "}]" +
  259. "}";
  260. String geoMultiLineString = "{\"type\":\"FeatureCollection\"," +
  261. "\"features\":[{" +
  262. "\"type\":\"Feature\"," +
  263. "\"geometry\":{\"type\":\"MultiLineString\"," +
  264. "\"coordinates\":[[[119,35],[120,35]],[[119,34],[122,34]]]}," +
  265. "\"properties\":null" +
  266. "}]" +
  267. "}";
  268. String geoMultiPolygon = "{\"type\":\"FeatureCollection\"," +
  269. "\"features\":[{" +
  270. "\"type\":\"Feature\"," +
  271. "\"geometry\":{\"type\":\"MultiPolygon\"," +
  272. "\"coordinates\":[" +
  273. "[[ [122,30],[123,30],[122,31],[122,30] ]]," +
  274. "[[ [122,33],[123,33],[122.5,34],[122,33] ]]" +
  275. "]" +
  276. "}," +
  277. "\"properties\":{\"id\":\"10\"}" +
  278. "}]" +
  279. "}";
  280. List<GeoJson> geoJson = getGeometryByGeoJson(geoPoints,"MultiPolygon",4326);
  281. System.out.println(geoJson);
  282. }
  283. }