geojson坐标转换为来自PostgreSQL的数据格式?
geojson coordinate conversion to the format of the data coming from PostgreSQL?
这是保存到矢量代码:
if (vectorType.equalsIgnoreCase("Point")) {
Point point = new GeometryJSON().readPoint(item.getData());
lineString.setSRID(3857);
theEvent.setGeom(point);
theEvent.setVectorType(vectorType);
}
在我想从数据库格式 geojson 中读取数据之后,我需要执行快捷方式
我做了以下代码:
if(entity.getVectorType().trim().equalsIgnoreCase("Point"))
{
JSONObject point = new JSONObject();
point.put("type", "Point");
JSONArray coord = new JSONArray("["+entity.getGeom().getX()+","+entity.getGeom().getY()+"]");
point.put("coordinates", coord);
geoJson.setData(point.toString());
}
但我必须走捷径。我能怎么做。我想用geotools做。我们可以使用 FeatureJson,但如何使用?
应该是这个例子:Point to GeoJSON
让我们看看您的代码:
if(entity.getVectorType().trim().equalsIgnoreCase("Point")){
geoJson.setData(createJSONGeoPoint(entity.getGeom()));//getGeom() is your Point.
}
你的新方法:
private String createJSONGeoPoint(Point point){
SimpleFeatureType TYPE = DataUtilities.createType("Test", "Location:Point");
final GeometryBuilder builder = new GeometryBuilder();
SimpleFeatureBuilder fBuild = new SimpleFeatureBuilder(TYPE);
fBuild.add(point);
SimpleFeature feature = fBuild.buildFeature(null);
FeatureJSON fjson = new FeatureJSON();
StringWriter writer = new StringWriter();
try {
fjson.writeFeature(feature, writer);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return writer.toString();
}
您需要用您的问题对此进行测试,如果需要,请更正代码。
我做过Whosebug用户
解决方案如下:
if(entity.getVectorType().trim().equalsIgnoreCase("Point"))
{
GeometryJSON gjson = new GeometryJSON();
Object obj = JSONValue.parse(gjson.toString(entity.getGeom()));
System.out.println(obj);
}
谢谢。
这是保存到矢量代码:
if (vectorType.equalsIgnoreCase("Point")) {
Point point = new GeometryJSON().readPoint(item.getData());
lineString.setSRID(3857);
theEvent.setGeom(point);
theEvent.setVectorType(vectorType);
}
在我想从数据库格式 geojson 中读取数据之后,我需要执行快捷方式
我做了以下代码:
if(entity.getVectorType().trim().equalsIgnoreCase("Point"))
{
JSONObject point = new JSONObject();
point.put("type", "Point");
JSONArray coord = new JSONArray("["+entity.getGeom().getX()+","+entity.getGeom().getY()+"]");
point.put("coordinates", coord);
geoJson.setData(point.toString());
}
但我必须走捷径。我能怎么做。我想用geotools做。我们可以使用 FeatureJson,但如何使用?
应该是这个例子:Point to GeoJSON
让我们看看您的代码:
if(entity.getVectorType().trim().equalsIgnoreCase("Point")){
geoJson.setData(createJSONGeoPoint(entity.getGeom()));//getGeom() is your Point.
}
你的新方法:
private String createJSONGeoPoint(Point point){
SimpleFeatureType TYPE = DataUtilities.createType("Test", "Location:Point");
final GeometryBuilder builder = new GeometryBuilder();
SimpleFeatureBuilder fBuild = new SimpleFeatureBuilder(TYPE);
fBuild.add(point);
SimpleFeature feature = fBuild.buildFeature(null);
FeatureJSON fjson = new FeatureJSON();
StringWriter writer = new StringWriter();
try {
fjson.writeFeature(feature, writer);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return writer.toString();
}
您需要用您的问题对此进行测试,如果需要,请更正代码。
我做过Whosebug用户 解决方案如下:
if(entity.getVectorType().trim().equalsIgnoreCase("Point"))
{
GeometryJSON gjson = new GeometryJSON();
Object obj = JSONValue.parse(gjson.toString(entity.getGeom()));
System.out.println(obj);
}
谢谢。