I have installed and played around with mapnik on my computer.
I was wondering if it is possible to draw GPX trails with mapnik as well. I looked around a bit but I couldn’t find anything that worked. I thought it would be possible by converting the GPX file to data in the postgis database, possibly with its own tag, and then a rule in the mapnik stylesheet to render it.
The closest I found was a “gpx to shape” converter, which allowed to me to get some kind of blob on the map but that’s not quite it.
It would seem to me that most tools already exist (?) but I haven’t really found something that works. Or is it much more difficult than I think to convert a bunch of coordinates to “ways” in the database?
You could try to tools that are availabe for converting gpx to osm which you then import into postgis and render with mapnik. Not really sure what is wronf with the gpx to shape solution, it should be the same as ugin postgresql
I also tried gpsbabel to convert a .gpx file to osm format, and then use osm2pgsql to put it into the database. That fails with an error: “Operation on two GEOMETRIES with different SRIDs” which doesn’t mean much to me.
The coastlines are rendered from shapefiles, try to look at your shapefile in other tools first and compare in what way they are different. I can confirm that mapnik can render shapefiles fine, since I’ve created my own, I had no problems so it would be interesting to know what you problem was.
GPX->osm: Try to make a simple import first then go back and see what you did wrong.
This should work, it’s just reality messing with the results again.
I have used mapnik to render my gpx traces, you can see the result here http://lin.pinkbile.com/gpx/
I rendered transparant tiles with a black dot for every track point. Openlayers then overlays my tiles over the osm tiles.
I wrote a simple ruby script to do the gpx → osm conversion. It just made a node tagged with amenity=post_box for every track point in the gpx files.
Then imported the osm file to postgis with a vanilla osm2pgsql. Modified the mapnik stylesheet. Then finally rendered the tiles with generate_tiles.py. I added a line to generate_tiles.py to delete blank tiles.
Here’s one: http://pixelz.se/map_bjare.jpg My tracks rendered in HotPink Converted with gpx2shp, and drawn with a few lines of code in the mapnik python script. (A lot in NV Skåne still needs to be mapped.)
you can get a sense of how to control with gpx layer is used by running the ‘ogrinfo’ command on your gpx file, eg:
$ ogrinfo test_point_line.gpx
Had to open data source read-only.
INFO: Open of test_point_line.gpx' using driver GPX’ successful.
1: waypoints (Point)
2: routes (Line String)
3: tracks (Multi Line String)
4: route_points (Point)
5: track_points (Point)
Grmbl, can’t get it to work. No errors, just no tracks on the map (probably means it is something simple )
I take a Garmin .gpx track, convert it to a shape, and import it into the DB. Selecting “way” from the created tables has lots of entries in there, so everything appears to be working. Hmmm… how can I debug this…?
gis=# select count(*) from cfd;
Hmm, there are errors in the log:
2009-04-08 06:27:33 CEST ERROR: column "the_geom" does not exist at character 17
2009-04-08 06:27:33 CEST STATEMENT: SELECT AsBinary("the_geom") AS geom from
(select way from cfd) as cfd WHERE "the_geom" && SetSRID('BOX3D(12.545 56.17817209103231, 13.0856.47480622614124)'::box3d,-1)
Does that mean I didn’t prepare the tables in the correct way? As you see, I used the same tablenames as in your example.
I was wrong but this error might help greatly, when you prepared the DB with -p you didn’t specified the geometry column so “the_geom” (default value with shp2pgsql) was choosen, but the query (select way from cfd) tries to get the column “way” wich was the one I choose (to keep it like the other mapnik requests)
To prepare the table you should use :
shp2pgsql -p -g way one_shp_file.shp | psql your_db
Hm, I must be misunderstanding something totally If I do:
shp2pgsql -p -g way 20090407_trk_edg cfd | psql gis
shp2pgsql -a -g way 20090407_trk_edg cfd | psql gis
It still gives me the same error:
2009-04-09 14:04:05 CEST ERROR: column "the_geom" does not exist at character 17
2009-04-09 14:04:05 CEST STATEMENT: SELECT AsBinary("the_geom") AS geom from
(select way from cfd) as cfd WHERE "the_geom" && SetSRID('BOX3D(4.883334414476785 51.303,5.959665585523214 51.97099999999999)'::box3d,-1)
So it still seems to want the “the_geom” column somehow?