java wkb字符串转geojson
时间: 2023-11-12 17:59:45 浏览: 212
可以使用开源库 JTS (Java Topology Suite) 来实现 wkb 字符串转 geojson。具体步骤如下:
1. 将 wkb 字符串转为 Geometry 对象:
```java
WKBReader reader = new WKBReader();
Geometry geometry = reader.read(WKBUtils.hexToBytes(wkbString));
```
2. 将 Geometry 对象转为 GeoJSON 字符串:
```java
GeoJSONWriter writer = new GeoJSONWriter();
String geoJsonString = writer.write(geometry);
```
完整代码示例:
```java
import org.locationtech.jts.geom.Geometry;
import org.locationtech.jts.io.geojson.GeoJSONWriter;
import org.locationtech.jts.io.WKBReader;
import org.locationtech.jts.io.WKBUtils;
public class WkbToGeoJson {
public static void main(String[] args) {
String wkbString = "0101000000000000000000F03F000000000000F03F";
WKBReader reader = new WKBReader();
try {
Geometry geometry = reader.read(WKBUtils.hexToBytes(wkbString));
GeoJSONWriter writer = new GeoJSONWriter();
String geoJsonString = writer.write(geometry);
System.out.println(geoJsonString);
} catch (Exception e) {
e.printStackTrace();
}
}
}
```
阅读全文