GeoJSON相关操作
简介
- 本文主要介绍GEOJSON相关的操作
环境
gt-geojson-14.2.jar,json-simple-1.1.1.jar,jts-1.8.jar
直接上代码
代码
- wkt格式的geometry转成json格式
public String evaluate(String wkt) { String ret = null; try { Geometry geometry = reader.read(wkt); StringWriter writer = new StringWriter(); GeometryJSON g = new GeometryJSON(); g.write(geometry, writer); ret = writer.toString(); } catch (Exception e) { LOGGER.error(e.getMessage(), e); } return ret; }
- json格式转wkt格式
public String evaluate(String geoJson) { String ret = null; GeometryJSON gjson = new GeometryJSON(); Reader reader = new StringReader(geoJson); try { Geometry geometry = gjson.read(reader); ret = geometry.toText(); } catch (IOException e) { LOGGER.error(e.getMessage(), e); } return ret; }