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

Maps with Turbogears

Install

virtualenv --no-site-packages tg2env
cd tg2env/
source bin/activate
easy_install -i http://www.turbogears.org/2.0/downloads/current/index tg.devtools
easy_install -i http://www.turbogears.org/2.0/downloads/current/index tg.ext.geo
easy_install tw.openlayers
easy_install psycopg2

Create project

paster quickstart geotry

python setup.py develop

vi geotry.egg-info/paster_plugins.txt

layers.ini

[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
|   |   |-- __init__.py
|   |   |-- error.py
|   |   |-- root.py
|   |   |-- secc.py
|   |   |-- template.py
|   |   `-- zipcodearea.py

Controllers

vi geotry/controllers/root.py

from geotry.controllers.zipcodearea import ZipcodeareaController


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

development.ini

sqlalchemy.url=postgres://myuser:mypass@localhost/gis

run app

paster serve --reload development.ini

Generate layers and maps

Mylayers

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",
        url=["http://labs.metacarta.com/wms/vmap0"],
        options = {'layers':'basic'})
    nasa = WMS(name="NASA Global Mosaic",
        url=['http://t1.hypercube.telascience.org/cgi-bin/landsat7'],
        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)

@expose('geogrid.templates.index')
    def index(self):
        pylons.c.map = 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)

http://www.alistapart.com/d/takecontrolofyourmaps/webmapstack.png http://tah.openstreetmap.org/Tiles/tile/10/262/380.png

References

  1. http://www.turbogears.org/2.0/docs/main/Extensions/Geo/MapFishTutorial.html (Main source)

  2. http://wiki.openstreetmap.org/index.php/OpenLayers_Simple_Example (Stand alone java script. Your final TG could should have similar characteristics)

  3. http://geo.turbogears.org/ (Examples of maps in turbogears2 apps)

  4. http://www2.computer.org/portal/c/document_library/get_file?folderId=144965&name=DLFE-4309.pdf (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)