-
-
Save nagellette/8098d9055259a959fcc36c9607f1c5dc 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