[GIS] Format a specific GeoJSON file into the correct format

geojsonjson

I want to use this json file it is no GeoJSON file yet but I noticed that it contains several Features and not one which I find confusing. I wanted to ask if you know some tool where I can merge all Features/FeatureCollections into one valid GeoJSON file so I can use it for like D3.js? The original file is here and I already got rid of the stuff which is not needed for the geojson.

Here is an excerpt of the GeoJson, it is fairly big so I'ts just a snippet

{"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"
            }
        }, {
            "type": "Feature",
            "geometry": {
                "coordinates": [42.4509315, 36.3707008],
                "type": "Point"
            },
            "properties": {
                "attacks": 3,
                "location": "Tal Afar",
                "date": "2015-10-16"
            }
        }, {
            "type": "Feature",
            "geometry": {
                "coordinates": [43.76667, 35.31667],
                "type": "Point"
            },
            "properties": {
                "attacks": 1,
                "location": "Hawija",
                "date": "2015-10-16"
            }
        }]
    }, {
        "type": "FeatureCollection",
        "features": [{
            "type": "Feature",
            "geometry": {
                "coordinates": [43.7820587, 33.3516083],
                "type": "Point"
            },
            "properties": {
                "attacks": 4,
                "location": "Fallujah",
                "date": "2015-04-24"
            }
        }, {
            "type": "Feature",
            "geometry": {
                "coordinates": [43.2637405, 33.4324112],
                "type": "Point"
            },
            "properties": {
                "attacks": 1,
                "location": "Ramadi",
                "date": "2015-04-24"
            }
        }, {
            "type": "Feature",
            "geometry": {
                "coordinates": [43.1170998, 36.3246002],
                "type": "Point"
            },
            "properties": {
                "attacks": 5,
                "location": "Mosul",
                "date": "2015-04-24"
            }
        }, {
            "type": "Feature",
            "geometry": {
                "coordinates": [38.3535004, 36.8908997],
                "type": "Point"
            },
            "properties": {
                "attacks": 4,
                "location": "Kobane",
                "date": "2015-04-24"
            }
        }, {
            "type": "Feature",
            "geometry": {
                "coordinates": [42.4509315, 36.3707008],
                "type": "Point"
            },
            "properties": {
                "attacks": 1,
                "location": "Tal Afar",
                "date": "2015-04-24"
            }
        }]
    }, {
        "type": "FeatureCollection",
        "features": [{
            "type": "Feature",
            "geometry": {
                "coordinates": [43.7820587, 33.3516083],
                "type": "Point"
            },
            "properties": {
                "attacks": 1,
                "location": "Fallujah",
                "date": "2015-09-09"
            }
        }, {
            "type": "Feature",
            "geometry": {
                "coordinates": [43.2637405, 33.4324112],
                "type": "Point"
            },
            "properties": {
                "attacks": 3,
                "location": "Ramadi",
                "date": "2015-09-09"
            }
        }, {
            "type": "Feature",
            "geometry": {
                "coordinates": [41.9773865, 36.3372536],
                "type": "Point"
            },
            "properties": {
                "attacks": 1,
                "location": "Sinjar",
                "date": "2015-09-09"
            }
        }, {
            "type": "Feature",
            "geometry": {
                "coordinates": [43.4873886, 34.9301605],
                "type": "Point"
            },
            "properties": {
                "attacks": 1,
                "location": "Baiji",
                "date": "2015-09-09"
            }
        }, {
            "type": "Feature",
            "geometry": {
                "coordinates": [42.4509315, 36.3707008],
                "type": "Point"
            },
            "properties": {
                "attacks": 2,
                "location": "Tal Afar",
                "date": "2015-09-09"
            }
        }, 

Do you have some ideas how to solve this problem and get a proper GeoJSON file?

Best Answer

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.

The points from each of the feature collections, merged.