Skip to content

Commit

Permalink
Merge branch 'geobuff_changes'
Browse files Browse the repository at this point in the history
  • Loading branch information
omanges committed Aug 24, 2020
2 parents a2eb184 + 6ebdcf0 commit b7e2adc
Show file tree
Hide file tree
Showing 17 changed files with 73 additions and 29 deletions.
10 changes: 10 additions & 0 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
coverage:
status:
project:
default:
target: auto # auto compares coverage to the previous base commit
threshold: 0%
branches:
- master
comment:
layout: "reach, diff, flags, files" # Remove items here to change the format
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ script:
- make lint
- make typing
- mkdir public
- pytest -v --cov-report=xml --cov=xyzspaces tests
- codecov
- pytest -v --durations=10 --cov-report=xml --cov=xyzspaces tests
- make draft_changelog
deploy:
provider: pypi
Expand All @@ -29,3 +28,5 @@ env:
- secure: K8I9mDTKeXHLgG/gdwamQ3D1S2I8aQjZfqlRJBwmk3nPhJMfSjgPAMJRp3GmWxxElg/3iF8LoDTrXXw3/l4zd7o6SAZG0fTN2J/9zAa6afi10H43GPiiESiNNfbYFTOk4S2C6+9HsjyjgrYxaMTMvs5euLfBM9Q0uMkgLUCMxbIxQ8yGxgCQHA7zogDkvybxiXw5Yxny8gl8L3hqmixKDZwRwbPgtsEL/Zf4nqQT6D3HRt1v2gdScg/1csLk/CVZ54cess2nspbfuyNW+3+q6twHkzO3XAGOg5gqkBTiXE4n7eIrQUOyTpesT4bw1ku8btAUcb85JcSe/xKCeUI81XaQtULCXr8xo2nefRHxWGYEXZ30vHotJpnTk7CdJPXF7q/gCf+NqaMDy+bCKu9dgqFqRXkBg8mUaSblrk99d4Ec9NdUoJoonXnWEAS3KC/Ijm8XA7/v1+xUVxedCD4v9K0bLS5oqHiRfkn7T7mRl5HuErL12EJCeKD5HT3OyPvu8L7yST7Jaik7Ieznyk1uJCg3UGjAdjbHNneoBmGlavKUEL0OuDyeAJKOZVWy7IXmv9bBKg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0xVK63UV/7zA+8Wk5wDY0Jfdbg8S6JorZGKjsMKz7shs5QwViI10kCihnfwh8fCZMwwUdIKwuRMrMTMEb2HWVm0W5Hhies+7khDO0MXvKJ7dSIWssA6/f6Fr46054OCnbW5laJVBkzt8CAnOBXvauQu7DzqNjNAA7fyvBBpWHhvlOL0WWyV+wmzwDcGoCfL6+fCVIDzMMpUwu7RS21bROLdak+/3RpnLKDNf6im9IZ72S0L2ya2ojtZwjENbtWMLh2eIW78MaLjl8BvKHKC5Yi8RL/WsHVXRkrvrCIoCTKLXLa4NOfS9p2sgy8jyUOQG5BHMNjfaBa8Ol4FHfatjFzwvfU+LwOliu/0Gcj4Lp37xUlRjp+asNYHoWX1tXXgM3CatS1yiMIDB4zYmdFD3bTBlu37n8=
after_success:
- codecov
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,4 @@ draft_changelog:
proclamation draft $(shell python -c "import xyzspaces; print(xyzspaces.__version__)")

build_changelog:
proclamation build -o $(shell python -c "import xyzspaces; print(xyzspaces.__version__)")
proclamation build -d -o $(shell python -c "import xyzspaces; print(xyzspaces.__version__)")
1 change: 0 additions & 1 deletion changes/features/pr.40.md

This file was deleted.

1 change: 0 additions & 1 deletion changes/features/pr.41.md

This file was deleted.

1 change: 0 additions & 1 deletion changes/features/pr.42.md

This file was deleted.

1 change: 0 additions & 1 deletion changes/features/pr.44.md

This file was deleted.

1 change: 1 addition & 0 deletions changes/features/pr.57.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added feature to upload data from `geobuff` file to the space.
1 change: 0 additions & 1 deletion changes/misc/pr.28.md

This file was deleted.

1 change: 0 additions & 1 deletion changes/misc/pr.36.md

This file was deleted.

1 change: 0 additions & 1 deletion changes/misc/pr.38.md

This file was deleted.

1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ geojson
requests
geopandas
turfpy>=0.0.3
geobuf
Binary file added tests/data/test.pbf
Binary file not shown.
14 changes: 5 additions & 9 deletions tests/hub/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,11 @@ def test_get_space_bbox(api, space_id):
assert len(bbox["features"]) == 0
assert bbox["type"] == "FeatureCollection"

with warnings.catch_warnings(record=True) as w:
# Cause all warnings to always be triggered.
warnings.simplefilter("always")
# Trigger a warning.
api.get_space_bbox(space_id=space_id, bbox=bb, params={"foo": "bar"})
# Verify some things
assert len(w) == 1
assert issubclass(w[-1].category, UserWarning)
assert str(w[-1].message).endswith("not supported, yet.")
resp = api.get_space_bbox(
space_id=space_id, bbox=bb, params={"p.name": "Ghana"}
)
assert len(resp["features"]) == 1
assert resp["type"] == "FeatureCollection"

bbox = api.get_space_bbox(space_id=space_id, bbox=bb, selection=["p.name"])
assert bbox["features"][0]["properties"]["name"] == "Benin"
Expand Down
12 changes: 11 additions & 1 deletion tests/space/test_space_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ def test_add_features_shapefile(empty_space):
"""Test uploading shapefile to the space."""
space = empty_space
shapefile = Path(__file__).parents[1] / "data" / "stations.zip"
space.add_features_shapefile(f"zip://{shapefile}")
space.add_features_shapefile(f"zip://{shapefile}", crs="EPSG:4326")
resp = space.search(params={"p.name": "Van Dorn Street"})
flist = list(resp)
assert flist[0]["geometry"]["coordinates"] == [
Expand Down Expand Up @@ -639,3 +639,13 @@ def test_add_features_kml(empty_space):
space.add_features_kml(kml_file, features_size=500)
stats = space.get_statistics()
assert stats["count"]["value"] == 243


@pytest.mark.skipif(not XYZ_TOKEN, reason="No token found.")
def test_add_features_geobuff(empty_space):
"""Test uploading geobuff file to the space."""
space = empty_space
geobuff_file = Path(__file__).parents[1] / "data" / "test.pbf"
space.add_features_geobuf(geobuff_file, features_size=500)
stats = space.get_statistics()
assert stats["count"]["value"] == 180
6 changes: 1 addition & 5 deletions xyzspaces/apis.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,11 +619,7 @@ def get_space_bbox(
if clustering:
q_params["clustering"] = clustering
if params:
warnings.warn(
f"The 'params' parameter for the `{path}` API endpoint "
"is not supported, yet."
)
# TODO
q_params.update(params)
if selection:
q_params["selection"] = ",".join(selection)
if clusteringParams:
Expand Down
44 changes: 40 additions & 4 deletions xyzspaces/spaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from typing import Any, Dict, Generator, List, Optional, Union

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

Expand Down Expand Up @@ -283,14 +284,15 @@ def search(
for f in features["features"]:
yield f

def iter_feature(self) -> Generator[Feature, None, None]:
def iter_feature(self, limit: int = 100) -> Generator[Feature, None, None]:
"""
Iterate over features in this space object.
:param limit: A max. number of features to return in the result.
:yields: A Feature object.
"""
for feature in self.api.get_space_iterate(
space_id=self._info["id"], limit=100
space_id=self._info["id"], limit=limit
):
yield feature

Expand Down Expand Up @@ -882,7 +884,12 @@ def isshared(self) -> bool:
return True if "shared" in self.info else False

def add_features_shapefile(
self, path: str, features_size: int = 2000, chunk_size: int = 1
self,
path: str,
features_size: int = 2000,
chunk_size: int = 1,
crs: str = None,
encoding: str = "utf-8",
):
"""Upload shapefile to the space.
Expand All @@ -892,14 +899,20 @@ def add_features_shapefile(
a time.
: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.
:param crs: A string to represent Coordinate Reference System(CRS),
If you want to change CRS, please pass the value of desired CRS
Example: ``epsg:4326``.
:param encoding: A string to represent the type of encoding.
Example:
>>> from xyzspaces import XYZ
>>> xyz = XYZ(credentials="XYZ_TOKEN")
>>> space = xyz.spaces.from_id(space_id="existing-space-id")
>>> space.add_features_shapefile(path="shapefile.shp")
"""
gdf = gpd.read_file(path)
gdf = gpd.read_file(path, encoding=encoding)
if crs is not None:
gdf = gdf.to_crs(crs)
with tempfile.NamedTemporaryFile() as temp:
gdf.to_file(temp.name, driver="GeoJSON")
self.add_features_geojson(
Expand Down Expand Up @@ -990,3 +1003,26 @@ def add_features_kml(
features_size=features_size,
chunk_size=chunk_size,
)

def add_features_geobuf(
self, path: str, features_size: int = 2000, chunk_size: int = 1
):
"""
To upload data from geobuff file to a space.
:param path: Path to geobuff file.
:param features_size: An int representing a number of features to upload at
a time.
: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.
"""

with open(path, "rb") as f:
geobuff_data = f.read()
geojson = geobuf.decode(geobuff_data)

self.add_features(
features=geojson,
features_size=features_size,
chunk_size=chunk_size,
)

0 comments on commit b7e2adc

Please sign in to comment.