Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 0 down vote accepted

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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