Skip to content

Commit

Permalink
Merge pull request #2 from cogeotiff/shapesEncoder
Browse files Browse the repository at this point in the history
encode shapes
  • Loading branch information
vincentsarago authored Jan 21, 2021
2 parents 7e9eda6 + d397205 commit 0b8d171
Show file tree
Hide file tree
Showing 15 changed files with 407 additions and 194 deletions.
85 changes: 0 additions & 85 deletions .circleci/config.yml

This file was deleted.

80 changes: 80 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: CI

# On every pull request, but only on push to master
on:
push:
branches:
- master
tags:
- '*'
pull_request:

jobs:
tests:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6, 3.7, 3.8]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install tox codecov pre-commit
# Run tox using the version of Python in `PATH`
- name: Run Tox
run: tox -e py

# Run pre-commit (only for python-3.7)
- name: run pre-commit
if: matrix.python-version == 3.7
run: pre-commit run --all-files

- name: Upload Results
if: success()
uses: codecov/codecov-action@v1
with:
file: ./coverage.xml
flags: unittests
name: ${{ matrix.platform }}-${{ matrix.tox-env }}
fail_ci_if_error: false

publish:
needs: [tests]
runs-on: ubuntu-latest
if: startsWith(github.event.ref, 'refs/tags') || github.event_name == 'release'
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: "3.x"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install tox
- name: Set tag version
id: tag
# https://stackoverflow.com/questions/58177786/get-the-current-pushed-tag-in-github-actions
run: echo ::set-output name=tag::${GITHUB_REF#refs/*/}

- name: Set module version
id: module
# https://stackoverflow.com/questions/58177786/get-the-current-pushed-tag-in-github-actions
run: echo ::set-output name=version::$(python setup.py --version)

- name: Build and publish
if: steps.tag.outputs.tag == steps.module.outputs.version
env:
TOXENV: release
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: tox
76 changes: 43 additions & 33 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,34 +1,44 @@

repos:
-
repo: 'https://github.com/ambv/black'
# 18.6b1
rev: ed50737290662f6ef4016a7ea44da78ee1eff1e2
hooks:
- id: black
args: ['--safe']
language_version: python3.6
-
repo: 'https://github.com/pre-commit/pre-commit-hooks'
# v1.3.0
rev: a6209d8d4f97a09b61855ea3f1fb250f55147b8b
hooks:
- id: flake8
language_version: python3.6
args: [
# E501 let black handle all line length decisions
# W503 black conflicts with "line break before operator" rule
# E203 black conflicts with "whitespace before ':'" rule
'--ignore=E501,W503,E203']
-
repo: 'https://github.com/chewse/pre-commit-mirrors-pydocstyle'
# 2.1.1
rev: 22d3ccf6cf91ffce3b16caa946c155778f0cb20f
hooks:
- id: pydocstyle
language_version: python3.6
args: [
# Check for docstring presence only
'--select=D1',
# Don't require docstrings for tests
'--match=(?!test).*\.py']
- repo: https://github.com/psf/black
rev: 19.10b0
hooks:
- id: black
language_version: python3.7
args: ["--safe"]

- repo: https://github.com/PyCQA/isort
rev: 5.4.2
hooks:
- id: isort
language_version: python3.7

- repo: https://github.com/PyCQA/flake8
rev: 3.8.3
hooks:
- id: flake8
language_version: python3.7
args: [
# E501 let black handle all line length decisions
# W503 black conflicts with "line break before operator" rule
# E203 black conflicts with "whitespace before ':'" rule
"--ignore=E501,W503,E203",
]

- repo: https://github.com/PyCQA/pydocstyle
rev: 5.1.1
hooks:
- id: pydocstyle
language_version: python3.7
args: [
# Check for docstring presence only
"--select=D1",
# Don't require docstrings for tests
'--match=(?!test).*\.py',
]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.770
hooks:
- id: mypy
language_version: python3.7
args: ["--no-strict-optional", "--ignore-missing-imports"]
16 changes: 16 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## Next (TBD)

* update tests for new vector-tile-base version
* add `shapes` encoding (add shapely and rasterio in requirements).

**breaking changes**

* renamed `mvt.encoder` to `mvt.pixels_encoder`

## 0.0.1dev1 (2019-06-25)

* Fix missing files in package

## 0.0.1dev0 (2019-06-24)

* Initial release.
11 changes: 0 additions & 11 deletions CHANGES.txt

This file was deleted.

90 changes: 69 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
# rio-tiler-mvt

[![Packaging status](https://badge.fury.io/py/rio-tiler-mvt.svg)](https://badge.fury.io/py/rio-tiler-mvt)
[![CircleCI](https://circleci.com/gh/cogeotiff/rio-tiler-mvt.svg?style=svg)](https://codecov.io/gh/cogeotiff/rio-tiler-mvt)
[![codecov](https://codecov.io/gh/cogeotiff/rio-tiler-mvt/branch/master/graph/badge.svg)](https://circleci.com/gh/cogeotiff/rio-tiler-mvt)
<p align="center">
<img src="https://user-images.githubusercontent.com/10407788/57476379-72cf6000-7264-11e9-979d-bf9f486518c2.png" style="max-width: 800px;" alt="rio-tiler"></a>
</p>
<p align="center">
<em>A rio-tiler plugin to translate tile array to MVT (using python-vtzero).</em>
</p>
<p align="center">
<a href="https://github.com/cogeotiff/rio-tiler-mvt/actions?query=workflow%3ACI" target="_blank">
<img src="https://github.com/cogeotiff/rio-tiler-mvt/workflows/CI/badge.svg" alt="Test">
</a>
<a href="https://codecov.io/gh/cogeotiff/rio-tiler-mvt" target="_blank">
<img src="https://codecov.io/gh/cogeotiff/rio-tiler-mvt/branch/master/graph/badge.svg" alt="Coverage">
</a>
<a href="https://pypi.org/project/rio-tiler-mvt" target="_blank">
<img src="https://img.shields.io/pypi/v/rio-tiler-mvt?color=%2334D058&label=pypi%20package" alt="Package version">
</a>
<a href="https://github.com/cogeotiff/rio-tiler-mvt/blob/master/LICENSE" target="_blank">
<img src="https://img.shields.io/github/license/cogeotiff/rio-tiler-mvt.svg" alt="Downloads">
</a>
</p>


A rio-tiler plugin to translate tile array to MVT (using python-vtzero)

![](https://user-images.githubusercontent.com/10407788/57476379-72cf6000-7264-11e9-979d-bf9f486518c2.png)

More on [COG Talk](https://medium.com/devseed/search?q=cog%20talk) blog posts

## Install
Expand All @@ -22,7 +35,7 @@ $ pip install cython~=0.28 # see https://github.com/tilery/python-vtzero#require

$ pip install rio-tiler-mvt
```
Or
Or
```bash
$ git clone http://github.com/cogeotiff/rio-tiler-mvt
$ cd rio-tiler-mvt
Expand All @@ -33,14 +46,53 @@ $ pip install -e .

### API

`mvt.encoder(data, mask, band_names=[], layer_name="my_layer", feature_type="point")`
#### **pixel_encoder**

pixels_encoder(
data: numpy.ndarray,
mask: numpy.ndarray,
band_names: list = [],
layer_name: str = "my_layer",
feature_type: str = "point"
)

Inputs:
- data: raster tile data to encode
- mask: mask data
- band_names: Raster band's names
- layer_name: Layer name
- feature_type: Feature type (point or polygon)

Returns:
- mvt : Mapbox Vector Tile encoded data.

Examples:

```python
from rio_tiler.io import COGReader
from rio_tiler_mvt import pixels_encoder

with COGReader("fixtures/test.tif") as cog
img = cog.tile(72, 63, 7, resampling_method="nearest")
mvt = pixels_encoder(img.data, img.mask, layer_name="test", feature_type="point")
```

#### **shapes_encoder**

shapes_encoder(
data: numpy.ndarray, # 1D array (height, width)
mask: numpy.ndarray,
layer_name: str = "my_layer",
colormap: dict = {},
class_names: dict = {}
)

Inputs:
- data : raster tile data to encode
- mask : mask data
- band_names : Raster band's names
- layer_name : Layer name
- feature_type : Feature type (point or polygon)
- data: raster tile data to encode
- mask: mask data
- layer_name: Layer name
- colormap: GDAL colormap. If provided a `color` value will be added to the feature properties
- class_names: Dictionary mapping pixel value with class names. If provided a `name` value will be added to the feature properties.

Returns:
- mvt : Mapbox Vector Tile encoded data.
Expand All @@ -58,16 +110,12 @@ $ cd rio-tiler-mvt
$ pip install -e .[dev]
```

**Python3.6 only**
**Python3.7 only**

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

```bash
$ pre-commit install
```


## Implementations
[cogeo-mosaic](http://github.com/developmentseed/cogeo-mosaic.git)

[satellite-3d](http://github.com/developmentseed/satellite-3d.git)
[satellite-3d](http://github.com/developmentseed/satellite-3d.git)
Loading

0 comments on commit 0b8d171

Please sign in to comment.