Package: rio-tiler-crs
rio-tiler-crsA rio-tiler plugin to create tiles in different projectionInstall$pipinstallpip-U
$pipinstallrio-tiler-crs# Or using source$pipinstallgit+http://github.com/cogeotiff/rio-tiler-crsHow Torio-tiler-crs usesmorecantileto define the custom tiling grid schema.Define grid systemimportmorecantilefromrasterio.crsimportCRS# Use default TMStms=morecantile.tms.get("WorldCRS84Quad")# or create a custom TMScrs=CRS.from_epsg(3031)# Morecantile TileMatrixSet uses Rasterio CRS objectextent=[-948.75,-543592.47,5817.41,-3333128.95]# From https:///epsg.io/3031tms=morecantile.TileMatrixSet.custom(extent,crs)read tilefromrio_tiler_crsimportCOGReader# Read tile x=10, y=10, z=4withCOGReader("myfile.tif",tms=tms)ascog:tile,mask=cog.tile(10,10,4)APIclassCOGReader:"""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: strCloud Optimized GeoTIFF path.dataset: rasterio.DatasetReader, optionalRasterio dataset.tms: morecantile.TileMatrixSet, optionalTileMatrixSet to use, default is WebMercatorQuad.Properties----------minzoom: intCOG minimum zoom level in TMS projection.maxzoom: intCOG maximum zoom level in TMS projection.bounds: tuple[float]COG bounds in WGS84 crs.center: tuple[float, float, int]COG center + minzoomcolormap: dictCOG internal colormap.info: dictGeneral 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(): Read map tile from a rastertms=morecantile.tms.get("WorldCRS84Quad")withCOGReader("myfile.tif",tms=tms)ascog:tile,mask=cog.tile(1,2,3,tilesize=256)# With indexeswithCOGReader("myfile.tif",tms=tms)ascog:tile,mask=cog.tile(1,2,3,tilesize=256,indexes=1)# With expressionwithCOGReader("myfile.tif",tms=tms)ascog:tile,mask=cog.tile(1,2,3,tilesize=256,expression="B1/B2")COGReader.part(): Read part of a rasterNote:tmshas no effect onpartread.tms=morecantile.tms.get("WorldCRS84Quad")withCOGReader("myfile.tif",tms=tms)ascog:data,mask=cog.part((10,10,20,20))# Limit output size (default is set to 1024)withCOGReader("myfile.tif",tms=tms)ascog:data,mask=cog.part((10,10,20,20),max_size=2000)# Read high resolutionwithCOGReader("myfile.tif",tms=tms)ascog:data,mask=cog.part((10,10,20,20),max_size=None)# With indexeswithCOGReader("myfile.tif",tms=tms)ascog:data,mask=cog.part((10,10,20,20),indexes=1)# With expressionwithCOGReader("myfile.tif",tms=tms)ascog:data,mask=cog.part((10,10,20,20),expression="B1/B2")COGReader.preview(): Read a preview of a rasterNote:tmshas no effect onpartread.withCOGReader("myfile.tif")ascog:data,mask=cog.preview()# With indexeswithCOGReader("myfile.tif")ascog:data,mask=cog.preview(indexes=1)# With expressionwithCOGReader("myfile.tif")ascog:data,mask=cog.preview(expression="B1+2,B1*4")COGReader.point(): Read point value of a rasterNote:tmshas no effect onpartread.withCOGReader("myfile.tif")ascog:print(cog.point(-100,25))# With indexeswithCOGReader("myfile.tif")ascog:print(cog.point(-100,25,indexes=1))[1]# With expressionwithCOGReader("myfile.tif")ascog:print(cog.point(-100,25,expression="B1+2,B1*4"))[3,4]COGReader.info: Return simple metadata about the rasterwithCOGReader("myfile.tif")ascog: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(): Return image statistics (Min/Max/Stdev)withCOGReader("myfile.tif")ascog:print(cog.stats()){"1":{"pc":[1,16],"min":1,"max":18,"std":4.069636227214257,"histogram":[[...],[...]]}}COGReader.metadata(): Return COG info + statisticswithCOGReader("myfile.tif")ascog: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":[[...],[...]]}}}ExampleSee/demoContribution & DevelopmentIssues and pull requests are more than welcome.dev install$gitclonehttps://github.com/cogeotiff/rio-tiler-crs.git
$cdrio-tiler-crs
$pipinstall-e.[dev]Python >=3.7 onlyThis repo is set to usepre-committo runisort,flake8,pydocstring,black("uncompromising Python code formatter") and mypy when committing new code.$ 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