Repository: mapbox/mapbox-sdk-py

Issue:
Encoded polylines in wrong coordinate order
Currently, we take the geojson point array and encode the point directly in [lon, lat] order. Polylines should be [lat, lon].

Discussion:

Patch:
diff --git a/docs/surface.md b/docs/surface.md
index 8fcbb77..c6e9676 100644
--- a/docs/surface.md
+++ b/docs/surface.md
@@ -86,7 +86,7 @@ contours).
 ...    polyline=True, zoom=12, interpolate=False)
 >>> points = response.geojson()
 >>> [f['properties']['ele'] for f in points['features']]
-[None, None, None]
+[2190, 2190, 2160]
 
 ```
 
diff --git a/mapbox/encoding.py b/mapbox/encoding.py
index 0674d51..6190ea6 100644
--- a/mapbox/encoding.py
+++ b/mapbox/encoding.py
@@ -68,12 +68,13 @@ def encode_waypoints(features, min_limit=None, max_limit=None, precision=6):
     return ';'.join(coords)
 
 
-def encode_polyline(features, zoom_level=18):
+def encode_polyline(features):
     """Encode and iterable of features as a polyline
     """
     points = list(read_points(features))
+    latlon_points = [(x[1], x[0]) for x in points]
     codec = PolylineCodec()
-    return codec.encode(points)
+    return codec.encode(latlon_points)
 
 
 def encode_coordinates_json(features):


Test patch:
diff --git a/tests/test_encoding.py b/tests/test_encoding.py
index fa15f14..9326ae6 100644
--- a/tests/test_encoding.py
+++ b/tests/test_encoding.py
@@ -113,7 +113,7 @@ def test_unknown_object():
 
 
 def test_encode_polyline():
-    expected = "vdatOwp_~EhupD{xiA"
+    expected = "wp_~EvdatO{xiAhupD"
     assert expected == encode_polyline(gj_point_features)
     assert expected == encode_polyline(gj_multipoint_features)
     assert expected == encode_polyline(gj_line_features)
diff --git a/tests/test_surface.py b/tests/test_surface.py
index 05bd2c7..2ba08cd 100644
--- a/tests/test_surface.py
+++ b/tests/test_surface.py
@@ -55,7 +55,7 @@ def test_surface_geojson():
 @responses.activate
 def test_surface_params():
 
-    params = "&encoded_polyline=~kbkTss%60%7BEQeAHu%40&zoom=16&interpolate=false"
+    params = "&encoded_polyline=ss%60%7BE~kbkTeAQu%40H&zoom=16&interpolate=false"
     responses.add(
         responses.GET,
         'https://api.mapbox.com/v4/surface/mapbox.mapbox-terrain-v1.json?access_token=pk.test&fields=ele&layer=contour&geojson=true' + params,