Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Python script to merge all GeoJSON files in a directory into a single GeometryCollection and write as a GeoJSON.
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)
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