Skip to content

Instantly share code, notes, and snippets.

@nagellette
Forked from ericrobskyhuntley/geojson-merge.py
Created December 14, 2019 22:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nagellette/8098d9055259a959fcc36c9607f1c5dc to your computer and use it in GitHub Desktop.
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.
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