GeoTools wkt 转 geojson
时间: 2023-08-22 17:10:06 浏览: 163
可以使用GeoTools库来实现WKT转换为GeoJSON。以下是一个Java代码示例:
```java
import org.geotools.geojson.geom.GeometryJSON;
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.io.ParseException;
import org.locationtech.jts.io.WKTReader;
import java.io.IOException;
import java.io.StringWriter;
public class WktToGeojsonConverter {
public static String convert(String wkt) throws ParseException, IOException {
WKTReader reader = new WKTReader();
Geometry geometry = reader.read(wkt);
StringWriter writer = new StringWriter();
GeometryJSON gjson = new GeometryJSON();
gjson.write(geometry, writer);
return writer.toString();
}
}
```
你可以将WKT作为参数传递给convert()方法,然后它将返回一个GeoJSON字符串。
阅读全文