1

I want to show a number of GPX files in a TileMill map. Here's the process that I thought would work:

  1. gpsbabel -i gpx -f "$myfile" -o kml,lines=1 -F "$myfile.kml"
  2. Add as layer in Tilemill, style with line-width: 2; and voila.

But no. Only points are being rendered, not the lines between them.

The generated .kml files contain <linestring> elements, which I would have thought is the key:

    <Placemark>
      <name>Path</name>
      <styleUrl>#lineStyle</styleUrl>
      <LineString>
        <tessellate>1</tessellate>
        <coordinates>
          146.153490,-38.211270

Is the problem a shortcoming at the TileMill end, or something in how I'm converting the files? Unfortunately none of the other formats supported by TileMill (GeoJSON, Shapefiles...) are supported by GPSBabel.

Other options? I'm using PostGIS, so a way to load them straight into the database would also be fine.

1 Answer 1

0

In the end using GDAL's ogr2ogr worked:

#!/bin/bash
for f in *.gpx
do
  echo $f
  ogr2ogr -f GeoJSON "$f.json" "$f" routes
done

Then, either load the GeoJSON files directly into TileMill, or load them into PostGIS first:

psql -d gis -c "drop table ogrgeojson;"
# Annoyingly we need to specify these properties the first time we import, then use -append afterwards.
extraargs="-nlt MULTILINESTRING -lco DIM=2"
for f in /usr/share/mapbox/project/myproject/*.json
do
  echo $f
  ogr2ogr -f "PostgreSQL" $extraargs  -a_srs "EPSG:900913" PG:"host=localhost user=ubuntu dbname=gis password=..." "$f"
  extraargs="-append -nlt MULTILINESTRING"
done

End result:

Cycle tours around Victoria

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.