为什么将多边形GeoJSON对象的坐标存储在数组数组中? [英] Why are coordinates of polygon GeoJSON Objects stored in an array of array?

查看:406
本文介绍了为什么将多边形GeoJSON对象的坐标存储在数组数组中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

官方文档页中,多边形GeoJSON对象如下:

As seen in the Official documentation page, "Schema" of the polygon GeoJSON Object is as below:

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

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

why cannot it be simply as shown below: Type A

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

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

I assume the reason might be to store multiple geofences....am i right?

类似:类型B

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

我之所以发布此问题,是因为在使用Mongo DB中的某些功能(例如 $ geoIntersects $ geoWithin )后,我猜我的假设是错误的要求模式"采用 Type A 格式

The reason why i posted this question is because i guess my assumption is wrong after using some of the features in Mongo DB(like $geoIntersects and $geoWithin) which requires the "schema" to be in Type A format

推荐答案

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

MongoDB does not define the GeoJSON format. Instead, it was defined in a standard: RFC7946

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

This is the relevant section about polygon in the RFC: https://tools.ietf.org/html/rfc7946#section-3.1.6 where it stated:

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

  • 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.

其中线性环定义为:

  • 线性环是具有四个或更多位置的闭合LineString.
  • A linear ring is a closed LineString with four or more positions.

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

And a LineString is https://tools.ietf.org/html/rfc7946#section-3.1.4:

  • 对于类型"LineString","coordinates"成员是两个或 更多职位.
  • For type "LineString", the "coordinates" member is an array of two or more positions.

基本上,多边形被定义为一系列闭合的LineString,其中第一个LineString定义多边形的边界,随后的LineStrings定义第一个LineString中的孔".

Basically a polygon is defined as a series of closed LineStrings, with the first LineString defining the borders of the polygon, and subsequent LineStrings defining "holes" in the first LineString.

以此方式定义,可以创建具有多边形的甜甜圈形状.

Defined in this manner, it is possible to create a donut shape with polygon.

仅当将其表示为数组数组(因此是标准数组)时,这种类型的构造才是可能的.

This type of construction is only possible if it's represented as an array of arrays, hence the standard.

这篇关于为什么将多边形GeoJSON对象的坐标存储在数组数组中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆