Skip to content

Instantly share code, notes, and snippets.

@papakpmartin
Last active June 12, 2018 04:16
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 papakpmartin/b22a64862eac945a2216725d07c6ace4 to your computer and use it in GitHub Desktop.
Save papakpmartin/b22a64862eac945a2216725d07c6ace4 to your computer and use it in GitHub Desktop.
Merging shapefiles and making GEOJSON

After downloading the Natural Earth country and state/province shapefiles, unzip them into a directory and then cd into that directory. Then merge the shapefiles into one file called merged.shp by doing...

docker run -v $(pwd):/data geodata/gdal \
ogr2ogr \
  -lco ENCODING=UTF-8 \
  -f "ESRI Shapefile" \
  merged.shp \
  ne_50m_admin_0_countries/ne_50m_admin_0_countries.shp

docker run -v $(pwd):/data geodata/gdal \
ogr2ogr \
  -lco ENCODING=UTF-8 \
  -f "ESRI Shapefile" \
  -update \
  -append merged.shp ne_50m_admin_1_states_provinces/ne_50m_admin_1_states_provinces.shp \
  -nln merged

Then generate the GEOJSON (selecting only a few properties of interest with the goal of reducing file size) by doing...

docker run -v $(pwd):/data geodata/gdal \
ogr2ogr \
  -f GeoJSON \
  -select NAME,ADM0_A3,TYPE \
  -simplify 0.15 \
  merged.geojson \
  merged.shp
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment