TileStache.Goodies.Providers.PostGeoJSON
index
/home/migurski/public_html/TileStache/TileStache/Goodies/Providers/PostGeoJSON.py

Provider that returns GeoJSON data responses from PostGIS queries.
 
This is an example of a provider that does not return an image, but rather
queries a database for raw data and replies with a string of GeoJSON. For
example, it's possible to retrieve data for locations of OpenStreetMap points
of interest based on a query with a bounding box intersection.
 
Read more about the GeoJSON spec at: http://geojson.org/geojson-spec.html
 
Caveats:
 
Currently only databases in the 900913 (google) projection are usable, though
this is the default setting for imports from osm2pgsql. The "!bbox!" query
placeholder (see example below) must be lowercase, and expands to:
    
    ST_SetSRID(ST_MakeBox2D(ST_MakePoint(ulx, uly), ST_MakePoint(lrx, lry)), 900913)
    
You must support the "900913" SRID in your PostGIS database for now. I'll make
this more flexible if this provider proves useful.
 
Example TileStache provider configuration:
 
"pois":
{
    "provider": {"class": "TileStache.Goodies.Providers.PostGeoJSON.Provider",
                 "kwargs": {
                    "dsn": "dbname=geodata user=postgres",
                    "query": "SELECT osm_id, name, way FROM planet_osm_point WHERE way && !bbox! AND name IS NOT NULL",
                    "id_column": "osm_id", "geometry_column": "way",
                    "indent": 2
                 }}
}

 
Classes
       
Provider
SaveableResponse

 
class Provider
     Methods defined here:
__init__(self, layer, dsn, query, id_column='id', geometry_column='geometry', indent=2)
getTypeByExtension(self, extension)
Get mime-type and format by file extension.
 
This only accepts "json".
renderTile(self, width, height, srs, coord)
Render a single tile, return a SaveableResponse instance.

 
class SaveableResponse
    Wrapper class for JSON response that makes it behave like a PIL.Image object.
 
TileStache.getTile() expects to be able to save one of these to a buffer.
 
  Methods defined here:
__init__(self, content, indent=2)
save(self, out, format)

 
Functions
       
row2feature(row, id_field, geometry_field)
Convert a database row dict to a feature dict.
shape2geometry(shape, projection)
Convert a Shapely geometry object to a GeoJSON-suitable geometry dict.