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

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第三方库


热门话题
java LineNumberReader。如果查询行为不正确,则返回readLine()   java包含了一个使用AndroidX的工具栏,这让我的应用程序崩溃了   JVM设置通过“java jar”运行应用程序的最佳实践   java如何获取ImageButton宽度   java Oracle SQLLDR实用程序无响应   列出Java获取对象的arrayList中最常见的元素   java使用带有FlowLayout的getContentpane对布局应用更改,但不起作用为什么?   在java中,我可以在画布上绘制画布吗?   编译游戏代码时发生java异常错误   从firestore获取java Webview失败   java将TableLayout中单元格的内容向右对齐   java无法在发布模式下启动活动(使用proguard安卓optimize配置)   java允许在线程期间进行GUI更新。睡觉   java如何对以变量为列表的列表进行排序   API URL上的java Google云端点异常