Created
March 20, 2019 14:55
-
-
Save ericrobskyhuntley/790937a759fd89ed77c8831f880f854c to your computer and use it in GitHub Desktop.
Python script to merge all GeoJSON files in a directory into a single GeometryCollection and write as a GeoJSON.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import glob | |
import geojson | |
json_dir_name = "./" | |
json_pattern = os.path.join(json_dir_name,'*.geojson') | |
file_list = glob.glob(json_pattern) | |
collection = [] | |
for file in file_list: | |
with open(file) as f: | |
layer = geojson.load(f) | |
collection.append(layer) | |
geo_collection = geojson.GeometryCollection(collection) | |
with open('test_collection.geojson', 'w') as f: | |
geojson.dump(geo_collection, f) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment