python - Creating a OSM map tiles server in Django -
i followed tutorial switch2osm create tiles server, tutorial apache server.
i have django server , wanted create custom map it. installed mapnik, postgis , loaded osm data postgis database.
i created python script that, using mapnik, creates simple map following code:
#!/usr/bin/env python import mapnik stylesheet = 'database.xml' image = 'database.png' m = mapnik.map(900, 450) mapnik.load_map(m, stylesheet) m.zoom_all() mapnik.render_to_file(m, image) print "rendered image '%s'" % image
and xml file:
<map background-color="steelblue" srs="+proj=longlat +ellps=wgs84 +datum=wgs84 +no_defs"> <style name="my style"> <rule> <polygonsymbolizer fill="#f2eff9" /> <linesymbolizer stroke="rgb(50%,50%,50%)" stroke-width="0.1" /> </rule> </style> <layer name="countries" status="on" srs="+proj=latlong +datum=wgs84"> <stylename>my style</stylename> <datasource> <parameter name="type">postgis</parameter> <parameter name="host">localhost</parameter> <parameter name="dbname">db</parameter> <parameter name="user">user</parameter> <parameter name="password"></parameter> <parameter name="table">(select * planet_osm_line highway not null) foo</parameter> <!-- <parameter name="extent">-180,-90,180,89.99</parameter> --> <!-- <parameter name="extent">-20037508.34,-20037508.34,20037508.34,20037508.34</parameter> --> </datasource> </layer> </map>
this generates following image (i loaded osm data , not whole planet):
i thinking of creating create django view offer map tiles, takes long process (3 minutes).
how can use mapnik create, django, tile server? there django library make easier?
i guess mix 2 complete independend things:
django service
this part, create kinds of logic, models, views etc. on dedicated usecase. example code plattform mark interesting places on map, can use djangos geoapp (fka. geodjango) embedd geospatial magic etc.
tile map service
this (independly!) creates map tiles can consumed other application (desktop gis... js webmap widgets). people use existing tile-providers maps without own work , free. if need create own custom mapstyle need host own tile rendering stack, explained @ www.switch2osm.org . anyway, it's highly recommend follow guide , rely on existing tools (mapnik, postgis, ...) avoid lot of troubles. please keep in mind hardware , service requirements (tile coverage, reliability, update-frequency, ...) before start own service!
this tiles how ever linked @ django frontend code leaflet/openlayers/... layer. nothing more :)
Comments
Post a Comment