异步cogeotiff读取器
aiocogeo的Python项目详细描述
航空地理![CircleCI](https://warehouse-camo.ingress.cmh1.psfhosted.org/48c83aea2fd80226cff6a0107aab5e7d93e07f46/68747470733a2f2f636972636c6563692e636f6d2f67682f67656f7370617469616c2d6a6566662f61696f636f67656f2f747265652f6d61737465722e7376673f7374796c653d737667)
![codecov](https://warehouse-camo.ingress.cmh1.psfhosted.org/5cd29c5f98b4420781692c4a5dc9c360f6d7661e/68747470733a2f2f636f6465636f762e696f2f67682f67656f7370617469616c2d6a6566662f61696f636f67656f2f6272616e63682f6d61737465722f67726170682f62616467652e737667)
安装
pip install aiocogeo
# With S3 filesystem
pip install aiocogeo[s3]
使用
{cd1>使用异步上下文管理器^打开:
^{pr2}$支持多种文件系统:
- HTTP/HTTPS(
http://
,https://
) - S3(
s3://
) - File(
/
)
元数据
为COG生成rasterio-style profile:
asyncwithCOGReader("https://async-cog-reader-test-data.s3.amazonaws.com/lzw_cog.tif")ascog:print(cog.profile)>>>{'driver':'GTiff','width':10280,'height':12190,'count':3,'dtype':'uint8','transform':Affine(0.6,0.0,367188.0,0.0,-0.6,3777102.0),'blockxsize':512,'blockysize':512,'compress':'lzw','interleave':'pixel','crs':'EPSG:26911','tiled':True,'photometric':'rgb'}
低级元数据
COG由多个IFD组成,每个IFD都有许多TIFF标记:
fromaiocogeo.ifdimportIFDfromaiocogeo.tagimportTagasyncwithCOGReader("https://async-cog-reader-test-data.s3.amazonaws.com/lzw_cog.tif")ascog:forifdincog:assertisinstance(ifd,IFD)fortaginifd:assertisinstance(tag,Tag)
每个IFD包含的关于映像的粒度元数据比概要文件中包含的元数据更多。例如,查找 每个IFD的瓷砖大小:
asyncwithCOGReader("https://async-cog-reader-test-data.s3.amazonaws.com/lzw_cog.tif")ascog:forifdincog:print(ifd.TileWidth.value,ifd.TileHeight.value)>>>512512128128128128128128128128128128
更高级的用例可能需要访问标记级别的元数据:
asyncwithCOGReader("https://async-cog-reader-test-data.s3.amazonaws.com/lzw_cog.tif")ascog:first_ifd=cog.ifds[0]assertfirst_ifd.tag_count==24fortaginfirst_ifd:print(tag)>>>Tag(code=258,name='BitsPerSample',tag_type=TagType(format='H',size=2),count=3,length=6,value=(8,8,8))Tag(code=259,name='Compression',tag_type=TagType(format='H',size=2),count=1,length=2,value=5)Tag(code=257,name='ImageHeight',tag_type=TagType(format='H',size=2),count=1,length=2,value=12190)Tag(code=256,name='ImageWidth',tag_type=TagType(format='H',size=2),count=1,length=2,value=10280)...
图像数据
读取器还具有读取内部图像块和执行部分读取的方法。目前只支持jpeg、lzw、deflate、packbits和webp压缩。在
图像平铺
以本机分辨率读取图像左上角的平铺图:
asyncwithCOGReader("https://async-cog-reader-test-data.s3.amazonaws.com/webp_cog.tif")ascog:x=y=z=0tile=awaitcog.get_tile(x,y,z)ifd=cog.ifds[z]asserttile.shape==(ifd.bands,ifd.TileHeight.value,ifd.TileWidth.value)
在
部分读取
您可以通过在图像的本机crs中指定边界框和输出形状来读取图像的一部分:
asyncwithCOGReader("https://async-cog-reader-test-data.s3.amazonaws.com/webp_cog.tif")ascog:assertcog.epsg==26911partial_data=awaitcog.read(bounds=(368461,3770591,368796,3770921),shape=(512,512))
在
内部掩码
如果COG有一个内部掩码,则返回的数组将是一个掩码数组:
importnumpyasnpasyncwithCOGReader("https://async-cog-reader-test-data.s3.amazonaws.com/naip_image_masked.tif")ascog:assertcog.is_maskedtile=awaitcog.get_tile(0,0,0)assertnp.ma.is_masked(tile)
在
配置
配置选项通过环境变量公开:
- incented_BYTES_AT_OPEN定义文件打开时第一个GET请求中的字节数(默认为16KB)
- HEADER_CHUNK_SIZE-用于读取头的块大小(默认为16KB)
- ENABLE_BLOCK_CACHE确定是否在内存中缓存图像块(默认为TRUE)
- ENABLE_HEADER_CACHE-确定COG头是否缓存在内存中(默认为TRUE)
- HTTP_MERGE_continuous_RANGES确定是否将连续范围合并到单个请求中(默认为FALSE)
- BOUNDLESS_READ确定是否读取IFD边界之外的内部分片(默认为TRUE)
- BOUNDLESS_READ_FILL_VALUE确定用于填充无边界读取的值(默认为0)
- LOG_LEVEL确定包使用的日志级别(默认为ERROR)
- VERBOSE_LOGS—启用详细日志记录,设计用于
LOG_LEVEL=DEBUG
(默认为FALSE)时使用 - AWS\u REQUEST_PAYER-设置为
requester
以启用从S3 RequesterPays存储桶读取。在
有关配置选项的详细信息,请参阅^{
命令行接口
$ aiocogeo --help
Usage: aiocogeo [OPTIONS] COMMAND [ARGS]...
Options:
--install-completion [bash|zsh|fish|powershell|pwsh]
Install completion for the specified shell.
--show-completion [bash|zsh|fish|powershell|pwsh]
Show completion for the specified shell, to
copy it or customize the installation.
--help Show this message and exit.
Commands:
create-tms Create OGC TileMatrixSet.
info Read COG metadata.
- 项目
标签: