Why are coordinates of polygon GeoJSON Objects stored in an array of array?

五迷三道 提交于 2019-12-23 12:41:15

问题


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  ] ] ]
});

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?

Something like: Type B

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

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


回答1:


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

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.

Where a linear ring is defined as:

  • A linear ring is a closed LineString with four or more positions.

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

  • For type "LineString", the "coordinates" member is an array of two or more positions.

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.



来源:https://stackoverflow.com/questions/46917361/why-are-coordinates-of-polygon-geojson-objects-stored-in-an-array-of-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!