Skip to content

Instantly share code, notes, and snippets.

@ericrobskyhuntley
Created March 20, 2019 14:55
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save ericrobskyhuntley/790937a759fd89ed77c8831f880f854c to your computer and use it in GitHub Desktop.
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.
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