简体   繁体   中英

Can I use other coordinate types to create a 2d index in MongoDB?

I am building a MongoDB database of property data in the Netherlands. I want to be able to perform geospatial queries on my dataset. Each document does not have longitude and latitude coordinates, but something called "Rijksdriehoeks" coordinates. These Rijksdriehoeks coordinates do not conform to MongoDB's requirements for 2d coordinate pairs, in that they can exceed values of 600.000 (this system uses meters for units). This is a problem, because creating a 2d index requires all coordinate pairs to use longitude and latitude and thus to have values between [-180, 180] and [-90, 90] , respectively.

I need to create a geo index for this dataset to reduce query time to acceptable levels, but creating a "legacy" 2d index will give this error because of the issue described above:

> 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"
}

Is there any way I can persuade MongoDB to accept my "Rijksdriehoeks" coordinates or will I need to convert them to longitude and latitude values?

Check documentation Create a 2d Index :

On 2d indexes you can change the location range.

You can build a 2d geospatial index with a location range other than the default. Use the min and max options when creating the index.

Would be

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM