Skip to content

Instantly share code, notes, and snippets.

@keum
Last active November 26, 2018 22:49
Show Gist options
  • Save keum/7920560 to your computer and use it in GitHub Desktop.
Save keum/7920560 to your computer and use it in GitHub Desktop.
How to: Converting Shape file into geojson format
WORK FLOW:Convert Shape files into GeoJSON using GDAl library
Two step process.
Step 1.Convert Data in WGS 84 projection --> 2. Convert shp into Geojson using ogr2ogr
STEP 1. Make sure your data is in EPSG 4326 (Geographic projection WGS 84) is NOT Web Mercator projection
(most commonly used projection that can be use to post onto GitHub page is web mercator is EPSG:3857).
Before geoJSON conversion, make sure data isn't in WGS 84 projection already by checking for projection meta using ogrinfo command.
Convert WA State Plane EPSG 2926 to WGS 84 - EPSG 4326 (Geographic Projection WGS 84)
--Use ogrinfo to check the projection of data, example : sewer.shp
TYPE > ogrinfo sewer.shp -al -so *note* important to type -al first then -so
-al :means List all features of all layers (used instead of having to give layer names as arguments).
-so : means Summary Only: supress listing of features, show only the summary information
like projection, schema, feature count and extents.
Converting shape files into geographic coordinate reference system using WGS84 datum w/ long/lat
in decimal degress using ogr2ogr command
--Use command ogr2ogr -t_srs EPSG:3857 newname.shp oldname.shp example: sewer.shp (this to convert into web mercator)
TYPE > ogr2ogr -t_srs EPSG:4326 newsewer.shp sewer.shp (this into mercator)
STEP 2. Once the file has converted to right projection, use ogr2ogr command convert shape file into geoJSON format
TYPE > ogr2ogr -f geoJSON new_file.geojson shape-file.shp
NOTE: new_file has to have extension of .geojson to be view in GitHub correctly.
Displaying Long directory to display limited files in screen
>ls | more
>ls | less
@sachinsharma9780
Copy link

hey I am trying to cnvt shp file to geojson using above method but getting broken map. can u help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment