geojson的属性功能按属性值在javascript中
我有一个Geojson功能列表,每个功能都具有其属性中的资产ID。我想操纵Geojson,因此我只剩下每个资产ID的单个功能,每个功能的属性都添加到了功能属性中。
例如,以下Geojson具有4个功能。其中2个具有100和2的资产ID,其中2个资产ID为200: -
{
"type":"FeatureCollection",
"title":"map_features",
"features":[
{
"type":"Feature",
"geometry":{
"type":"Point",
"coordinates":[
525408,
162788
]
},
"properties":{
"CASENO":"CASE29302",
"CASE_TYPE":"litterBin",
"ASSETID":"100",
"DESCRIPTION":"Bin is full"
}
},
{
"type":"Feature",
"geometry":{
"type":"Point",
"coordinates":[
525408,
162788
]
},
"properties":{
"CASENO":"CASE56843",
"CASE_TYPE":"litterBin",
"ASSETID":"100",
"NOTES":"Bin needs emptying"
}
},
{
"type":"Feature",
"geometry":{
"type":"Point",
"coordinates":[
525177,
164509
]
},
"properties":{
"CASENO":"CASE77112",
"CASE_TYPE":"litterBin",
"ASSETID":"200",
"NOTES":"Bin cleaned"
}
},
{
"type":"Feature",
"geometry":{
"type":"Point",
"coordinates":[
525177,
164509
]
},
"properties":{
"CASENO":"CASE04393",
"CASE_TYPE":"litterBin",
"ASSETID":"200",
"NOTES":"Bin full"
}
}
]
}
我希望仅保留资产ID 100和200的两个功能,并将属性从重复的功能中分组在一起: -
{
"type": "FeatureCollection",
"title": "map_features",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
525408,
162788
]
},
"properties": [
{
"CASENO": "CASE29302",
"CASE_TYPE": "litterBin",
"ASSETID": "100",
"DESCRIPTION": "Bin is full"
},
{
"CASENO": "CASE56843",
"CASE_TYPE": "litterBin",
"ASSETID": "100",
"NOTES": "Bin needs emptying"
}
]
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
525408,
162788
]
},
"properties": [
{
"CASENO": "CASE56843",
"CASE_TYPE": "litterBin",
"ASSETID": "100",
"NOTES": "Bin needs emptying"
},
{
"CASENO": "CASE04393",
"CASE_TYPE": "litterBin",
"ASSETID": "200",
"NOTES": "Bin full"
}
]
}
]
}
我不确定是否有JavaScript / jQuery方法可能会有所帮助?我需要使用循环吗?
任何指针都将不胜感激。
I have a list of geojson features that each have an asset ID in their properties. I want to manipulate the geojson so I am left with only a single feature per asset ID, with the properties from each feature found added to the feature properties.
As an example, the following geojson has 4 features; 2 of them have an asset ID of 100 and 2 of them have an asset ID of 200:-
{
"type":"FeatureCollection",
"title":"map_features",
"features":[
{
"type":"Feature",
"geometry":{
"type":"Point",
"coordinates":[
525408,
162788
]
},
"properties":{
"CASENO":"CASE29302",
"CASE_TYPE":"litterBin",
"ASSETID":"100",
"DESCRIPTION":"Bin is full"
}
},
{
"type":"Feature",
"geometry":{
"type":"Point",
"coordinates":[
525408,
162788
]
},
"properties":{
"CASENO":"CASE56843",
"CASE_TYPE":"litterBin",
"ASSETID":"100",
"NOTES":"Bin needs emptying"
}
},
{
"type":"Feature",
"geometry":{
"type":"Point",
"coordinates":[
525177,
164509
]
},
"properties":{
"CASENO":"CASE77112",
"CASE_TYPE":"litterBin",
"ASSETID":"200",
"NOTES":"Bin cleaned"
}
},
{
"type":"Feature",
"geometry":{
"type":"Point",
"coordinates":[
525177,
164509
]
},
"properties":{
"CASENO":"CASE04393",
"CASE_TYPE":"litterBin",
"ASSETID":"200",
"NOTES":"Bin full"
}
}
]
}
I am looking to be left with just two features for asset ID 100 and 200, and have the properties grouped together from the duplicate features:-
{
"type": "FeatureCollection",
"title": "map_features",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
525408,
162788
]
},
"properties": [
{
"CASENO": "CASE29302",
"CASE_TYPE": "litterBin",
"ASSETID": "100",
"DESCRIPTION": "Bin is full"
},
{
"CASENO": "CASE56843",
"CASE_TYPE": "litterBin",
"ASSETID": "100",
"NOTES": "Bin needs emptying"
}
]
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
525408,
162788
]
},
"properties": [
{
"CASENO": "CASE56843",
"CASE_TYPE": "litterBin",
"ASSETID": "100",
"NOTES": "Bin needs emptying"
},
{
"CASENO": "CASE04393",
"CASE_TYPE": "litterBin",
"ASSETID": "200",
"NOTES": "Bin full"
}
]
}
]
}
I am not sure if there is a javascript / jquery method that might help with this? Would I need to use a for loop?
Any pointers would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您有信心重复的功能具有相同的几何形状,则可以使用以下方法:
assetId
将功能分组,您可以使用map
使用降低在每个键的地方执行此操作是唯一的
AssetId
,该值是一个填充功能的数组。MAP
中的每个项目,请使用几何>几何>的数组中的第一个功能,然后使用
properties
用数组替换功能数组仅属性
。featurecollection
,并在步骤2中解决了新功能。请参阅下面的工作代码中的注释:
If you're confident that the duplicate features have the same geometry you can use this approach:
ASSETID
you can use aMap
withreduce
to do this where each key is a uniqueASSETID
and the value is an array that fills up with features.Map
, use the first feature in the array for thegeometry
and then forproperties
replace the array of features with an array of just theproperties
.featureCollection
with the new features resolved in step 2.See the comments in the working code below: