====== Hackfest 2009 ====== Au programme : http://thomas.enix.org/Hackfest2009 * IRC OSM : #osm-fr sur irc.oftc.net ===== Autres pages ===== * [[ToDo]] * [[Projections]] * [[Hébergement]] * [[Mapnik]] et [[OGR]] * [[Trucs]] * [[RevueDePresse]] ===== Installation et configuration de PostgreSQL/PostGIS ===== * Paquet installé pour PostGIS : postgresql-8.3-postgis. Cela installe le serveur et le client PostgreSQL, ainsi que l'extension Postgis. À noter que le paquet postgis installe seulement quelques outils liés à PostGIS, pas PostGIS lui-même. * Paquet installé pour une interface graphique d'administration de PostgreSQL: pgadmin3 * Configuration du mot de passe de l'utilisateur postgres du serveur de base de données (pas l'utilisateur Unix !), voir https://help.ubuntu.com/community/PostgreSQL#Basic%20Server%20Setup ===== Jouons avec PostGIS ===== * Connexion à la base de données: psql -h localhost -U test testdb * Création d'une table: ''create table cities (name varchar);''. On ne peut pas créer directement au //create table// les champs géographiques, car il faut non seulement créer un champ dans la table, mais aussi créer une entrée dans la date spéciale //geometry_columns// * Ajout du champ géographique: ''select addgeometrycolumn('cities', 'geom', 4002, 'POINT', 2);''. //cities// est la table, //geom// est le nom du champ, //4002// est le SRID, //POINT// le type du champ et //2// la dimension * Insertion de quelques entrées dans la table: * ''insert into cities (name, geom) values ('Plop', st_geomfromtext('POINT(10 10)', 4002));''. La fonction //st_geomfromtext()// sert à créer le bazar binaire qui sera stocké dans la table à partir d'une description en WKT (Well-Known Text) de l'information géographique. On doit également spécifier le SRID dans lequel la donnée géographique est passée. * ''insert into cities (name, geom) values ('Plap', st_geomfromtext('POINT(20 20)', 4002));'' * ''insert into cities (name, geom) values ('Plip', st_geomfromtext('POINT(30 10)', 4002));'' * Jouons avec les données en calculant les distances entre toutes les entrées de la table et le point de coordonnées (0,0) select name, st_distance(geom, st_geomfromtext('POINT(0 0)', 4002)) from cities; name | st_distance ------+------------------ Plop | 14.142135623731 Plap | 28.2842712474619 Plip | 31.6227766016838 * Jouons avec les polygones. * Création d'une table: ''create table communes (name varchar);''. * Création du champ géographique: ''select addgeometrycolumn('communes', 'geom', 4002, 'POLYGON', 2);'' * Insertion d'une donnée: ''insert into communes (name, geom) values ('Ville1', st_geomfromtext('POLYGON( (10 10, 15 20, 30 40, 10 10) )', 4002));'' * Calcul de la surface: select name, st_area(geom) from communes; name | st_area --------+--------- Ville1 | 25 * Calcul du périmètre select name, st_perimeter(geom) from communes; name | st_perimeter --------+------------------ Ville1 | 72.2358526421388 * Affichage de la donnée géographique sous forme texte (lisible!) avec la fonction ''st_astext()'' select name, st_astext(geom) from communes; name | st_astext --------+------------------------------------ Ville1 | POLYGON((10 10,15 20,30 40,10 10)) ==== Référence ==== * http://postgis.refractions.net/documentation/manual-1.4/ch02.html#id2532099 ===== OpenStreetMap dans PostGIS ===== * Chargement de france.osm dans le pgsql de Thomas avec osm2pgsql (svn rel 17214) : ''osm2pgsql -c -d testdb -m -U test -H surf.local Desktop/france.osm.bz2'' ===== Ressources ===== * SRID & co : http://cfis.savagexi.com/2006/05/03/google-maps-deconstructed * Description : http://www.sharpgis.net/post/2007/05/Spatial-references2c-coordinate-systems2c-projections2c-datums2c-ellipsoids-e28093-confusing.aspx * SRID 900913 (« google » en chiffres, osm, ...) : http://spatialreference.org/ref/sr-org/6627/ * SRID 3785 : http://www.sharpgis.net/post/2008/05/SphericalWeb-Mercator-EPSG-code-3785.aspx * API Postgis : http://postgis.refractions.net/documentation/manual-1.4/ch07.html * Stats des communes dans OSM : http://www.mail-archive.com/talk-fr@openstreetmap.org/msg12151.html * Declarations proj4 usuelles : http://www.remotesensing.org/geotiff/proj_list/ * Shapefiles : http://en.wikipedia.org/wiki/Shapefile ===== OpenStreetMap ===== * dump de la base : http://download.geofabrik.de/osm/ et en particulier http://download.geofabrik.de/osm/europe/france.osm.bz2 * Requête pour calculer la bounding box d'une commune, en supposant que les limites administratives de celles-ci existent dans OSM : ''select st_astext(st_transform(st_setsrid(st_box2d(way), 900913), 4002)) from planet_osm_polygon where name='Toulouse';'' ===== Installation Ubuntu par PXE ===== * Télécharger les fichiers nécessaires, http://archive.ubuntu.com/ubuntu/dists/jaunty/main/installer-amd64/current/images/netboot/netboot.tar.gz * Extraire l'archive (qui contient le noyau, l'initrd ainsi que le bazar PXE nécessaire) * Installer le serveur PXE de Maxime (il inclut tout le nécessaire, serveur DHCP et TFTP, etc.), disponible à l'adresse https://ssl.bulix.org/svn/ptftpd/trunk/, et les paquets Debian sur http://blog.bulix.org/pub/2009/07/15/ptftpd/ * S'assurer qu'il n'y a pas de serveur DHCP sur le réseau entre la machine à installer et la machine serveur * Lancer le serveur PXE: ''sudo pxed eth0 /la/ou/le/netboot.tar.gz/est/decompresse pxelinux.0'' * Démarrer la machine à installer. Si elle boote sur le réseau, ça marche, sinon, utiliser http://rom-o-matic.net/ pour générer une image ISO/USB avec le nécessaire pour faire du PXE ===== Installation mapnik ===== * docs : * http://trac.mapnik.org/wiki/InstallGuide * http://trac.mapnik.org/wiki/UbuntuInstallation * http://wiki.openstreetmap.org/wiki/Mapnik * compilation $ cd mapnik-0.6.1/ $ python scons/scons.py configure INPUT_PLUGINS=all \ OPTIMIZATION=3 PREFIX=/usr/local/stow/mapnik-0.6.1 \ PYTHON_PREFIX=/usr/local/stow/mapnik-0.6.1/ \ SYSTEM_FONTS=/usr/share/fonts/truetype/ttf-dejavu/ $ python scons/scons.py $ export PYTHONPATH="/home/thomas/sys/lib/python2.6/site-packages" $ export LD_LIBRARY_PATH="/home/thomas/sys/lib" $ python Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) [GCC 4.3.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import mapnik >>> $ svn checkout http://svn.openstreetmap.org/applications/rendering/mapnik mapnik-osm $ cd mapnik-osm/ $ diff -u ./set-mapnik-env.orig ./set-mapnik-env --- ./set-mapnik-env.orig 2009-08-23 18:39:24.000000000 +0200 +++ ./set-mapnik-env 2009-08-23 18:43:28.000000000 +0200 @@ -30,26 +30,26 @@ # This is the name of the *local* version of the Mapnik map file after it has # been run through the cutomize-mapnik-map script. -export MAPNIK_MAP_FILE=~/mapnik/osm.xml +export MAPNIK_MAP_FILE=~/osm/mapnik-osm/osm.xml # This is the directory where the icons and symbols for Mapnik are. If # you have checked out the OSM subversion directory into a directory # called ~/svn.openstreetmap.org, the symbols will be in # ~/svn.openstreetmap.org/applications/rendering/mapnik/symbols -export MAPNIK_SYMBOLS_DIR=~/mapnik/symbols +export MAPNIK_SYMBOLS_DIR=~/osm/mapnik-osm/symbols # This is the directory where you upacked the world_boundaries.tar.bz2 # file you got from # http://artem.dev.openstreetmap.org/files/world_boundaries.tar.bz2 -export MAPNIK_WORLD_BOUNDARIES_DIR=~/mapnik/world_boundaries +export MAPNIK_WORLD_BOUNDARIES_DIR=~/osm/mapnik-osm/world_boundaries # Directory where the created map tiles should be stored. Must end with # a slash (/) -export MAPNIK_TILE_DIR=~/mapnik/tiles/ +export MAPNIK_TILE_DIR=~/osm/mapnik-osm/tiles/ # This is the name of the server running the PostgreSQL database. Leave # this empty if your database is on the local machine. -export MAPNIK_DBHOST="" +export MAPNIK_DBHOST="localhost" # This is the TCP port where the PostgreSQL server is listening. The # default port for PostgreSQL is 5432. Leave this empty if your database @@ -57,13 +57,13 @@ export MAPNIK_DBPORT="" # This is the name of the database where the OSM data is stored. -export MAPNIK_DBNAME='osm' +export MAPNIK_DBNAME='testdb' # This is the username we should use to log into the PostgreSQL database. -export MAPNIK_DBUSER=`whoami` +export MAPNIK_DBUSER="test" # This is the password we should use to log into the PostgreSQL database. -export MAPNIK_DBPASS="" +export MAPNIK_DBPASS="test" # This is the prefix used in the table names. Matches the -p option in osm2pgsql # Unspecified defaults to "planet_osm" $ . ./set-mapnik-env $ ./customize-mapnik-map >$MAPNIK_MAP_FILE Modifier ''osm.xml''. $ wget http://tile.openstreetmap.org/world_boundaries-spherical.tgz $ wget http://tile.openstreetmap.org/processed_p.zip $ wget http://tile.openstreetmap.org/shoreline_300.tar.bz2 $ cd /home/thomas/osm/mapnik-osm/ $ tar xzf ~/osm/world_boundaries-spherical.tgz $ unzip ~/osm/processed_p.zip $ mv coastlines/* world_boundaries/ $ rmdir coastlines $ tar xjf ~/osm/shoreline_300.tar.bz2 -C world_boundaries --- generate_image.py (revision 17214) +++ generate_image.py (working copy) @@ -14,6 +14,7 @@ # pixel size so will appear smaller on a large image. from mapnik import * +import cairo import sys, os if __name__ == "__main__": @@ -26,12 +27,13 @@ #--------------------------------------------------- # Change this to the bounding box you want # - ll = (-6.5, 49.5, 2.1, 59) + #ll = (-6.5, 49.5, 2.1, 59) + ll = (-1.0901, 44.4883, -1.0637, 44.4778) #--------------------------------------------------- - z = 10 - imgx = 500 * z - imgy = 1000 * z + z = 17 + imgx = 500 + imgy = 1000 m = Map(imgx,imgy) load_map(m,mapfile) @@ -44,3 +46,8 @@ render(m, im) view = im.view(0,0,imgx,imgy) # x,y,width,height view.save(map_uri,'png') + + # SVG + surface = cairo.SVGSurface('image.svg', m.width, m.height) + render(m, surface) + $ ./generate_image.py $ gthumb image.png $ firefox image.svg ===== Préfixes pour les voies urbaines ===== Liste des déterminants : * de * du * de la * des * d' Liste des appellations particulières de rues : * Allée f. * Avenue f. * Boulevard m. * Carrefour m. * Chaussée f. * Chemin m. * Cité f. * Clos m. * Côte f. * Cour f. * Cours m. * Degré m. * Esplanade f. * Impasse f. * Liaison f. * Mail m. * Montée f. * Passage m. * Place f. * Placette f. * Pont m. * Promenade f. * Quai m. * Résidence f. * Rond-Point m. * Rang m. * Route f. * Ruelle f. * Square m. * Traboule f. * Traverse f. * Venelle f. * Voie f. Mais aussi : * Berge * Cul-de-Sac * Escalier * Parvis * Passerelle * Giratoire * Jardin Les dénominations suivantes s'appliquent à des voies qui ne sont pas des rues, soit parce qu'elles ne se trouvent pas en zone urbaine, soit qu'elles en sont complètement isolées. Ces voies ne remplissent donc qu'une fonction de circulation exclusivement : * Autoroute f. * Bretelle * Sente f. * Sentier m. ===== Cairo ===== * Tutorial Python/Cairo: http://www.tortall.net/mu/wiki/CairoTutorial