【问题标题】:Can I use other coordinate types to create a 2d index in MongoDB?我可以使用其他坐标类型在 MongoDB 中创建二维索引吗?
【发布时间】:2023-03-14 16:36:01
【问题描述】:

我正在荷兰建立一个房地产数据的 MongoDB 数据库。我希望能够对我的数据集执行地理空间查询。每个文档都没有经度和纬度坐标,而是有一个叫做“Rijksdriehoeks”的坐标。这些 Rijksdriehoeks 坐标不符合 MongoDB 对 2d 坐标对的要求,因为它们可以超过 600.000 的值(该系统使用米作为单位)。这是一个问题,因为创建二维索引要求所有坐标对都使用经度和纬度,因此值分别在 [-180, 180][-90, 90] 之间。

我需要为此数据集创建地理索引以将查询时间减少到可接受的水平,但由于上述问题,创建“旧版”二维索引会出现此错误:

> db.Bag3DMembers.createIndex( { "properties.bbox" : "2d" })
{
    "ok" : 0,
    "errmsg" : "point not in interval of [ -180, 180 ] :: caused by :: { _id: ObjectId('5dfa7596cc0b7324e5331509'), type: \"Feature\", properties: { identificatie: \"0003100000117485\", aanduidingrecordinactief: false, aanduidingrecordcorrectie: 0, officieel: false, inonderzoek: false, documentnummer: \"FB 2010/PANDEN001\", documentdatum: \"2010-07-20\", bouwjaar: \"1991-01-01\", begindatumtijdvakgeldigheid: null, einddatumtijdvakgeldigheid: null, gemeentecode: \"0003\", ground-000: -0.43, ground-010: -0.34, ground-020: -0.31, ground-030: -0.3, ground-040: -0.27, ground-050: -0.25, roof-025: 10.58, rmse-025: 1.5, roof-050: 13.43, rmse-050: 1.28, roof-075: 13.46, rmse-075: 1.28, roof-090: 13.52, rmse-090: 1.27, roof-095: 13.87, rmse-095: 1.27, roof-099: 14.35, rmse-099: 1.27, roof_flat: false, nr_ground_pts: 220, nr_roof_pts: 6816, ahn_file_date: null, ahn_version: 2, height_valid: true, tile_id: \"07fz1\", gid: \"1\", bbox: [ [ 254052.046875, 593486.3125 ], [ 254076.625, 593504.6875 ] ] }, geometry: { type: \"Polygon\", coordinates: [ [ [ 254059.737, 593504.637, 0.0 ], [ 254059.227, 593500.0, 0.0 ], [ 254059.216, 593499.899, 0.0 ], [ 254058.242, 593500.0, 0.0 ], [ 254057.914, 593500.034, 0.0 ], [ 254057.893, 593500.0, 0.0 ], [ 254057.807, 593499.863, 0.0 ], [ 254052.074, 593490.692, 0.0 ], [ 254052.182, 593490.639, 0.0 ], [ 254058.138, 593490.002, 0.0 ], [ 254057.932, 593488.165, 0.0 ], [ 254074.487, 593486.4129999999, 0.0 ], [ 254075.981, 593500.0, 0.0 ], [ 254076.265, 593502.583, 0.0 ], [ 254076.561, 593502.55, 0.0 ], [ 254076.594, 593502.847, 0.0 ], [ 254059.737, 593504.637, 0.0 ] ] ] } }",
    "code" : 13027,
    "codeName" : "Location13027"
}

有什么方法可以说服 MongoDB 接受我的“Rijksdriehoeks”坐标,或者我需要将它们转换为经度和纬度值吗?

【问题讨论】:

    标签: mongodb geospatial mongodb-geospatial


    【解决方案1】:

    查看文档Create a 2d Index

    在二维索引上,您可以更改位置范围。

    您可以建立一个二维地理空间索引,其位置范围不是 默认值。创建索引时使用 min 和 max 选项。

    应该是

    db.Bag3DMembers.createIndex( 
       { "properties.bbox" : "2d" }, 
       { min: -10000, max: 630000, bits: 24 }
    )
    

    【讨论】:

    • 谢谢,您节省了我很多时间将所有内容重写为 lat lon!
    猜你喜欢
    • 2013-09-19
    • 2012-06-28
    • 2020-08-15
    • 2023-03-21
    • 1970-01-01
    • 2019-12-22
    • 2016-10-27
    • 2021-06-11
    • 1970-01-01
    相关资源
    最近更新 更多