是否可以使用javascript内置函数合并多个GeoJSON对象?如果不行,我该如何在程序运行期间完成此操作?
我尝试了geoJSON1 = geoJSON1.concat(geoJSON2)
,这是根据JSON的建议(e.g. here),但返回了geoJSON1.concat is not a function
。这些GeoJSON是点要素,并且是有效的GeoJSON对象。
这可能是一个简单的问题,答案可能是否定的,但我还没有找到一个确定的答案。
示例GeoJSON:
GeoJSON1 = { "type" : "FeatureCollection",
"features" : [
{ "type" : "Feature",
"id" : 1,
"geometry" : {
"type" : "Point",
"coordinates" : ["-119.6165333","34.35935"]},
"properties" : { "video" : "S105SC_Tape13o.noaudio.mpg", "video_second" : "0", "time" : "19:26:58", "date" : "2005-08-26"}
},
{ "type" : "Feature",
"id" : 2,
"geometry" : {
"type" : "Point",
"coordinates" : ["-119.6165167","34.35935"]},
"properties" : { "video" : "S105SC_Tape13o.noaudio.mpg", "video_second" : "2", "time" : "19:27:00", "date" : "2005-08-26"}
}
]
}
GeoJSON2 = { "type" : "FeatureCollection",
"features" : [
{ "type" : "Feature",
"id" : 27,
"geometry" : {
"type" : "Point",
"coordinates" : ["-119.61635","34.3593833"]},
"properties" : { "video" : "S105SC_Tape13o.noaudio.mpg", "video_second" : "55", "time" : "19:27:53", "date" : "2005-08-26"}
},
{ "type" : "Feature",
"id" : 28,
"geometry" : {
"type" : "Point",
"coordinates" : ["-119.6163333","34.3594"]},
"properties" : { "video" : "S105SC_Tape13o.noaudio.mpg", "video_second" : "56", "time" : "19:27:54", "date" : "2005-08-26"}
}
]
}
期望结果(单个GeoJSON包含所有原始要素):
newGeoJSON = { "type" : "FeatureCollection",
"features" : [
{ "type" : "Feature",
"id" : 1,
"geometry" : {
"type" : "Point",
"coordinates" : ["-119.6165333","34.35935"]},
"properties" : { "video" : "S105SC_Tape13o.noaudio.mpg", "video_second" : "0", "time" : "19:26:58", "date" : "2005-08-26"}
},
{ "type" : "Feature",
"id" : 2,
"geometry" : {
"type" : "Point",
"coordinates" : ["-119.6165167","34.35935"]},
"properties" : { "video" : "S105SC_Tape13o.noaudio.mpg", "video_second" : "2", "time" : "19:27:00", "date" : "2005-08-26"}
},
{ "type" : "Feature",
"id" : 27,
"geometry" : {
"type" : "Point",
"coordinates" : ["-119.61635","34.3593833"]},
"properties" : { "video" : "S105SC_Tape13o.noaudio.mpg", "video_second" : "55", "time" : "19:27:53", "date" : "2005-08-26"}
},
{ "type" : "Feature",
"id" : 28,
"geometry" : {
"type" : "Point",
"coordinates" : ["-119.6163333","34.3594"]},
"properties" : { "video" : "S105SC_Tape13o.noaudio.mpg", "video_second" : "56", "time" : "19:27:54", "date" : "2005-08-26"}
}
]
}
concat
方法不起作用的原因吗? @kristaps 我添加了一些简单的输入和结果示例。 - Evan