Keywords: Geo, OpenLayers, turbogears, turbogears2, Openstreetmap,mapnik,postgis, TMS,WMS,GML, layers, maps, googlemaps,

Maps with Turbogears


virtualenv --no-site-packages tg2env
cd tg2env/
source bin/activate
easy_install -i tg.devtools
easy_install -i tg.ext.geo
easy_install tw.openlayers
easy_install psycopg2

Create project

paster quickstart geotry

python develop

vi geotry.egg-info/paster_plugins.txt


[zipcodes]            #Name of the page/section
singular=zipcode      #Singular name
plural=zipcodes       #Plural name
db=gis                #Name of the database in postgreGIS
table=zipcodes        #Table name that holds geographic infomration
epsg=4326             #Projection, "European petroleum survey group" Standard projection on most maps
units=degrees         #Units
geomcolumn=the_geom   #The geographic column that holds shapes of geographic data. Usually its called the_geom
idcolumn=Integer:gid  #ID

paster geo-layer zipcodearea

-- controllers
|   |   |--
|   |   |--
|   |   |--
|   |   |--
|   |   |--
|   |   `--


vi geotry/controllers/

from geotry.controllers.zipcodearea import ZipcodeareaController

class RootController(BaseController):
    #admin = DBMechanic(SAProvider(metadata), '/admin')



run app

paster serve --reload development.ini

Generate layers and maps


from tw.api import WidgetsList, js_symbol
from tw.openlayers import Map, GML, WMS, OMSMapnik,OMSRenderer, LayerSwitcher, OverviewMap, \
                    MouseToolbar, MousePosition, PanZoomBar, \
                    Permalink, SelectFeature

class MyLayers(WidgetsList):
    ol = WMS(name="OpenLayers WMS",
        options = {'layers':'basic'})
    nasa = WMS(name="NASA Global Mosaic",
        options={'layers': 'landsat7'})
    mapnik = OSMMapnik(name='MAPNIK')
    transportation = GML(name="Transportation", url="countries",
        options = {
            "format": js_symbol(" OpenLayers.Format.GeoJSON"),
            "isBaseLayer": False,
            "projection": js_symbol(' new OpenLayers.Projection("EPSG:4326")')

class MyControls(WidgetsList):
    ls = LayerSwitcher()
    ovm = OverviewMap()
    mtb = MouseToolbar()
    mp = MousePosition()
    pzb = PanZoomBar()
    pl = Permalink()
    sf = SelectFeature(layer_name="Transportation", options={
            "hover": True,
            "onSelect": js_symbol("show_info"),
            "onUnselect": js_symbol("erase_info")})

mymap = Map(id="map", layers=MyLayers(), controls=MyControls(),
                            center=(15,0), zoom=3)

    def index(self): = mymap
        return dict(page='index')

Layer in wms is usually a url part http://localhost/mymaps/basic/someWMSservice
layers:basic should get you a basic map using VMAP0 data refer to WMS way of serving maps (http://localhost/mymaps/basic/someWMSservice)
but layers:landsat7 should show up landsat imagery (http://localhost/mymaps/landsat7/someWMSservice)


  1. (Main source)

  2. (Stand alone java script. Your final TG could should have similar characteristics)

  3. (Examples of maps in turbogears2 apps)

  4. (IEEE Review)

  5. This document was made in Chicago IL.

MyWiki: TurboGears2/tg.ext.geo (last edited 2009-09-06 02:49:19 by localhost)