Custom map grid utilities
Project description
Morecantile
Construct and use map tile grids in different projection.
The name is an homage to mercantile, a great tools to work with Web Mercator tile indexes. This module aims to mimic mercatile
features but for other projections.
Install
$ pip install -U pip
$ pip install morecantile
# Or install from source:
$ pip install git+https://github.com/developmentseed/morecantile.git
How To
+-------------+-------------+ ymax
| | |
| x: 0 | x: 1 |
| y: 0 | y: 0 |
| z: 1 | z: 1 |
| | |
+-------------+-------------+
| | |
| x: 0 | x: 1 |
| y: 1 | y: 1 |
| z: 1 | z: 1 |
| | |
+-------------+-------------+ ymin
xmin xmax
Define custom grid
import morecantile
from rasterio.crs import CRS
epsg = 3031
extent = [-948.75, -543592.47, 5817.41, -3333128.95] # From https:///epsg.io/3031
ts = morecantile.TileSchema(CRS.from_epsg(epsg), extent)
# Or
# epsg:3031 is one of the default grids available in morecantile
# see https://github.com/developmentseed/morecantile/blob/master/__init__.py#L94-L99
crs, args = morecantile.default_grids.get(3031)
ts = morecantile.TileSchema(crs, **args)
Create tile and get bounds
# Get the bounds for tile Z=4, X=10, Y=10 in the input projection
ts.xy_bounds(morecantile.Tile(10, 10, 4))
>> CoordsBbox(xmin=1742511.5500000003, ymin=-5250935.28, xmax=1916857.5800000003, ymax=-5076589.25)
# Get the bounds for tile Z=4, X=10, Y=10 in LatLon (WGS84)
ts.bounds(morecantile.Tile(10, 10, 4))
>> CoordsBbox(xmin=161.0554963794693, ymin=-41.54639259511877, xmax=159.94535469608172, ymax=-43.27127363762563)
Find tile for lat/lon
ts.tile(159.31, -42, 4)
>> Tile(x=11, y=10, z=4)
# Or using coordinates in input CRS
x, y = ts.point_fromwgs84(159.31, -42)
ts._tile(x, y, z)
>> Tile(x=11, y=10, z=4)
Get Geojson Feature
ts.feature(morecantile.Tile(10, 10, 4))
>> {
'type': 'Feature',
'bbox': [
159.94535469608172,
-43.27127363762563,
161.0554963794693,
-41.54639259511877
],
'id': 'Tile(x=10, y=10, z=4)',
'geometry': {
'type': 'Polygon',
'coordinates': [[
[161.0554963794693, -41.54639259511877],
[161.0554963794693, -43.27127363762563],
[159.94535469608172, -43.27127363762563],
[159.94535469608172, -41.54639259511877],
[161.0554963794693, -41.54639259511877]
]]
},
'properties': {
'title': 'XYZ tile Tile(x=10, y=10, z=4)',
'grid_crs': 'EPSG:3031'
}
}
Contribution & Development
Issues and pull requests are more than welcome.
dev install
$ git clone https://github.com/developmentseed/morecantile.git
$ cd rio-cogeo
$ pip install -e .[dev]
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.
$ pre-commit install
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
morecantile-0.0.1.tar.gz
(6.1 kB
view details)
File details
Details for the file morecantile-0.0.1.tar.gz
.
File metadata
- Download URL: morecantile-0.0.1.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.7.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d0154abe6af7b238cf2ab0ceb393a7cba6d83802a4ce89fd3472d59b894c8d41 |
|
MD5 | d2224f9c4e8d24bf9d82e8c568f8cb6f |
|
BLAKE2b-256 | 8a54c5c915394aa1e5d33b25eb6861ca260ad46f0f059e3965bd0d41b8ed5aa7 |