Skip to content

Commit

Permalink
🐛 Fixed bug for gpx file upload
Browse files Browse the repository at this point in the history
Signed-off-by: Kharude, Sachin <sachin.kharude@here.com>
  • Loading branch information
Kharude, Sachin authored and sackh committed Aug 17, 2020
1 parent d4c95a7 commit 58fb410
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 24 deletions.
17 changes: 17 additions & 0 deletions tests/data/example.gpx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<gpx version="1.0">
<name>Example gpx</name>
<wpt lat="46.57638889" lon="8.89263889">
<ele>2372</ele>
<name>LAGORETICO</name>
</wpt>
<trk><name>Example gpx</name><number>1</number><trkseg>
<trkpt lat="46.57608333" lon="8.89241667"><ele>2376</ele><time>2007-10-14T10:09:57Z</time></trkpt>
<trkpt lat="46.57619444" lon="8.89252778"><ele>2375</ele><time>2007-10-14T10:10:52Z</time></trkpt>
<trkpt lat="46.57641667" lon="8.89266667"><ele>2372</ele><time>2007-10-14T10:12:39Z</time></trkpt>
<trkpt lat="46.57650000" lon="8.89280556"><ele>2373</ele><time>2007-10-14T10:13:12Z</time></trkpt>
<trkpt lat="46.57638889" lon="8.89302778"><ele>2374</ele><time>2007-10-14T10:13:20Z</time></trkpt>
<trkpt lat="46.57652778" lon="8.89322222"><ele>2375</ele><time>2007-10-14T10:13:48Z</time></trkpt>
<trkpt lat="46.57661111" lon="8.89344444"><ele>2376</ele><time>2007-10-14T10:14:08Z</time></trkpt>
</trkseg></trk>
</gpx>
15 changes: 0 additions & 15 deletions tests/data/sample.gpx

This file was deleted.

6 changes: 3 additions & 3 deletions tests/space/test_space_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,8 +595,8 @@ def test_add_features_wktfile(empty_space):
def test_add_features_gpx(empty_space):
"""Test uploading gpx file to the space."""
space = empty_space
gpx_file = Path(__file__).parents[1] / "data" / "sample.gpx"
gpx_file = Path(__file__).parents[1] / "data" / "example.gpx"
space.add_features_gpx(gpx_file, features_size=500)
resp = space.search(params={"p.time": "2016-06-17T23:41:13"})
resp = space.search(params={"p.ele": "2376"})
flist = list(resp)
assert flist[0]["geometry"]["coordinates"] == [-122.391226, 37.778194, 0]
assert flist[0]["geometry"]["coordinates"] == [8.89241667, 46.57608333, 0]
21 changes: 15 additions & 6 deletions xyzspaces/spaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from functools import partial
from typing import Any, Dict, Generator, List, Optional, Union

import fiona
import geopandas as gpd
from geojson import Feature, GeoJSON

Expand Down Expand Up @@ -862,9 +863,17 @@ def add_features_gpx(
:param chunk_size: Number of chunks for each process to handle. The default value
is 1, for a large number of features please use `chunk_size` greater than 1.
"""
gdf = gpd.read_file(path)
with tempfile.NamedTemporaryFile(delete=False) as temp:
gdf.to_file(temp.name, driver="GeoJSON")
self.add_features_geojson(
path=temp.name, features_size=features_size, chunk_size=chunk_size
)
layers = fiona.listlayers(path)
for layer in layers:
gdf = gpd.read_file(path, driver="GPX", layer=layer)
if gdf.empty:
logger.debug(f"Empty Layer: {layer}")
continue
else:
with tempfile.NamedTemporaryFile() as temp:
gdf.to_file(temp.name, driver="GeoJSON")
self.add_features_geojson(
path=temp.name,
features_size=features_size,
chunk_size=chunk_size,
)

0 comments on commit 58fb410

Please sign in to comment.