Skip to content

Commit

Permalink
Merge pull request #1471 from makinacorpus/fix_gpx_waypoint_projection
Browse files Browse the repository at this point in the history
Fix projection of waypoints in GPX exports
  • Loading branch information
Gaël UTARD committed Jul 30, 2015
2 parents 33319ae + c4d269f commit 9296612
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
4 changes: 2 additions & 2 deletions conf/buildout.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ zc.buildout = 1.7.1
# From Geotrek
#
Django = 1.6.5
mapentity = 2.4.2
mapentity = 2.5.2
GDAL=1.10.0
tif2geojson=0.1.3
django-extended-choices = 0.3.0
Expand All @@ -100,7 +100,7 @@ django-leaflet = 0.16.0
django-geojson = 2.6.0
django-appypod = 0.0.2
django-screamshot = 0.4.0
gpxpy = 0.7.1
gpxpy = 0.9.8
BeautifulSoup4 = 4.1.3
requests = 1.2.3
django-modeltranslation = 0.7.3
Expand Down
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ CHANGELOG
**Bug fixes**

* Reload supervisor configuration after Geotrek upgrade
* Fix projection of waypoints in GPX exports

**Documentation**

Expand Down
9 changes: 5 additions & 4 deletions geotrek/trekking/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import datetime
import json

import gpxpy
import gpxpy.gpx
from django.conf import settings
from django.core.urlresolvers import reverse
from django.utils import translation
Expand All @@ -29,9 +29,10 @@ class TrekGPXSerializer(GPXSerializer):
def end_object(self, trek):
super(TrekGPXSerializer, self).end_object(trek)
for poi in trek.pois.all():
wpt = gpxpy.gpx.GPXWaypoint(latitude=poi.geom.y,
longitude=poi.geom.x,
elevation=poi.geom.z)
geom_3d = poi.geom_3d.transform(4326, clone=True) # GPX uses WGS84
wpt = gpxpy.gpx.GPXWaypoint(latitude=geom_3d.y,
longitude=geom_3d.x,
elevation=geom_3d.z)
wpt.name = u"%s: %s" % (poi.type, poi.name)
wpt.description = poi.description
self.gpx.waypoints.append(wpt)
Expand Down
16 changes: 15 additions & 1 deletion geotrek/trekking/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from django.contrib.gis.geos import LineString, MultiPoint, Point
from django.core.management import call_command
from django.core.urlresolvers import reverse
from django.db import connection
from django.db import connection, connections, DEFAULT_DB_ALIAS
from django.template.loader import find_template
from django.test import RequestFactory
from django.test.utils import override_settings
Expand Down Expand Up @@ -704,6 +704,16 @@ def test_points_reference_is_marked_as_disabled_when_disabled(self):
class TrekGPXTest(TrekkingManagerTest):

def setUp(self):
# Create a simple fake DEM
conn = connections[DEFAULT_DB_ALIAS]
cur = conn.cursor()
cur.execute('CREATE TABLE mnt (rid serial primary key, rast raster)')
cur.execute('INSERT INTO mnt (rast) VALUES (ST_MakeEmptyRaster(10, 10, 700040, 6600040, 10, 10, 0, 0, %s))', [settings.SRID])
cur.execute('UPDATE mnt SET rast = ST_AddBand(rast, \'16BSI\')')
for y in range(0, 1):
for x in range(0, 1):
cur.execute('UPDATE mnt SET rast = ST_SetValue(rast, %s, %s, %s::float)', [x + 1, y + 1, 42])

self.login()

self.trek = TrekWithPOIsFactory.create()
Expand Down Expand Up @@ -743,8 +753,12 @@ def test_gpx_contains_pois(self):
waypoint = waypoints[0]
name = waypoint.find('name').string
description = waypoint.find('desc').string
elevation = waypoint.find('ele').string
self.assertEqual(name, u"%s: %s" % (pois[0].type, pois[0].name))
self.assertEqual(description, pois[0].description)
self.assertEqual(waypoint['lat'], '46.5003601787')
self.assertEqual(waypoint['lon'], '3.00052158552')
self.assertEqual(elevation, '42.0')


class TrekViewTranslationTest(TrekkingManagerTest):
Expand Down

0 comments on commit 9296612

Please sign in to comment.