4

座標の JSON データを turf.polygon にフィードする方法は?

例: turf.polygon();

var polygon = turf.polygon([[
 [-2.275543, 53.464547],
 [-2.275543, 53.489271],
 [-2.215118, 53.489271],
 [-2.215118, 53.464547],
 [-2.275543, 53.464547]
]], { name: 'poly1', population: 400});

例: JSON フォーム

var json = 
{
    "type": "geojson",
    "data": 
        {
         "type": "FeatureCollection",
         "features": [{
               "type": "Feature",
               "geometry": {
                   "type": "Polygon",
                   "coordinates": [[
                         [1.275543, 54.464547], // I want to feed these coordinates
                         [1.275543, 54.489271],
                         [1.215118, 54.489271],
                         [1.215118, 54.464547],
                         [1.275543, 54.464547]  
                    ]]
                }
            }]
       }
 }

私の疑似コード:それは機能せず、エラーメッセージを返します"LinearRing of a Polygon must have 4 or more Positions."

var polygon = turf.polygon([[ json.data.features[0].geometry.coordinates ]], { name: 'poly1', population: 400});

ありがとうございました。

4

1 に答える 1