为什么多边形GeoJSON对象的坐标存储在数组数组中?

Pur*_*jax 4 datamodel geospatial mongodb mongodb-query

官方文档页面所示,多边形GeoJSON Object的"Schema"如下所示:

db.someCollection.insert({
  type: "Polygon",
  coordinates: [ [ [ 0 , 0 ] , [ 3 , 6 ] , [ 6 , 1 ] , [ 0 , 0  ] ] ]
});
Run Code Online (Sandbox Code Playgroud)

为什么不能简单地如下所示:A型

db.someCollection.insert({
  type: "Polygon",
  coordinates: [ [ 0 , 0 ] , [ 3 , 6 ] , [ 6 , 1 ] , [ 0 , 0  ] ]
});
Run Code Online (Sandbox Code Playgroud)

我认为原因可能是存储多个地理围栏......我是对的吗?

类似的东西:B型

db.someCollection.insert({
    type: "Polygon",
    coordinates: [ 
        [ [ 0 , 0 ] , [ 3 , 6 ] , [ 6 , 1 ] , [ 0 , 0  ] ],
        [ [ 1 , 1 ] , [ 3 , 6 ] , [ 6 , 1 ] , [ 1 , 1  ] ]
    ]
});
Run Code Online (Sandbox Code Playgroud)

为什么我张贴了这个问题的原因是因为我想我的假设是使用的一些功能在蒙戈DB(如错后$ geoIntersects$ geoWithin),这需要"模式"是在A型格式

kev*_*adi 6

MongoDB没有定义GeoJSON格式.相反,它是在标准中定义的:RFC7946

这是RFC中关于多边形的相关部分:https://tools.ietf.org/html/rfc7946#section-3.1.6其中声明:

  • 对于"Polygon"类型,"坐标"成员必须是线性环坐标数组的数组.

  • 对于具有多个这些环的多边形,第一个必须是外环,而任何其他环必须是内环.外环限制表面,内环(如果存在)在表面内限定孔.

线性环定义为:

  • 线性环是具有四个或更多位置的闭合LineString.

LineString是https://tools.ietf.org/html/rfc7946#section-3.1.4:

  • 对于"LineString"类型,"coordinates"成员是两个或多个位置的数组.

基本上,多边形被定义为一系列封闭的LineStrings,第一个LineString定义多边形的边界,后续的LineStrings定义第一个LineString中的"hole".

以这种方式定义,可以创建具有多边形的圆环形状.

这种类型的构造只有在它表示为数组数组时才有可能,因此也就是标准.