Goal: be able to compute geo files (.shp, kml, geojson, topojson for arbitrary census geographic entities)

What are useful libraries?

From Learning Geospatial Analysis with Python > Preface > What you need for this book : Safari Books Online:

Python Version 2.x (minimum Version 2.5)
GDAL/OGR Version 1.7.1 or later
GEOS Version 3.2.2 or later
PyShp 1.1.6 or later
Shapely Version 1.2 or later
Proj Version 4.7 or later
PyProj Version 1.8.6 or later
NumPy
PNGCanvas
Python Imaging Library (PIL)

using ogr2ogr command line to convert shapefile to geojson

On my mac, I installed binaries from Build Notes [KyngChaos Wiki] -> but I see

conda install gdal

will give you command line tools like ogr2ogr

Documentation: GDAL: ogr2ogr -- see whether How to convert Shapefiles to GeoJSON maps for use on GitHub (and why you should) » Ben Balter gives the right incantation:

ogr2ogr -f GeoJSON -t_srs crs:84 [name].geojson [name].shp

In [1]:
!ls /Users/raymondyee/Downloads/tl_2010_06001_bg00/tl_2010_06001_bg00.shp


ls: /Users/raymondyee/Downloads/tl_2010_06001_bg00/tl_2010_06001_bg00.shp: No such file or directory

In [2]:
!rm /Users/raymondyee/Downloads/tl_2010_06001_bg00/tl_2010_06001_bg00.geojson
!/Library/Frameworks/Python.framework/Versions/Current/bin/ogr2ogr -f GeoJSON /Users/raymondyee/Downloads/tl_2010_06001_bg00/tl_2010_06001_bg00.geojson /Users/raymondyee/Downloads/tl_2010_06001_bg00/tl_2010_06001_bg00.shp
#!ogr2ogr -f GeoJSON -t_srs crs:84 /Users/raymondyee/Downloads/tl_2010_06001_bg00/tl_2010_06001_bg00.geojson /Users/raymondyee/Downloads/tl_2010_06001_bg00/tl_2010_06001_bg00.shp


rm: /Users/raymondyee/Downloads/tl_2010_06001_bg00/tl_2010_06001_bg00.geojson: No such file or directory
/bin/sh: /Library/Frameworks/Python.framework/Versions/Current/bin/ogr2ogr: No such file or directory
ogr2ogr -f GeoJSON tl_2010_06001_bg00.geojson tl_2010_06001_bg00.shp

ogr2ogr -f GeoJSON tl_2010_06001_tract10.geojson tl_2010_06001_tract10.shp

GDAL


In [3]:
import gdal
import ogr
import osr
import gdalnumeric
import gdalconst

In [ ]: