我正在考虑在MongoDB中存储一个引用路由的条目,该条目存储在外部文件中,但在数据库中具有该路由的边界框。我不确定我是否应该使用Polygon,或者是否有更好的数据类型?需要考虑的主要问题是这将用于搜索。例如,搜索路径是区域的搜索。起点和终点是不够的,因为它们不一定代表范围(例如,轨道可以在它开始的地方完成)。
我使用的是mongoose和mongoose-geojson-schema
到目前为止,我有类似的内容:
const mongoose = require('mongoose');
const mongooseGeoJSON = require('mongoose-geojson-schema');
const hikeSchema = mongoose.Schema({
title: String,
description: String,
when: Date,
startPoint: mongoose.Schema.Types.Point,
endPoint: mongoose.Schema.Types.Point,
boundingBox: //Not sure?
});
更新:目前我只是使用Polygon类型,没有更好的建议。
答案 0 :(得分:1)
正如你最后说的那样,这就是我使用的(mongoose 3.6) - 仍然使用多边形,但那是我怀疑的正确方法:
Place.where('location').intersects().geometry({
type: "Polygon",
coordinates: [[
[ minLongitude, minLatitude ],
[ minLongitude, maxLatitude ],
[ maxLongitude, maxLatitude ],
[ maxLongitude, minLatitude ],
[ minLongitude, minLatitude ]
]]
}).exec()