On 01/20/10 Tiziano D'Angelo wrote:
> Volevo chiedervi un paio di questioni.
> 1- C'è un modo per ricercare in OSM tutte le relazioni di un dato tipo o con
> un dato tag eventualmente in una data area?

Usa XAPI come suggerito, per esempio per una zona di Padova:
wget 
http://www.informationfreeway.org/api/0.6/relation[route=bus][bbox=11.867423989753554,45.41459045126265,11.88459689726845,45.425251791743904]
 -O padova-routes.xml

> 2- Come ho chiesto sulla lista public transport, c'è un modo per esportare
> in formato CSV/TXT/Excel/Database i dati delle relation (ad esempio già
> selezionate per tipo con la ricerca di cui al punto 1)? Vorrei ottenere una
> lista linea per linea con tutte le fermate in ordine andata e ritorno e in
> una colonna la lat/long associata.

Devi farti un programmino che legga l'XML.

> 3- A partire dai dati OSM, vorrei costruire delle mappe del percorso linea
> per linea (sullo stile di
> http://en.wikipedia.org/wiki/File:Bakerloo_line_Topological_map.svg e
> http://en.wikipedia.org/wiki/File:Bakerloo_Line.svg) ed eventualmente
> dell'intera rete (solo con la rete, senza mappa sullo sfondo, o
> eventualmente quasi trasparente) sia corrispondente alle coordinate
> geografiche, sia come schema in stile Parigi/Londra.

In pausa pranzo ho scritto un programmino per la versione lineare
(non e' completamente parametrizzata ma l'output e' quasi decente e gestisce
automaticamente le fermate di linee multiple in base al tag route_ref).
La versione in forma di mappa non e' molto piu' complicata.
In attach il programma (serve mono e la libreria OpenStreetMap di cui ho
postato anche in questa lista tempo fa) e un esempio di rendering.

lupus

-- 
-----------------------------------------------------------------
lu...@debian.org                                     debian/rules
lu...@ximian.com                             Monkeys do it better
using System;
using System.IO;
using System.Collections.Generic;
using Cairo;
using OpenStreetMap;

class Route {
        // gmcs route2svg.cs -r:OpenStreetMap.dll -r:Mono.Cairo
        // ./route2svg.exe /tmp/padova-routes.xml 10 linea10.svg
        List<Node> stops = new List<Node> ();
        Relation route;

        public Route (List<OsmObject> data, string routename) {
                Dictionary<long,Node> nodes = new Dictionary<long,Node> ();
                foreach (OsmObject obj in data) {
                        Node node = obj as Node;
                        if (node != null) {
                                nodes [node.ID] = node;
                                continue;
                        }
                        Relation rel = obj as Relation;
                        if (rel != null && (rel ["name"] == routename || rel 
["ref"] == routename)) {
                                route = rel;
                                break;
                        }
                }
                if (route == null)
                        throw new Exception ("Can't find route " + routename);
                foreach (RelationMember m in route.Members) {
                        if (m.Role == "forward_stop")
                                stops.Add (nodes [m.Ref]);
                }
        }

        static bool HasCrossing (string refs)
        {
                if (refs == null)
                        return false;
                string[] lines = refs.Split (new char[] {';', ' '}, 2, 
StringSplitOptions.RemoveEmptyEntries);
                return lines.Length > 1;
        }

        public void Render (string output) {
                int xlen = 40;
                int width = (1 + stops.Count) * xlen + 40;
                int heigth = 200;
                SvgSurface svg = new SvgSurface (output, width, heigth);
                using (Context cr = new Context (svg)) {
                        cr.MoveTo (20, 20);
                        string desc = string.Format ("Linea: {0} Da {1} a {2}", 
route ["name"], route ["from"], route ["to"]);
                        cr.SetFontSize (15);
                        cr.ShowText (desc);
                        int xpos = 20;
                        cr.LineWidth = 4;
                        cr.MoveTo (xpos, heigth - 30);
                        cr.LineTo (xpos + stops.Count * xlen, heigth - 30);
                        cr.Stroke ();
                        xpos += xlen / 2;
                        cr.SetFontSize (10);
                        foreach (Node n in stops) {
                                cr.Color = new Color (0, 0, 0, 1);
                                cr.MoveTo (xpos, heigth - 50);
                                cr.Save ();
                                cr.Rotate (-Math.PI / 4);
                                cr.ShowText (n ["name"]);
                                cr.Restore ();
                                cr.MoveTo (xpos, heigth - 30);
                                if (HasCrossing (n ["route_ref"]))
                                        cr.Color = new Color (0, 0, 1, 1);
                                else
                                        cr.Color = new Color (1, 0.1, 0.1, 1);
                                cr.Arc (xpos, heigth - 30, 4, 0, Math.PI * 2);
                                cr.Fill ();
                                xpos += xlen;
                        }
                        svg.Flush ();
                        svg.Finish ();
                }
        }
}

class Route2Svg {

        static int Main (string[] args) {
                // arguments: osmfile routename/routeref outfile
                List<OsmObject> data = DataBase.Load (args [0]);
                Route route = new Route (data, args [1]);
                route.Render (args [2]);
                return 0;
        }
}

Attachment: 10.svg.gz
Description: Binary data

_______________________________________________
Talk-it mailing list
Talk-it@openstreetmap.org
http://lists.openstreetmap.org/listinfo/talk-it

Reply via email to