Skip to content

Instantly share code, notes, and snippets.

@tdaubs
Forked from benbalter/geojson-conversion.sh
Created August 30, 2014 07:19
Show Gist options
  • Save tdaubs/884ebcf1dc0433d2340d to your computer and use it in GitHub Desktop.
Save tdaubs/884ebcf1dc0433d2340d to your computer and use it in GitHub Desktop.

Revisions

  1. @benbalter benbalter revised this gist Jun 27, 2013. 1 changed file with 8 additions and 4 deletions.
    12 changes: 8 additions & 4 deletions geojson-conversion.sh
    Original file line number Diff line number Diff line change
    @@ -1,16 +1,20 @@
    # Assumes you're in a folder with one or more zip files containing shape files
    # Outputs as geojson with the crs:84 SRS
    # Bulk convert shapefiles to geojson using ogr2ogr
    # For more information, see http://ben.balter.com/2013/06/26/how-to-convert-shapefiles-to-geojson-for-use-on-github/

    # Note: Assumes you're in a folder with one or more zip files containing shape files
    # and Outputs as geojson with the crs:84 SRS (for use on GitHub or elsewhere)

    #geojson conversion
    function shp2geojson() {
    ogr2ogr -f GeoJSON -t_srs crs:84 "$1.geojson" "$1.shp"
    }

    #unzip all files in a directory
    for var in *.zip; do unzip "$var";done
    for var in *.zip; do unzip "$var"; done

    #convert all shapefiles
    for var in *.shp; do shp2geojson ${var%\.*}; done

    # You'd probably want to `mv *.geojson [path-to-git-repo]/` at this point
    # so you could commit the file to GitHub
    # so you could commit the file to GitHub
    # Happy mapping!
  2. @benbalter benbalter revised this gist Jun 26, 2013. 1 changed file with 4 additions and 1 deletion.
    5 changes: 4 additions & 1 deletion geojson-conversion.sh
    Original file line number Diff line number Diff line change
    @@ -10,4 +10,7 @@ function shp2geojson() {
    for var in *.zip; do unzip "$var";done

    #convert all shapefiles
    for var in *.shp; do shp2geojson ${var%\.*}; done
    for var in *.shp; do shp2geojson ${var%\.*}; done

    # You'd probably want to `mv *.geojson [path-to-git-repo]/` at this point
    # so you could commit the file to GitHub
  3. @benbalter benbalter revised this gist Jun 25, 2013. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions geojson-conversion.sh
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,6 @@
    # Assumes you're in a folder with one or more zip files containing shape files
    # Outputs as geojson with the crs:84 SRS

    #geojson conversion
    function shp2geojson() {
    ogr2ogr -f GeoJSON -t_srs crs:84 "$1.geojson" "$1.shp"
  4. @benbalter benbalter revised this gist Jun 25, 2013. 1 changed file with 8 additions and 2 deletions.
    10 changes: 8 additions & 2 deletions geojson-conversion.sh
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,10 @@
    #geojson conversion
    function shp2geojson() {
    ogr2ogr -f GeoJSON -t_srs crs:84 "$0.geojson" "$1.shp"
    }
    ogr2ogr -f GeoJSON -t_srs crs:84 "$1.geojson" "$1.shp"
    }

    #unzip all files in a directory
    for var in *.zip; do unzip "$var";done

    #convert all shapefiles
    for var in *.shp; do shp2geojson ${var%\.*}; done
  5. @benbalter benbalter created this gist Jun 25, 2013.
    4 changes: 4 additions & 0 deletions geojson-conversion.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    #geojson conversion
    function shp2geojson() {
    ogr2ogr -f GeoJSON -t_srs crs:84 "$0.geojson" "$1.shp"
    }