Skip to content

Commit a69c7a5

Browse files
committed
fix coordinates
1 parent 564d205 commit a69c7a5

File tree

5 files changed

+32
-23
lines changed

5 files changed

+32
-23
lines changed

.pre-commit-config.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/psf/black
3-
rev: 19.10b0
3+
rev: 22.3.0
44
hooks:
55
- id: black
66
language_version: python
@@ -18,7 +18,7 @@ repos:
1818
language_version: python
1919

2020
- repo: https://github.com/PyCQA/pydocstyle
21-
rev: 5.1.1
21+
rev: 6.1.1
2222
hooks:
2323
- id: pydocstyle
2424
language_version: python

CHANGES.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.0.1dev3 (2022-08-08)
2+
3+
* Fix polygon and point coordinates in `pixels_encoder`
4+
15
## 0.0.1dev2 (2021-04-06)
26

37
* update tests for new vector-tile-base version

README.md

+8-4
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ More on [COG Talk](https://medium.com/devseed/search?q=cog%20talk) blog posts
2828

2929
### Requirements
3030

31-
rio-tiler-mvt use [python-vtzero](https://github.com/tilery/python-vtzero) wrapper to encode point and polygons to MVT. Because VTZERO is a C++ library, python-vtzero is written in Cython, thus cython~=0.28 is required to compile this library.
31+
rio-tiler-mvt use [python-vtzero](https://github.com/tilery/python-vtzero) wrapper to encode point and polygons to MVT. Because VTZERO is a C++ library, python-vtzero is written in Cython, thus cython is required to compile this library.
3232

3333
```bash
34-
$ pip install cython~=0.28 # see https://github.com/tilery/python-vtzero#requirements
34+
$ pip install cython # see https://github.com/tilery/python-vtzero#requirements
3535

3636
$ pip install rio-tiler-mvt
3737
```
@@ -110,12 +110,16 @@ $ cd rio-tiler-mvt
110110
$ pip install -e .[dev]
111111
```
112112

113-
**Python3.7 only**
113+
**pre-commit**
114114

115115
This repo is set to use `pre-commit` to run *isort*, *flake8*, *pydocstring*, *black* ("uncompromising Python code formatter") and mypy when committing new code.
116116

117117
```bash
118118
$ pre-commit install
119119
```
120120

121-
[satellite-3d](https://github.com/developmentseed/satellite-3d.git)
121+
## Links
122+
123+
- **satellite-3d**: https://github.com/developmentseed/satellite-3d.git
124+
- **titiler-mvt**: https://github.com/developmentseed/titiler-mvt.git
125+
- **rio-viz**: https://github.com/developmentseed/rio-viz.git

rio_tiler_mvt/mvt.pyx

+16-15
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ cpdef bytes pixels_encoder(
2020
str layer_name = "my_layer",
2121
str feature_type = "point",
2222
):
23-
cdef int sc = 4096 // data.shape[1]
24-
cdef tuple indexes = numpy.where(mask)
23+
cdef int sc = 4096 // data.shape[1] # cell resolution
24+
cdef tuple indexes = numpy.where(mask) # Index of non-masked data
2525

26-
cdef tuple idx
27-
cdef int x, y
26+
cdef tuple
27+
cdef int x, y, x_coord, y_coord
2828

2929
if not band_names:
3030
band_names = [
@@ -33,31 +33,32 @@ cpdef bytes pixels_encoder(
3333

3434
mvt = Tile()
3535
mvt_layer = Layer(mvt, layer_name.encode())
36-
for idx in zip(indexes[1], indexes[0]):
37-
x, y = idx
38-
x *= sc
39-
y *= sc
36+
for (y, x) in zip(indexes[0], indexes[1]):
37+
x_coord = sc * x
38+
y_coord = sc * y
4039

4140
if feature_type == 'point':
4241
feature = Point(mvt_layer)
43-
feature.add_point(x + sc / 2, y - sc / 2)
42+
# Point is at the center of the pixel
43+
feature.add_point(x_coord + sc // 2, y_coord + sc // 2)
4444

4545
elif feature_type == 'polygon':
4646
feature = Polygon(mvt_layer)
4747
feature.add_ring(5)
48-
feature.set_point(x, y)
49-
feature.set_point(x + sc, y)
50-
feature.set_point(x + sc, y - sc)
51-
feature.set_point(x, y - sc)
52-
feature.set_point(x, y)
48+
feature.set_point(x_coord, y_coord)
49+
feature.set_point(x_coord + sc, y_coord)
50+
feature.set_point(x_coord + sc, y_coord + sc)
51+
feature.set_point(x_coord, y_coord + sc)
52+
feature.set_point(x_coord, y_coord)
53+
5354
else:
5455
raise Exception(f"Invalid geometry type: {feature_type}")
5556

5657
# TODO: fix https://github.com/tilery/python-vtzero/issues/3
5758
for bidx in range(data.shape[0]):
5859
feature.add_property(
5960
band_names[bidx].encode(),
60-
str(data[bidx, idx[1], idx[0]]).encode()
61+
str(data[bidx, y, x]).encode()
6162
)
6263
feature.commit()
6364

setup.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
setup(
2525
name="rio-tiler-mvt",
2626
version="0.0.1dev2",
27-
description=u"""A rio-tiler plugin to encode tile array to MVT""",
27+
description="""A rio-tiler plugin to encode tile array to MVT""",
2828
long_description=long_description,
2929
long_description_content_type="text/markdown",
3030
python_requires=">=3",
@@ -39,7 +39,7 @@
3939
"Topic :: Scientific/Engineering :: GIS",
4040
],
4141
keywords="COG MVT mapbox vectortile GIS",
42-
author=u"Vincent Sarago",
42+
author="Vincent Sarago",
4343
author_email="[email protected]",
4444
url="https://github.com/cogeotiff/rio-tiler-mvt",
4545
license="MIT",

0 commit comments

Comments
 (0)