Skip to content

Commit eb65271

Browse files
committed
Add tests and some documentation.
1 parent dcf5ee2 commit eb65271

File tree

5 files changed

+34
-3
lines changed

5 files changed

+34
-3
lines changed

setup.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@
1414
},
1515
install_requires=[
1616
"mapbox_vector_tile"
17-
]
17+
],
18+
test_suite="tests"
1819
)

tests/__init__.py

Whitespace-only changes.

tests/sample_14_8185_5449.pbf

5.85 KB
Binary file not shown.

tests/test_conversions.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import os
2+
from unittest import TestCase
3+
4+
from vt2geojson.tools import vt_bytes_to_geojson
5+
6+
DIRPATH = os.path.dirname(os.path.realpath(__file__))
7+
SAMPLE_FILEPATH = os.path.join(DIRPATH, "sample_14_8185_5449.pbf")
8+
9+
with open(SAMPLE_FILEPATH, "rb") as f:
10+
sample_content = f.read()
11+
12+
13+
class TestConversions(TestCase):
14+
def test_bytes_to_geojson(self):
15+
result = vt_bytes_to_geojson(sample_content, 8185, 5449, 14)
16+
assert result['features']

vt2geojson/tools.py

+16-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,25 @@
55
from vt2geojson.features import Layer
66

77

8-
def _is_url(uri):
8+
def _is_url(uri: str) -> bool:
9+
"""
10+
Checks if the uri is actually an url.
11+
:param uri: the string to check.
12+
:return: a boolean.
13+
"""
914
return urlparse(uri).scheme != ""
1015

1116

12-
def vt_bytes_to_geojson(b_content, x, y, z, layer=None):
17+
def vt_bytes_to_geojson(b_content: bytes, x: int, y: int, z: int, layer=None) -> dict:
18+
"""
19+
Make a GeoJSON from bytes in the vector tiles format.
20+
:param b_content: the bytes to convert.
21+
:param x: tile x coordinate.
22+
:param y: tile y coordinate.
23+
:param z: tile z coordinate.
24+
:param layer: include only the specified layer.
25+
:return: a features collection (GeoJSON).
26+
"""
1327
data = decode(b_content)
1428
features_collections = [Layer(x=x, y=y, z=z, name=name, obj=layer_obj).toGeoJSON()
1529
for name, layer_obj in data.items() if layer is None or name == layer]

0 commit comments

Comments
 (0)