用于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 testcontainers maven构建失败   java实现jacobi算法实现laplace方程   java中的多线程:如何在不等待所有线程使用ExecutorService完成任务的情况下终止所有线程的执行?   java Hello World不在Android Studio 3中工作   ubuntu Tomcat7的Java版本不正确   java Javafx内存泄漏   对于手动实现的Spring数据存储库方法,我应该使用Java8默认方法吗?   googleappengine中的java添加过滤查询   html当使用JSOUP库在Java中读取标签时,如何保留标签(如<br>、<ul>、<li>、<p>等)的含义?   编码为什么jasper生成的报告在Java中不显示西里尔语(保加利亚语)?   java有没有办法隐藏当前位置和jdk动作?   java找出编译原型文件的版本   有没有办法在运行时更改java方法的访问修饰符?   语法字符串。。。Java中的参数   java数组元素在添加其他元素时会相互覆盖   eclipse中的java GWT项目   java如何为spring rest模板请求将动态json属性名映射到jackson   java无法在Windows 10上找到特定的JDK   在xml字符串和java字符串之间提取正则表达式子字符串