Spring data 如何使用Spring数据将原始GeoJson多多边形存储到MongoDB中

Spring data 如何使用Spring数据将原始GeoJson多多边形存储到MongoDB中,spring-data,geojson,spring-mongodb,Spring Data,Geojson,Spring Mongodb,如何轻松地将原始GeoJson MultiPolygon功能转换为org.springframework.data.mongodb.core.geo.GeoJsonMultiPolygon,以便使用SpringData(mongoTemplate)将其保存到mongodb?我需要保留多个多边形的孔 GeoJson org.geojson.MultiPolygon到org.springframework.data.mongodb.core.geo.GeoJsonMultiPolygon 目前,

如何轻松地将原始GeoJson MultiPolygon功能转换为org.springframework.data.mongodb.core.geo.GeoJsonMultiPolygon,以便使用SpringData(mongoTemplate)将其保存到mongodb?我需要保留多个多边形的孔

GeoJson

org.geojson.MultiPolygon到org.springframework.data.mongodb.core.geo.GeoJsonMultiPolygon

目前,下面的工作,我可以保存这个多多边形到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);