Format a specific GeoJSON file into the correct format
You could write a simple script in (for example) Python that will process the data for you.
import json
from itertools import chain
Open the file and read the data into a Python dictionary:
isil = json.load(open('isil.en.json'))
The points object is just a list of feature collections, so you can use the python itertools
library to help chain the features in those collections together:
features = list(chain.from_iterable(fc['feature'] for fc in isil['points']))
And finally write a new feature collection with all 2818 features out to a file.
feature_collection = {
"type": "FeatureCollection":,
"features": features
}
with open("isil_points.geojson", "w") as f:
json.dump(feature_collection, f)
And that should be able to be loaded up into a system of your choice. Looking at the data You'll probably have to do some manual cleaning as well (some "total" locations and a few points that don't have a location), but that should be a start.
Because it's a "oneshot", you can do it manually (also possible running via Node)
Open a JavaScript console in your browser.
You need to loop to get an array of array of Feature
(because each FeatureCollection
have one or more Feature
)
Then, you will use the flatten function to transform the array of array into an array (a recursive function borrowed from https://stackoverflow.com/a/15030117)
The full code is below (except the file content, not complete to keep things readable)
// Copy/paste the text from you source https://raw.githubusercontent.com/RitterLean/Geojson/master/geofile.json
content = {
"points": [{
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"geometry": {
"coordinates": [41.9773865, 36.3372536],
"type": "Point"
},
"properties": {
"attacks": 1,
"location": "Sinjar",
"date": "2015-10-16"
}
}, {
"type": "Feature",
"geometry": {
"coordinates": [43.4873886, 34.9301605],
"type": "Point"
},
"properties": {
"attacks": 2,
"location": "Baiji",
"date": "2015-10-16"
}
}, {
...
// Be careful, incomplete because shortened for illustration
intermediate_result = content['points'].map(function(el){
return el.features;
});
function flatten(arr) {
return arr.reduce(function (flat, toFlatten) {
return flat.concat(Array.isArray(toFlatten) ? flatten(toFlatten) : toFlatten);
}, []);
};
geojson_output = {
"type": "FeatureCollection",
"features": flatten(intermediate_result)
}
// Transform the object to a string you can paste into a file
console.log(JSON.stringify(geojson_output));
The result can be seen at http://geojson.io/#id=gist:anonymous/da10ab9afc9a5941ba66&map=4/19.48/22.32
You will see that some results have wrong coordinates (0, 0). It's due to the original content.
From this demo, you can also export to GeoJSON.