Javascript 如何将坐标的JSON数据馈送到turp.polygon?
如何将坐标的JSON数据馈送到turp.polygon 示例:turp.polygon(); 示例:JSON表单 我的伪代码:不起作用,并返回错误消息“多边形的线性化必须有4个或更多位置。”Javascript 如何将坐标的JSON数据馈送到turp.polygon?,javascript,json,turfjs,Javascript,Json,Turfjs,如何将坐标的JSON数据馈送到turp.polygon 示例:turp.polygon(); 示例:JSON表单 我的伪代码:不起作用,并返回错误消息“多边形的线性化必须有4个或更多位置。” 谢谢。坐标属性已经是一个深度嵌套的数组: "coordinates": [[ [1.275543, 54.464547], // I want to feed these coordinates [1.275543, 54.489271], [1.215118, 54.489271],
谢谢。坐标
属性已经是一个深度嵌套的数组:
"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]
]]
执行此操作时:
var polygon = turf.polygon([[
json.data.features[0].geometry.coordinates
]], ...
它将决心:
var polygon = turf.polygon([[
[[
[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]
]]
]], ...
您希望在不进行修改的情况下提取并使用原始嵌套数组本身。试试这个:
var polygon = turf.polygon(json.data.features[0].geometry.coordinates, { name: 'poly1', population: 400});
features
属性是数组,而不是object.ops!我忘了包括那个。但仍然有相同的错误消息。谢谢
var polygon = turf.polygon([[
json.data.features[0].geometry.coordinates
]], ...
var polygon = turf.polygon([[
[[
[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]
]]
]], ...
var polygon = turf.polygon(json.data.features[0].geometry.coordinates, { name: 'poly1', population: 400});