如何使用 Spring 数据将原始 GeoJson MultiPolygon 存储到 MongoDB
How do I store raw a GeoJson MultiPolygon into MongoDB using Spring Data
如何轻松地将原始 GeoJson MultiPolygon 特征转换为 org.springframework.data.mongodb.core.geo.GeoJsonMultiPolygon,以便我可以使用 SpringData(mongoTemplate) 将其保存到 MongoDB?我需要保留多边形的孔....
GeoJson
https://gist.github.com/boundaries-io/978eaa4a10df9467638a5eb9259c84e6
org.geojson.MultiPolygon 至 org.springframework.data.mongodb.core.geo.GeoJsonMultiPolygon
目前以下工作正常,我可以将这个 MultiPolygon 保存到 MongoDb。
org.geojson.MultiPolygon multiPolygon ....
ObjectMapper mapper = new ObjectMapper();
String writer = new StringWriter();
org.geojson.Feature feature = new org.geojson.Feature();
feature.setGeometry(multiPolygon);
mapper.writeValue(writer, feature);
String geoJson = writer.getBuffer().toString();
Document document = Document.parse( g );
Object obj = document.get("geometry");
Place place = new Place();
place.setMultiPolygon(obj);
这允许我在包含孔等的多边形上进行地理空间搜索。我觉得这不是最干净的方法..
我最终采用的解决方案如下..无法从 org.geojson.MultiPolygon.
清楚地创建 GeoJsonMultiPolygon
org.geojson.MultiPolygon multiPolygon = //a complicated MultiPolygon with holes,etc.
ObjectMapper mapper = new ObjectMapper();
String writer = new StringWriter();
org.geojson.Feature feature = new org.geojson.Feature();
feature.setGeometry(multiPolygon);
mapper.writeValue(writer, feature);
String geoJson = writer.getBuffer().toString();
Document document = Document.parse( g );
Object obj = document.get("geometry");
Place place = new Place();
place.setMultiPolygon(obj);
如何轻松地将原始 GeoJson MultiPolygon 特征转换为 org.springframework.data.mongodb.core.geo.GeoJsonMultiPolygon,以便我可以使用 SpringData(mongoTemplate) 将其保存到 MongoDB?我需要保留多边形的孔....
GeoJson https://gist.github.com/boundaries-io/978eaa4a10df9467638a5eb9259c84e6
目前以下工作正常,我可以将这个 MultiPolygon 保存到 MongoDb。
org.geojson.MultiPolygon multiPolygon ....
ObjectMapper mapper = new ObjectMapper();
String writer = new StringWriter();
org.geojson.Feature feature = new org.geojson.Feature();
feature.setGeometry(multiPolygon);
mapper.writeValue(writer, feature);
String geoJson = writer.getBuffer().toString();
Document document = Document.parse( g );
Object obj = document.get("geometry");
Place place = new Place();
place.setMultiPolygon(obj);
这允许我在包含孔等的多边形上进行地理空间搜索。我觉得这不是最干净的方法..
我最终采用的解决方案如下..无法从 org.geojson.MultiPolygon.
清楚地创建 GeoJsonMultiPolygon org.geojson.MultiPolygon multiPolygon = //a complicated MultiPolygon with holes,etc.
ObjectMapper mapper = new ObjectMapper();
String writer = new StringWriter();
org.geojson.Feature feature = new org.geojson.Feature();
feature.setGeometry(multiPolygon);
mapper.writeValue(writer, feature);
String geoJson = writer.getBuffer().toString();
Document document = Document.parse( g );
Object obj = document.get("geometry");
Place place = new Place();
place.setMultiPolygon(obj);