Here's an example of some geojson that I have:
var json = {
features: [
{
properties: {
osm_key: "amenity",
extent: [
151.214672,
-33.8562966,
151.2158814,
-33.8574149
],
street: "Lower Concourse",
name: "Sydney Opera House",
state: "New South Wales",
osm_id: 4960757,
osm_type: "W",
postcode: "2061",
osm_value: "theatre",
country: "Australia"
},
type: "Feature",
geometry: {
type: "Point",
coordinates: [
151.2152582491399,
-33.85685575
]
}
},
{
properties: {
osm_key: "tourism",
extent: [
151.214672,
-33.8562966,
151.2158814,
-33.8574149
],
street: "Lower Concourse",
name: "Sydney Opera House",
state: "New South Wales",
osm_id: 4960757,
osm_type: "W",
postcode: "2061",
osm_value: "attraction",
country: "Australia"
},
type: "Feature",
geometry: {
type: "Point",
coordinates: [
151.2152582491399,
-33.85685575
]
}
},
{
properties: {
osm_key: "highway",
extent: [
-95.6987584,
29.9960185,
-95.6984449,
29.9907477
],
name: "Opera House Row Drive",
state: "Texas",
osm_id: 261793234,
osm_type: "W",
postcode: "77433",
osm_value: "residential",
city: "Cypress",
country: "United States of America"
},
type: "Feature",
geometry: {
type: "Point",
coordinates: [
-95.698749,
29.993634
]
}
},
{
properties: {
osm_key: "tourism",
street: "葆台路",
name: "Sydney Opera House",
state: "Beijing",
osm_id: 3184358225,
osm_type: "N",
postcode: "100070",
osm_value: "attraction",
city: "Beijing",
country: "China"
},
type: "Feature",
geometry: {
type: "Point",
coordinates: [
116.2844542,
39.8078321
]
}
},
{
properties: {
osm_key: "amenity",
street: "Macquarie Street",
name: "Opera House Car Park",
state: "New South Wales",
osm_id: 2877110066,
osm_type: "N",
postcode: "2000",
osm_value: "parking",
country: "Australia"
},
type: "Feature",
geometry: {
type: "Point",
coordinates: [
151.2135144,
-33.8593646
]
}
}
],
type: "FeatureCollection"
}
As you can see there are 2 entries for Sydney Opera House - one tagged with osm_value "theatre", the other tagged with "attraction".
I don't have control over the data being returned so I need a javascript function that I can pass the json to and it return a geoJson object in the same format but with the duplicate entries removed and the osm_values of the duplicates merged in csv format like:
var json = {
features: [
{
properties: {
osm_key: "amenity",
extent: [
151.214672,
-33.8562966,
151.2158814,
-33.8574149
],
street: "Lower Concourse",
name: "Sydney Opera House",
state: "New South Wales",
osm_id: 4960757,
osm_type: "W",
postcode: "2061",
osm_value: "theatre, attraction",
country: "Australia"
},
type: "Feature",
geometry: {
type: "Point",
coordinates: [
151.2152582491399,
-33.85685575
]
}
},
{
properties: {
osm_key: "highway",
extent: [
-95.6987584,
29.9960185,
-95.6984449,
29.9907477
],
name: "Opera House Row Drive",
state: "Texas",
osm_id: 261793234,
osm_type: "W",
postcode: "77433",
osm_value: "residential",
city: "Cypress",
country: "United States of America"
},
type: "Feature",
geometry: {
type: "Point",
coordinates: [
-95.698749,
29.993634
]
}
},
{
properties: {
osm_key: "tourism",
street: "葆台路",
name: "Sydney Opera House",
state: "Beijing",
osm_id: 3184358225,
osm_type: "N",
postcode: "100070",
osm_value: "attraction",
city: "Beijing",
country: "China"
},
type: "Feature",
geometry: {
type: "Point",
coordinates: [
116.2844542,
39.8078321
]
}
},
{
properties: {
osm_key: "amenity",
street: "Macquarie Street",
name: "Opera House Car Park",
state: "New South Wales",
osm_id: 2877110066,
osm_type: "N",
postcode: "2000",
osm_value: "parking",
country: "Australia"
},
type: "Feature",
geometry: {
type: "Point",
coordinates: [
151.2135144,
-33.8593646
]
}
}
],
type: "FeatureCollection"
}
The following needs to be bourne in mind:
- there may or may not be any duplicates to filter out
- the returned geoJson must stay in the same order but with the duplicates removed
- duplicates may not be adjacent items in the
featuresarray - the structure of the json should stay more or less the same but the keys in the geoJson should not be hard-coded because additional child keys (eg
coordinates,street) could be added at any point - duplicates are recognised by having both the same
properties.osm_idandproperties.osm_type - jquery is being used on the page
I've seen the following page that mentions something similar but the answer by adeneo looks to be limited to hard-coded keys: http://ift.tt/1Q0QAyk whereas I need it to be dynamic.
Hopefully someone can help.
Aucun commentaire:
Enregistrer un commentaire