用于Numpy和Scipy的快速直接光栅I/O

geoai-rasterio的Python项目详细描述


示例

下面是Rasterio提供的一些基本功能的示例。三带 从图像中读取并取平均值以产生类似全色的东西 乐队。然后,这个新乐队将被写入一个新的单一乐队tiff。

importnumpyasnpimportrasterio# Read raster bands directly to Numpy arrays.#withrasterio.open('tests/data/RGB.byte.tif')assrc:r,g,b=src.read()# Combine arrays in place. Expecting that the sum will# temporarily exceed the 8-bit integer range, initialize it as# a 64-bit float (the numpy default) array. Adding other# arrays to it in-place converts those arrays "up" and# preserves the type of the total array.total=np.zeros(r.shape)forbandinr,g,b:total+=bandtotal/=3# Write the product as a raster band to a new 8-bit file. For# the new file's profile, we start with the meta attributes of# the source file, but then change the band count to 1, set the# dtype to uint8, and specify LZW compression.profile=src.profileprofile.update(dtype=rasterio.uint8,count=1,compress='lzw')withrasterio.open('example-total.tif','w',**profile)asdst:dst.write(total.astype(rasterio.uint8),1)

输出:

http://farm6.staticflickr.com/5501/1139305054644/u 74f44444484d9/u z-d.jpg

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
JavaSpring重定向请求处理程序   SwingJava:拆分字符串并将其放入文本区域的   Java:标记“”上出现语法错误,此标记后面应为表达式   web服务Java RestService从日志文件写入和读取数据   java如何将ArrayList<String>转换为char数组,然后向后打印每个单词?   java SimpleDataFormat解析返回年终日期   加密Java aes解密bytebuffer,包括填充为空字节   java有没有办法从特定的if语句调用变量?   java从更新返回到渲染   spring GRPC Java登录测试   java为什么下面的代码不工作(StringBuffer.toString!=null)   java是一种可行的模式吗?   使用Spring集成测试的JavaOSGi片段   java jCommander为未知和未使用的值引发异常?   在imageView的editText中输入的java图像URL