Spring数据MongoDB地理空间

Spring数据MongoDB地理空间,mongodb,spring-boot,spring-data,geospatial,Mongodb,Spring Boot,Spring Data,Geospatial,我需要帮助。 这里我的json存储在MongoDB中 { "forecastTime":3, "infos": [ { "location": { "type": "Point", "coordinates": [ -10, 10 ] }, "data" : { "heading": 136, "wind": [ { "sail" : "spi",

我需要帮助。 这里我的json存储在MongoDB中

{
"forecastTime":3,
 "infos": [
   {
    "location": {
       "type": "Point", 
        "coordinates": [ -10, 10 ] 
    },
    "data" : {
       "heading": 136,
       "wind": [
         {
           "sail" : "spi",
             "speed" : 8.56
            },
         {
           "sail" : "foc",
             "speed" : 12.34
         }
        ]
    }
  },{
    "location": {
       "type": "Point", 
        "coordinates": [ -20, 10 ] 
    },
    "data" : {
       "heading": 78,
       "wind": [
         {
           "sail" : "spi",
             "speed" : 2.23
            },
         {
           "sail" : "foc",
             "speed" : 2.34
         }
        ]
    }
  }
  ]
}
我正在寻找的查询将检索预测为3(小时)的spi sail的风速,以及-20和10的位置。 那么,最好的解决方案是什么呢

谢谢

我尝试了这个函数,但没有结果

    public GeoResults<Wind> getWinds(float lon, float lat, int forecast) {

        Point point = new Point(lon, lat);
        NearQuery geoNear = NearQuery.near(point, Metrics.KILOMETERS).maxDistance(0.01);

        Query query = new Query(
            Criteria.where("forecastTime").is(forecast)
            //.and("type").is(type)
        );

        query.fields()
            .include("data.wind")
        ;

        geoNear.query(query);

        GeoResults<Wind> data = mongoTemplate.geoNear(geoNear, Wind.class);

        return data;
}

您使用spring数据存储库还是mongotemplate?您的选择是我的。。。这是一个微型服务,我会选择一个能回答我问题的人:)你尝试了什么?也可以考虑“接近”或“精确”的“<代码>”位置。坐标“< /代码>”。因为“精确”根本不需要地理空间查询,只是引用“精确”数组的查询参数。对于“接近”给定坐标或“包含”在坐标边界形状内的对象,您只需要“地理空间查询”。是否需要提交简短代码?感谢Neil关于地理空间查询的说明。事实上,我以后会用它来获得插值风…@anthony44。请务必理解,这不是一场由你主持,其他人参与的比赛。:)如果您有任何问题,我们很乐意提供帮助。但是你应该自己先试试。
    // the query object
    Criteria findForecastCriteria = Criteria.where("forecastTime").is(forecast);
    // the field object
    Criteria findLocationCriteria = Criteria.where("infos").elemMatch(Criteria.where("location.coordinates").is(new double[]{lon, lat}));

    BasicQuery query = new BasicQuery(findForecastCriteria.getCriteriaObject(), findLocationCriteria.getCriteriaObject());
    query.fields().include("data.wind");

    Grib g = mongoTemplate.findOne(query, Grib.class);

    result = new ApiResult(
            lon
            , lat
            , g.getData().get(0).getWind().getSpeed()
        );