[OSM-dev] Routing over OSM data

Sven Braun sven.braun at gmx.de
Wed Oct 24 11:58:02 BST 2007


Hmm,
like some internetpages describe, this message:

UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' in
position 1:                  ordinal not in range(128)

is an bug in python :-(

What python Version do you use? And what operating system ?
I use Ubuntu 7.04 and python 2.5.1

Does anybody know a workarround for this utf problem ?
thank
sven

Brandon Martin-Anderson schrieb:
> Looks like a unicode error, and I'm afraid I don't know how to fix it. 
> Python is my second language. I recommend asking on the list.
>
> -B
>
> On 10/22/07, * Sven Braun* <sven.braun at gmx.de 
> <mailto:sven.braun at gmx.de>> wrote:
>
>     Hi, I tried to execute your script, but got some errors.
>     What python libraries should i install ?
>
>     Thanks
>     Sven
>
>     python osm_to_pgrouting.py
>     Opening and parsing OSM file...
>     Traceback (most recent call last):
>       File "osm_to_pgrouting.py", line 6, in <module>
>         osmfile = libosm.OSMFile( osmfilename )
>       File "/var/www/openlayer/libosm.py", line 82, in __init__
>         self.parse_osmfile( filename )
>       File "/var/www/openlayer/libosm.py", line 89, in parse_osmfile
>         parser.parse(filename)
>       File "/usr/lib/python2.5/site-packages/_xmlplus/sax/expatreader.py",
>     line 109,                  in parse
>         xmlreader.IncrementalParser.parse(self, source)
>       File "/usr/lib/python2.5/site-packages/_xmlplus/sax/xmlreader.py",
>     line 123, i                 n parse
>         self.feed(buffer)
>       File
>     "/usr/lib/python2.5/site-packages/_xmlplus/sax/expatreader.py",
>     line 216,                  in feed
>         self._parser.Parse(data, isFinal)
>       File "/usr/lib/python2.5/site-packages/_xmlplus/sax/expatreader.py",
>     line 312,                  in start_element
>         self._cont_handler.startElement(name, AttributesImpl(attrs))
>       File "/var/www/openlayer/libosm.py", line 60, in startElement
>         self._curr_node.tags[ str(attrs['k']) ] = str(attrs['v'])
>     UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' in
>     position 1:                  ordinal not in range(128)
>
>
>
>
>     Brandon Martin-Anderson schrieb:
>     > Hi Sven,
>     >
>     > Yep. I got routing with one-way directional streets working with
>     > pgRouting. I figured it out while working on this routing demo with
>     > Chris, but we decided to use Graphserver (something else I wrote)
>     > instead.
>     >
>     > It's all in the python files I sent you.
>     >
>     > -B
>     >
>     > On 10/22/07, *Sven Braun* < sven.braun at gmx.de
>     <mailto:sven.braun at gmx.de>
>     > <mailto:sven.braun at gmx.de <mailto:sven.braun at gmx.de>>> wrote:
>     >
>     >     Thanks a lot. I will take a look at your files.
>     >
>     >     Have you done a routing with pgrouting on OSM Data ?
>     >     That may be very interessting.
>     >
>     >     Hopefully i understand your files, because my python is very
>     bad :-(
>     >
>     >     Thanks
>     >     Sven
>     >
>     >
>     >
>     >     Brandon Martin-Anderson schrieb:
>     >     > Hey Sven,
>     >     >
>     >     > I've attached two scripts I've used to create topology
>     databases
>     >     from
>     >     > OSM files. I haven't cleaned them up much from where I
>     last left
>     >     them,
>     >     > and contain references to local files and various other
>     junk. But
>     >     > considering I may never have a chance to finish this, I'll
>     just
>     >     give
>     >     > you what I have.
>     >     >
>     >     > "libosm.py" is a library for parsing and topologically
>     splitting OSM
>     >     > files into graph structures.
>     >     > "osm_to_pgrouting.py" is a script which converts OSM files
>     into SQL
>     >     > files for insertion into pgRouting-enabled databases.
>     >     >
>     >     > Cheers,
>     >     > B
>     >     >
>     >     > On 10/22/07, *Sven Braun* < sven.braun at gmx.de
>     <mailto:sven.braun at gmx.de>
>     >     <mailto:sven.braun at gmx.de <mailto:sven.braun at gmx.de>>
>     >     > <mailto: sven.braun at gmx.de <mailto:sven.braun at gmx.de>
>     <mailto: sven.braun at gmx.de <mailto:sven.braun at gmx.de>>>> wrote:
>     >     >
>     >     >     Hi,
>     >     >     that looks really good.
>     >     >     As you has seen i try the same, but with less success :-(
>     >     >
>     >     >     Here I create an similar Routing page.
>     >     >     http://132.230.29.38/openlayer/index2.html
>     >     >     < http://132.230.29.38/openlayer/index2.html
>     >     <http://132.230.29.38/openlayer/index2.html>>
>     >     >
>     >     >     My way was to create a postgis Database with pgrouting
>     on top.
>     >     >     First I pick the next Roads from the selected start
>     and end
>     >     point and
>     >     >     then do the routing.
>     >     >
>     >     >     This could work very fine but i have a problem with
>     the data.
>     >     >
>     >     >     I tried to convert the data in two ways with the same
>     problem:
>     >     >         1. With osm2pgsql
>     >     >         2. With osm2shp and shp2pgsql
>     >     >
>     >     >     The problem is the following:
>     >     >     The roads are stored in the geometrie table as
>     linestring or
>     >     >     multilinestring - thats okay.
>     >     >     Now I want to execute the assign_vertex_id function to
>     >     create the
>     >     >     source
>     >     >     and target fields.
>     >     >     But at this point i have the problem.
>     >     >
>     >     >     Lets consider to have the following 2 roads.
>     >     >
>     >     >     Road A:    LINESTRING (0 2, 10 2)
>     >     >     Road B:    LINESTRING (5 2, 5 0)
>     >     >
>     >     >       *----------+----------*
>     >     >                         |
>     >     >                         |
>     >     >                        *
>     >     >     Here the assign_vertex_id function doesn't connect
>     both roads.
>     >     >
>     >     >     So I need the segments of the roads like:
>     >     >
>     >     >     Road A1:    LINESTRING (0 2, 5 2)
>     >     >     Road A2:    LINESTRING (5 2, 10 2)
>     >     >     Road B:    LINESTRING (5 2, 5 0)
>     >     >
>     >     >     So I could get an perfect Graph with an very fast
>     routing.
>     >     >
>     >     >     Has someone an idea to create these segments in an
>     easy way
>     >     from the
>     >     >     actual planet.osm ?
>     >     >     Or is my intention wrong ?
>     >     >
>     >     >     regards
>     >     >     sven
>     >     >
>     >     >
>     >     >
>     >     >
>     >     >     Christopher Schmidt schrieb:
>     >     >     > http://crschmidt.net/osm/routing-demo.html
>     >     >     > (FF Only. *WILL NOT WORK IN IE.*)
>     >     >     >
>     >     >     >    1. Click "Set Start Point"
>     >     >     >    2. Click on the map
>     >     >     >    3. Click "Set Stop Point"
>     >     >     >    4. Click on the Map, and without letting go, drag
>     around.
>     >     >     >
>     >     >     > (May take some time to get started the first time,
>     since
>     >     the machine
>     >     >     > it's running on is somewhat... overused, given the
>     current
>     >     load
>     >     >     average
>     >     >     > of 3/4.)
>     >     >     >
>     >     >     > Uses http://graphserver.sourceforge.net/ with some hacks
>     >     on top
>     >     >     to load
>     >     >     > the small OSM file at
>     >     http://crschmidt.net/osm/cambridgeport.osm .
>     >     >     > Currently not entirely scalable, but that's a
>     project for next
>     >     >     weekend
>     >     >     > -- this weekend was to just get it working :)
>     >     >     >
>     >     >     > Brandon has tested Graphserver with OSM graphs of ~20MB
>     >     and had
>     >     >     good
>     >     >     > success -- now I just have to make the rest of the
>     code scale
>     >     >     similarly
>     >     >     > :)
>     >     >     >
>     >     >     > This is also, for the record, showing the use of
>     OpenLayers
>     >     >     reprojection
>     >     >     > support (not in trunk yet) -- you'll notice that it's
>     >     using the
>     >     >     standard
>     >     >     > OSM tiles, but the mouse possition, permalink, etc.
>     are in
>     >     lat/lon.
>     >     >     > (This is the part that doesn't work in IE, for the
>     >     record.) This
>     >     >     support
>     >     >     > should go into trunk in the next release.
>     >     >     >
>     >     >     > Regards,
>     >     >     >
>     >     >
>     >     >     _______________________________________________
>     >     >     dev mailing list
>     >     >     dev at openstreetmap.org <mailto:dev at openstreetmap.org>
>     <mailto:dev at openstreetmap.org <mailto:dev at openstreetmap.org>>
>     >     <mailto:dev at openstreetmap.org <mailto:dev at openstreetmap.org>
>     <mailto:dev at openstreetmap.org <mailto:dev at openstreetmap.org>>>
>     >     >    
>     http://lists.openstreetmap.org/cgi-bin/mailman/listinfo/dev
>     <http://lists.openstreetmap.org/cgi-bin/mailman/listinfo/dev>
>     >     <http://lists.openstreetmap.org/cgi-bin/mailman/listinfo/dev>
>     >     >
>     >     >
>     >
>     >
>
>




More information about the dev mailing list