Some good news for the open-source GIS community (at least something I recently discovered): GitHub.com now renders TopoJSON and GeoJSON in addition to JSON for a repository on any github.com account. In this post I will show how a .shp or ESRI Shapefile can be converted into GeoJSON and rendered in GitHub with some simple command line tools and basic familiarity with GitHub. (Similar instructions can be found at this website: http://ben.balter.com/2013/06/26/how-to-convert-shapefiles-to-geojson-for-use-on-github/)
The steps to convert .shp or ESRI Shapefile to GeoJSON are as follows: (Preface) I did this in OSX (Apple) so if you are on a PC see the link above for more instructions.
1. First, If you don’t already have it, install homebrew by opening up terminal and running:
$ ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
2. Then… Install gdal with the command:
$ brew install gdal
3. Download or acquire a Shapefile (distributed as a .zip file) from your data source of interest and unzip it someplace convenient (some place that is easy to navigate to on drive). Unzip the shape file if not already unzipped and remember where the folder directory it is stored in. You can find shapefiles in many geo data portals, for this project I chose the city of Boulder Colorado’s GIS and Maps Open Data webpage: https://bouldercolorado.gov/open-data
4. Once you have copied the shapefile folder from downloads to your new project folder, you can change the directory in terminal to the directory you project and then into the shapefile folder itself (I created a new folder for the shapefile folder to be in, this is not necessary but helps with organization if you are doing this to many shapefiles).
$ cd ~/myShapefile
5. Run (replacing
[name] with the name of your Shapefile):
$ ogr2ogr -f GeoJSON -t_srs crs:84 [name].geojson [name].shp
6. The resulting GeoJSON can be found in the same directory as the Shapefile once step 5 succeeds
7. Now it is time to commit the GeoJSON file to an empty repository on GitHub so we can view it in GitHub’s map previewer. If you already know how to do this then you can skip to the bottom of this tutorial to see what the results can look like on Git Hub, however if you are new to Git Hub keep reading. To commit to GitHub I will provide a quick starters guide (which can also be found at (http://readwrite.com/2013/09/30/understanding-github-a-journey-for-beginners-part-1 AND http://readwrite.com/2013/10/02/github-for-beginners-part-2):
If you don’t have a GitHub account follow the instructions in the first link(s) I posted above.
To configure GitHub through the command line use these commands along with your credentials from GitHub.com:
$ git config --global user.name "Your Name Here"
Next you will need to confirm your email associated with your GitHub terminal by typing this into Terminal:
$ git config --global user.email "email@example.com"
Now create a new repository page on GitHub’s website:
Create a local repository by creating a folder for your project in Finder and navigate to it in terminal using $ mkdir and $ cd:
Initialize the local git repository by using “git init”
If you have hidden or “invisible” folders shown in Finder you should see a .git folder added to your project folder. If you don’t have hidden or “invisible” folders visible you can enable them by following the instructions on this website.
You can edit or create a README.txt file if you would like to provide a description of your data however the next step is to commit this GeoJSON file to GitHub.com using the following commands:
git add yourGeoJSONFile.geojson
git commit -m “Add yourGeoJSONFile.geojson"
Make sure you type Add and a space within the quotations before entering your file name
First make sure your remote and origin are set correctly, using your username and project name
git remote add origin https://github.com/username/myproject.git
to check this use
git remote -v
Now you should see the two options (push and fetch). We want to push up to the master branch of our online GitHub repository. We do this by running a command like this
git push origin master
This should show some processing scripts, it should look something like this example that I did for main roads in Boulder Colorado:
Nicolass-MacBook-Pro:BoulderProject nico$ git add Mainrd.geojson
Nicolass-MacBook-Pro:BoulderProject nico$ git commit -m “Add Mainrd.geojson”
[master 5b89e22] Add Mainrd.geojson
1 file changed, 1501 insertions(+)
create mode 100644 Mainrd.geojson
Nicolass-MacBook-Pro:BoulderProject nico$ git push origin master
Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 272 bytes | 0 bytes/s, done.
Total 2 (delta 1), reused 0 (delta 0)
a30d30f..5b89e22 master -> master
Now in your browser you should be able to sign in and see the contents of your project uploaded to your repository you created for this project. Here are some pictures of how some of my data rendered in the repository
Thank you for reading I hope you find this useful for converting Shapefiles to GeoJSON and previewing GeoJSON files on GitHub.
There are 38 maps in this collection. Very insightful, beautifully composed and thoughtfully crafted to teach us about world economies. #mapsoftheworld #cartography #economics #world #education #maps #insights #spatiallearning #spatialinformatics
This past week at the FOSS4G open source geospatial software conference in Portland Oregon map makers and developers exhibited talents, methodologies and software that are as inspiring as they are enabling. I myself took two insightful workshops at Portland State University (PSU) and volunteered for some phenomenal presentations hosted at the Oregon Convention Center.
With these open source tools I will be transforming some static maps I created for previous clients and cartography class exercises into web maps. With the flexibility and accessibility that open source GIS platforms like OpenGeo, GeoNode and CartoDB give us as map makers of the present (online and on mobile) I am excited to breathe new life into previous works. Stay tuned, I welcome any comments on this new portfolio of work I will post here on geoidlife.com.
Oh and thanks again to everyone who helped make FOSS4G happen, it was truly an eye opening experience to what we can do with the power of where.
Interesting map projections article: Cartographic Anomalies: How Map Projections Have Shaped Our Perceptions of the World –Elizabeth Borneman
I am taking a class on projections as part of an elective at the University of Redlands MS GIS program and I thought I would share some projections that created interesting distortions to loxodromic (rhumb lines) lines and geodesics (great circles). The projections themselves create interesting distortions on the shapes/areas of countries and continents of the world.
Loxodromic lines in magenta, Geodesic (great circle) lines in navy blue, straight lines in light blue. Let me know what you think
Beautiful map of Aspen Mountain from skimap.org. Map developed for US Forest Service.
Year Published: 2009
Artist: Bill C. Brown
Added on: 28th Feb 2010
“…maps let you see where you’re going and where we want to be.” –Linda Hecht (‘Location Analytics: The Future is Where’. Wired Magazine. November 1st, 2013)
Isn’t this at the core of what we use geography and G.I.S. for?