문제 설명
RethinkDB r.polygon() ‑ GeoJSON LinearRing에는 최소 4개의 위치가 있어야 합니까? (RethinkDB r.polygon() ‑ GeoJSON LinearRing must have at least four positions?)
내 데이터베이스에 geoJSON 폴리곤을 삽입하는 데 문제가 있습니다.
삽입하려는 데이터는 다음과 같습니다.
{
"feature": {
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
‑71.17351189255714,
42.350224666504324
],
[
‑71.1677360907197,
42.34671571695422
],
[
‑71.16970919072628,
42.35326835618748
],
[
‑71.14341516047716,
42.36174674733808
],
[
‑71.17559093981981,
42.368232175909064
],
[
‑71.17351189255714,
42.350224666504324
]
]
},
"properties": {}
},
"name": "New Polygon"
}
여기에 내가 시도하는 코드가 있습니다. 실행하려면:
r.table( 'homebases' ).insert( {
xid: data.xid,
name: data.name,
geoType: "polygon",
geoPoly: r.geojson( data.feature.geometry )
} ).run().then( function ( doc ) {
return res.send( doc.generated_keys[ 0 ] )
} ).error( function ( err ) {
console.error( err.message )
return res.send( 500, err.message )
} )
이 오류가 발생했습니다:
GeoJSON LinearRing must have at least four positions
geoJSON으로 정확히 동일한 작업을 수행할 수 있으므로 여기에서 무슨 일이 일어나고 있는지 잘 모르겠습니다. 포인트 및 그것은 훌륭하게 작동합니다. API 문서에는 'type': 'Polygon' geoJSON 개체를 추가할 수 있다고 나와 있습니다.
모든 곳에서 검색을 시도했지만 솔루션을 찾을 수 없었습니다. 이 작업을 어떻게 진행해야 할지 잘 모르겠습니다. 어떤 도움이라도 대단히 감사하겠습니다!!! 감사합니다!
참조 솔루션
방법 1:
The input data is not a valid GeoJSON polygon.
From the spec [1]:
For type "Polygon", the "coordinates" member must be an array of LinearRing coordinate arrays.
So let's look at what a "LinearRing coordinate array" is [2]:
A LinearRing is closed LineString with 4 or more positions. The first and last positions are equivalent (they represent equivalent points). Though a LinearRing is not explicitly represented as a GeoJSON geometry type, it is referred to in the Polygon geometry type definition.
To make it short, the input data you mention here is missing one nested array in the coordinates
field. The coordinates
of a Polygon must be an array of arrays of coordinates. This is so that you can construct a polygon with holes in it (the first LinearRing in the Polygon is the outside edge, any subsequent LinearRings in the coordinates
array will be considered holes).
The following should work:
{
"feature": {
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[
‑71.17351189255714,
42.350224666504324
],
[
‑71.1677360907197,
42.34671571695422
],
[
‑71.16970919072628,
42.35326835618748
],
[
‑71.14341516047716,
42.36174674733808
],
[
‑71.17559093981981,
42.368232175909064
],
[
‑71.17351189255714,
42.350224666504324
]
]
]
},
"properties": {}
},
"name": "New Polygon"
}
[1] http://geojson.org/geojson‑spec.html#polygon
[2] http://geojson.org/geojson‑spec.html#linestring
(by Robert Laverty、Daniel Mewes)