概述
应用配置
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
com.lilei.geojson
wkt2geojson
0.0.1-SNAPSHOT
jar
wkt2geojson
http://maven.apache.org
UTF-8
junit
junit
3.8.1
test
org.geotools
gt-geojson
12.0
nexus2
internal nexus repository2
http://central.maven.org/maven2/
maven2-repository.dev.java.net
Java.net repository
http://download.java.net/maven/2
osgeo
Open Source Geospatial Foundation Repository
http://download.osgeo.org/webdav/geotools/
true
boundless
Boundless Maven Repository
http://repo.boundlessgeo.com/main
程序
package com.lilei.geojson.wkt2geojson;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.Map;
import org.geotools.geojson.geom.GeometryJSON;
import org.json.simple.JSONObject;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.io.WKTReader;
/**
* Hello world!
*
*/
public class App {
public static void main(String[] args) {
String wkt = "POINT(114.298456 30.553544)";
Map map = new HashMap();
map.put("name", "北清路");
map.put("author","李雷");
String json = geoToJson(wkt,map);
System.out.println(jsonToWkt(json));
}
//
public static String geoToJson(String wkt,Map map) {
String json = null;
try {
WKTReader reader = new WKTReader();
Geometry geometry = reader.read(wkt);
StringWriter writer = new StringWriter();
GeometryJSON g = new GeometryJSON();
g.write(geometry, writer);
map.put("geometry", writer);
json = JSONObject.toJSONString(map);
} catch (Exception e) {
e.printStackTrace();
}
return json;
}
public static String jsonToWkt(String geoJson) {
String wkt = null;
GeometryJSON gjson = new GeometryJSON();
Reader reader = new StringReader(geoJson);
try {
Geometry geometry = gjson.read(reader);
wkt = geometry.toText();
} catch (IOException e) {
e.printStackTrace();
}
return wkt;
}
}
最后
以上就是孝顺蜡烛为你收集整理的dxf geojson 转换_wkt转换geojson的全部内容,希望文章能够帮你解决dxf geojson 转换_wkt转换geojson所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复