用于创建任意网格瓦片的rio-tiler插件
项目描述
rio-tiler-crs
一个用于在不同投影中创建瓦片的rio-tiler插件
安装
$ pip install pip -U
$ pip install rio-tiler-crs
# Or using source
$ pip install git+http://github.com/cogeotiff/rio-tiler-crs
如何使用
rio-tiler-crs使用morecantile来定义自定义瓦片网格模式。
- 定义网格系统
import morecantile
from rasterio.crs import CRS
# Use default TMS
tms = morecantile.tms.get("WorldCRS84Quad")
# or create a custom TMS
crs = CRS.from_epsg(3031) # Morecantile TileMatrixSet uses Rasterio CRS object
extent = [-948.75, -543592.47, 5817.41, -3333128.95] # From https:///epsg.io/3031
tms = morecantile.TileMatrixSet.custom(extent, crs)
- 读取瓦片
from rio_tiler_crs import COGReader
# Read tile x=10, y=10, z=4
with COGReader("myfile.tif", tms=tms) as cog:
tile, mask = cog.tile( 10, 10, 4)
API
class COGReader:
"""
Cloud Optimized GeoTIFF Reader.
Examples
--------
with CogeoReader(src_path) as cog:
cog.tile(...)
with rasterio.open(src_path) as src_dst:
with WarpedVRT(src_dst, ...) as vrt_dst:
with CogeoReader(None, dataset=vrt_dst) as cog:
cog.tile(...)
with rasterio.open(src_path) as src_dst:
with CogeoReader(None, dataset=src_dst) as cog:
cog.tile(...)
Attributes
----------
filepath: str
Cloud Optimized GeoTIFF path.
dataset: rasterio.DatasetReader, optional
Rasterio dataset.
tms: morecantile.TileMatrixSet, optional
TileMatrixSet to use, default is WebMercatorQuad.
Properties
----------
minzoom: int
COG minimum zoom level in TMS projection.
maxzoom: int
COG maximum zoom level in TMS projection.
bounds: tuple[float]
COG bounds in WGS84 crs.
center: tuple[float, float, int]
COG center + minzoom
colormap: dict
COG internal colormap.
info: dict
General information about the COG (datatype, indexes, ...)
Methods
-------
tile(0, 0, 0, indexes=(1,2,3), expression="
B1/B2", tilesize=512, resampling_methods="nearest")
Read a map tile from the COG.
part((0,10,0,10), indexes=(1,2,3,), expression="
B1/B20", max_size=1024)
Read part of the COG.
preview(max_size=1024)
Read preview of the COG.
point((10, 10), indexes=1)
Read a point value from the COG.
stats(pmin=5, pmax=95)
Get Raster statistics.
meta(pmin=5, pmax=95)
Get info + raster statistics
"""
- COGReader.tile():从栅格中读取地图瓦片
tms = morecantile.tms.get("WorldCRS84Quad")
with COGReader("myfile.tif", tms=tms) as cog:
tile, mask = cog.tile(1, 2, 3, tilesize=256)
# With indexes
with COGReader("myfile.tif", tms=tms) as cog:
tile, mask = cog.tile(1, 2, 3, tilesize=256, indexes=1)
# With expression
with COGReader("myfile.tif", tms=tms) as cog:
tile, mask = cog.tile(1, 2, 3, tilesize=256, expression="B1/B2")
- COGReader.part():读取栅格的一部分
注意:tms
对part
读取没有影响。
tms = morecantile.tms.get("WorldCRS84Quad")
with COGReader("myfile.tif", tms=tms) as cog:
data, mask = cog.part((10, 10, 20, 20))
# Limit output size (default is set to 1024)
with COGReader("myfile.tif", tms=tms) as cog:
data, mask = cog.part((10, 10, 20, 20), max_size=2000)
# Read high resolution
with COGReader("myfile.tif", tms=tms) as cog:
data, mask = cog.part((10, 10, 20, 20), max_size=None)
# With indexes
with COGReader("myfile.tif", tms=tms) as cog:
data, mask = cog.part((10, 10, 20, 20), indexes=1)
# With expression
with COGReader("myfile.tif", tms=tms) as cog:
data, mask = cog.part((10, 10, 20, 20), expression="B1/B2")
- COGReader.preview():读取栅格的预览
注意:tms
对part
读取没有影响。
with COGReader("myfile.tif") as cog:
data, mask = cog.preview()
# With indexes
with COGReader("myfile.tif") as cog:
data, mask = cog.preview(indexes=1)
# With expression
with COGReader("myfile.tif") as cog:
data, mask = cog.preview(expression="B1+2,B1*4")
- COGReader.point():读取栅格的点值
注意:tms
对part
读取没有影响。
with COGReader("myfile.tif") as cog:
print(cog.point(-100, 25))
# With indexes
with COGReader("myfile.tif") as cog:
print(cog.point(-100, 25, indexes=1))
[1]
# With expression
with COGReader("myfile.tif") as cog:
print(cog.point(-100, 25, expression="B1+2,B1*4"))
[3, 4]
- COGReader.info:返回关于栅格的简单元数据
with COGReader("myfile.tif") as cog:
print(cog.info)
{
"bounds": [-119.05915661478785, 13.102845359730287, -84.91821332299578, 33.995073647795806],
"center": [-101.98868496889182, 23.548959503763047, 3],
"minzoom": 3,
"maxzoom": 12,
"band_metadata": [[1, {}]],
"band_descriptions": [[1,"band1"]],
"dtype": "int8",
"colorinterp": ["palette"],
"nodata_type": "Nodata",
"colormap": {
"0": [0, 0, 0, 0],
"1": [0, 61, 0, 255],
...
}
}
- COGReader.stats():返回图像统计数据(最小值/最大值/标准差)
with COGReader("myfile.tif") as cog:
print(cog.stats())
{
"1": {
"pc": [1, 16],
"min": 1,
"max": 18,
"std": 4.069636227214257,
"histogram": [
[...],
[...]
]
}
}
- COGReader.metadata():返回COG信息和统计数据
with COGReader("myfile.tif") as cog:
print(cog.metadata())
{
"bounds": [-119.05915661478785, 13.102845359730287, -84.91821332299578, 33.995073647795806],
"center": [-101.98868496889182, 23.548959503763047, 3],
"minzoom": 3,
"maxzoom": 12,
"band_metadata": [[1, {}]],
"band_descriptions": [[1,"band1"]],
"dtype": "int8",
"colorinterp": ["palette"],
"nodata_type": "Nodata",
"colormap": {
"0": [0, 0, 0, 0],
"1": [0, 61, 0, 255],
...
}
"statistics" : {
1: {
"pc": [1, 16],
"min": 1,
"max": 18,
"std": 4.069636227214257,
"histogram": [
[...],
[...]
]
}
}
}
示例
贡献与发展
欢迎提交问题和拉取请求。
dev安装
$ git clone https://github.com/cogeotiff/rio-tiler-crs.git
$ cd rio-tiler-crs
$ pip install -e .[dev]
仅Python >=3.7
此仓库设置为在提交新代码时使用pre-commit
来运行isort、flake8、pydocstring、black(“不妥协的Python代码格式化器”)和mypy。
$ pre-commit install
$ git add .
$ git commit -m'my change'
isort....................................................................Passed
black....................................................................Passed
Flake8...................................................................Passed
Verifying PEP257 Compliance..............................................Passed
mypy.....................................................................Passed
$ git push origin
项目详情
关闭
rio-tiler-crs-2.0.2.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 3a6a8e16200c2382a2e465e03905c56abe79cb30d4ceb7b0e183ffdc8033a3c8 |
|
MD5 | 4a1e1d21862e1f6f7b662e6afce15252 |
|
BLAKE2b-256 | c7dadc4f51a8a4f148955e971789d6107ca86991a716f56dec84c4d8f4f41b39 |