为什么多边形 GeoJSON 对象的坐标存储在数组的数组中?
Why are coordinates of polygon GeoJSON Objects stored in an array of array?
在official documentation中看到,多边形GeoJSON对象的结构如下图:
db.someCollection.insert({
type: "Polygon",
coordinates: [
[
[0, 0], [3, 6], [6, 1], [0, 0]
]
]
});
为什么A 类 格式的结构不如下所示?
类型 A
db.someCollection.insert({
type: "Polygon",
coordinates: [
[0, 0], [3, 6], [6, 1], [0, 0]
]
});
我认为原因可能是存储多个地理围栏。像这样:
类型 B
db.someCollection.insert({
type: "Polygon",
coordinates: [
[
[0, 0], [3, 6], [6, 1], [0, 0]
],
[
[1, 1], [3, 6], [6, 1], [1, 1]
]
]
});
我之所以发这个问题是因为我猜我的假设在使用了MongoDB中的一些运算符后是错误的(比如$geoIntersects
和$geoWithin
)需要结构采用 Type A 格式。
MongoDB 没有定义 GeoJSON 格式。相反,它是在标准中定义的:RFC7946
这是 RFC 中关于多边形的相关部分:https://www.rfc-editor.org/rfc/rfc7946#section-3.1.6 其中指出:
- For type "Polygon", the "coordinates" member MUST be an array of linear ring coordinate arrays.
- For Polygons with more than one of these rings, the first MUST be
the exterior ring, and any others MUST be interior rings. The
exterior ring bounds the surface, and the interior rings (if
present) bound holes within the surface.
线性环定义为:
- A linear ring is a closed LineString with four or more positions.
LineString 是 https://www.rfc-editor.org/rfc/rfc7946#section-3.1.4:
- For type "LineString", the "coordinates" member is an array of two or
more positions.
基本上,多边形被定义为一系列闭合的 LineString,第一个 LineString 定义多边形的边界,随后的 LineString 定义第一个 LineString 中的“孔”。
以这种方式定义,可以创建一个多边形的圆环形状。
这种类型的构造只有在表示为数组的数组时才有可能,因此是标准。
在official documentation中看到,多边形GeoJSON对象的结构如下图:
db.someCollection.insert({
type: "Polygon",
coordinates: [
[
[0, 0], [3, 6], [6, 1], [0, 0]
]
]
});
为什么A 类 格式的结构不如下所示?
类型 A
db.someCollection.insert({
type: "Polygon",
coordinates: [
[0, 0], [3, 6], [6, 1], [0, 0]
]
});
我认为原因可能是存储多个地理围栏。像这样:
类型 B
db.someCollection.insert({
type: "Polygon",
coordinates: [
[
[0, 0], [3, 6], [6, 1], [0, 0]
],
[
[1, 1], [3, 6], [6, 1], [1, 1]
]
]
});
我之所以发这个问题是因为我猜我的假设在使用了MongoDB中的一些运算符后是错误的(比如$geoIntersects
和$geoWithin
)需要结构采用 Type A 格式。
MongoDB 没有定义 GeoJSON 格式。相反,它是在标准中定义的:RFC7946
这是 RFC 中关于多边形的相关部分:https://www.rfc-editor.org/rfc/rfc7946#section-3.1.6 其中指出:
- For type "Polygon", the "coordinates" member MUST be an array of linear ring coordinate arrays.
- For Polygons with more than one of these rings, the first MUST be the exterior ring, and any others MUST be interior rings. The exterior ring bounds the surface, and the interior rings (if present) bound holes within the surface.
线性环定义为:
- A linear ring is a closed LineString with four or more positions.
LineString 是 https://www.rfc-editor.org/rfc/rfc7946#section-3.1.4:
- For type "LineString", the "coordinates" member is an array of two or more positions.
基本上,多边形被定义为一系列闭合的 LineString,第一个 LineString 定义多边形的边界,随后的 LineString 定义第一个 LineString 中的“孔”。
以这种方式定义,可以创建一个多边形的圆环形状。
这种类型的构造只有在表示为数组的数组时才有可能,因此是标准。