首页
学习
活动
专区
圈层
工具
发布
    • 综合排序
    • 最热优先
    • 最新优先
    时间不限
  • 来自专栏有趣的Python和你

    rasterio的安装和使用

    大家可能听过GDAL库,其实rasterio是基于GDAL库二次封装的,更加符合Python风格的主要用于空间栅格数据处理的Python库。所以本文就简单介绍下rasterio的安装和使用。 rasterio安装 这个第三方库不是很好安装,尝试了大半天也没安装上。rasterio依赖很多第三方库,所以比较麻烦,我们按下面的顺序依次安装即可。 rasterio 这里有两点需要注意。 rasterio使用 其实我用Python来操作影像就两个要求,一是能读取到各个影像波段的数据,二是经过一些处理后,能再将数据存为影像。 import rasterio data = rasterio.open('yingxiang.tif') print(data.count) 7 当然还有很多其他的影像属性。

    2.4K40编辑于 2022-05-13
  • 来自专栏给永远比拿愉快

    使用Rasterio创建栅格数据

    方法描述 使用Rasterio创建并写入栅格数据比GDAL还简单一些,基本使用到两个函数: rasterio.open() write() 在open()函数当中,我们可以像GDAL中的Create( )方法一样,设置数据类型,数据尺寸,投影定义,仿射变换参数等一系列信息 另外,Rasterio中的数据集提供了一个profile属性,通过该属性可以获取这些信息的集合,这样我们读取源数据文件的时候获得该属性 但是Rasterio比CreateCopy()更为强大的地方是:你可以修改profile以适配你的目标文件,而CreateCopy()通过提供的原型文件进行创建,无法直接对这些元信息进行修改。 import rasterio import numpy as np # 读入的数据是绿,红,近红外波段的合成数据 with rasterio.open('LC08_122043_20161207.tif ()函数中依次列出所有的参数 with rasterio.open('NDVI.tif', mode='w', driver='GTiff', width

    1.9K20发布于 2019-01-22
  • 来自专栏给永远比拿愉快

    使用Rasterio做投影变换

    rasterio中提供了calculate_default_transform,可以直接计算目标系统中的放射变换参数和图像尺寸。 这样我们直接根据计算的结果更新目标文件的元信息即可。 代码实现 import numpy as np import rasterio from rasterio.warp import calculate_default_transform, reproject , Resampling from rasterio import crs src_img = 'example.tif' dst_img = 'reproject.tif' # 转为地理坐标系WGS84 dst_crs = crs.CRS.from_epsg('4326') with rasterio.open(src_img) as src_ds: profile = src_ds.profile width': dst_width, 'height': dst_height, 'nodata': 0 }) # 重投影并写入数据 with rasterio.open

    1.4K10发布于 2019-01-22
  • 来自专栏给永远比拿愉快

    使用Rasterio读取栅格数据

    Rasterio简介 有没有觉得用GDAL的Python绑定书写的代码很不Pythonic,强迫症的你可能有些忍受不了。不过,没关系,MapBox旗下的开源库Rasterio帮我们解决了这个痛点。 Rasterio是基于GDAL库二次封装的更加符合Python风格的主要用于空间栅格数据处理的Python库。 Rasterio中栅格数据模型基本和GDAL类似,需要注意的是: 在Rasterio 1.0以后,对于GeoTransform的表示弃用了GDAL风格的放射变换,而使用了Python放射变换的第三方库affine 栅格数据读取代码示例 下面的示例程序中演示了如何读取一个GeoTIFF文件并获取相关信息,需要注意的是: rasterio使用rasterio.open()函数打开一个栅格文件 rasterio使用read with rasterio.open('example.tif') as ds: print('该栅格数据的基本数据集信息(这些信息都是以数据集属性的形式表示的):') print(

    2.5K20发布于 2019-01-22
  • windows上安装rasterio最简单方法

    若要查看,可以在激活虚拟环境后使用以下命令: python --version Rasterio简介 Rasterio是一个基于GDAL的Python包,广泛用于处理地理空间栅格数据,如GeoTIFF文件 Rasterio功能强大且易于使用,已成为卫星数据分析的标准工具。 Rasterio的安装建议 为了避免在线安装时可能出现的问题,建议使用本地包安装Rasterio及其依赖包。 按照以下顺序安装依赖包和Rasterio: pip install H:\pyproj-3.6.1-cp39-cp39-win_amd64.whl pip install H:\GDAL-3.8.4-cp39 shapely-2.0.2-cp39-cp39-win_amd64.whl pip install H:\fiona-1.9.5-cp39-cp39-win_amd64.whl pip install H:\rasterio # 导入rasterio包 如果上述代码没有报错,则说明所有包都已成功安装。

    1K10编辑于 2026-02-06
  • rasterio运行代码警告proj_create_from_database: Cannot find proj.db

    Why can't rasterio find proj.db (rasterio versions < 1.2.0)? If you see rasterio.errors.CRSError: The EPSG code is unknown. Why can't rasterio find proj.db (rasterio from PyPI versions >= 1.2.0)? Rasterio will then use the version of PROJ contained in the wheel. 参考文献: https://github.com/rasterio/rasterio/blob/main/docs/faq.rst#why-cant-rasterio-find-projdb

    28500编辑于 2025-07-21
  • 来自专栏二猫の家

    遥感影像计算Jaccard 相似性系数

    影响格式为二值图像 #import rasterio and sklearn import rasterio from rasterio.warp import reproject, Resampling calculate_default_transform from sklearn.metrics import jaccard_score #read the first raster image with rasterio.open tif") as src1: raster1 = src1.read(1) profile1 = src1.profile #read the second raster image with rasterio.open read(1) profile2 = src2.profile #resample the first raster to 100m resolution resampled_raster1 = rasterio.open height, *resampled_raster1.bounds) #reproject the first raster to WGS-84 reprojected_raster1 = rasterio.open

    33530编辑于 2023-10-16
  • 来自专栏一个有趣的灵魂W

    利用gdal、rasterio将modis文件进行格式转换、投影转换

    所以本次的代码任然有优化和改进的空间,但是感觉在hdf转tif这部中rasterio的效率比gdal高多了 import gdal, osr import numpy as np import os import rasterio from rasterio.warp import calculate_default_transform, reproject, Resampling from rasterio #10,5-10都是赋值给新数据 outDataRaster.FlushCache()#把缓存清理,很重要 del outDataRaster #投影转换,这部分既可以用rasterio dst_ds.write(dst_array, i) 2NDVI: import gdal, osr import numpy as np import os import rasterio from rasterio.warp import calculate_default_transform, reproject, Resampling from rasterio import crs

    2.3K30发布于 2020-09-15
  • 来自专栏点点GIS

    使用 ChatGPT 和 Python 分析 Sentinel 2 图像。

    此外,Python 有许多库可以使使用 Sentinel 2 图像变得更加容易,包括rasterio、geopandas和matplotlib。 下面是一个示例 Python 代码,用于打开 Sentinel-2 光栅文件并使用以下方法绘制假彩色合成图rasterio: import rasterio from rasterio.plot import 然后可以使用模块show中的函数显示生成的图像rasterio.plot。 一旦我们将 Sentinel 2 图像加载到 Python 中,我们就可以开始从中提取信息。 rasterio以下是使用 计算 `Sentinel-2` 栅格文件的归一化差异植被指数 (NDVI)并绘制结果的示例 Python 代码: 代码如下: import rasterio import numpy as np from rasterio.plot import show # Open the Sentinel-2 raster file with rasterio.open('path

    1.1K10编辑于 2023-08-19
  • 来自专栏代码编写世界

    GDAL关于读写图像的简明总结

    3.图像读写 GDAL读写图像是通过RasterIO()这个函数实现的,这个函数提供了非常强大的功能,目前笔者也只总结了这以下方面的内容。 = (size_t) bufWidth * bufHeight * bandNum * depth; GByte *imgBuf = new GByte[imgBufNum]; //读取 img->RasterIO 最后得到的dst.tif如下: 3.2.16位影像读写 上述RasterIO()的写法可以兼容16为图像的读写,只不过要注意的是buf中是用2个Gbyte来表达1个16像素值的。 3.5.重采样读写 RasterIO()另外一个用法是可以自动缩放,重采样读写影像,例如这里将512X512大小的lena图像重采样成256X256大小: //申请buf size_t imgBufNum 查阅网上资料得知,RasterIO()重采样方式默认是最临近的方法,只有建立金字塔时可以设置重采样方式,但也仅限于缩小。

    1.4K10编辑于 2022-05-05
  • 来自专栏自学气象人

    求栅格序列每个像元的变化趋势和对应P值

    之前我们讲了怎么读取单张栅格,读取完之后是一个numpy的ndarray,那么只要进行相应的矩阵拼接即可: 导入包 import rasterio import scipy.stats as ss import numpy as np import glob from rasterio.plot import show 读取第一张图的元数据,方便最后写出结果 with rasterio.open profile = src.profile data = src.read() 组成时空立方体 这里组成栅格立方体也非常简单,用numpy的concatenate函数拼接一下即可: ds = [rasterio.open p_value 应用函数 slope_rs,r2,pv = np.apply_along_axis(rs_slope, 0,arr=ds) 保存结果 profile['nodata'] = 0 with rasterio.open ('slope.tif','w',**profile) as dest: dest.write(slope_rs,1) 查看结果 with rasterio.open('.

    3.4K40编辑于 2022-11-14
  • 来自专栏给永远比拿愉快

    Python空间数据处理环境搭建

    append channels <channel> 空间数据处理Python库的安装 常用的空间数据处理Python库 GDAL 全能型的基础空间数据处理库 fiona 基于GDAL的空间矢量数据处理库 rasterio 输入命令,进入虚拟环境 安装GDAL库 conda install -c conda-forge gdal 安装fiona库 conda install -c conda-forge fiona 安装rasterio 库 conda install -c conda-forge rasterio ​ 使用pip进行库的安装 什么是pip呢? ‑2.2.4‑cp37‑cp37m‑win_amd64.whl 安装fiona库 pip install Fiona‑1.7.11.post1‑cp37‑cp37m‑win_amd64.whl 安装rasterio 库 pip install rasterio‑1.0a12‑cp37‑cp37m‑win_amd64.whl 安装Jupyter pip install jupyter 使用Jupyter Notebook

    3.2K20发布于 2019-01-22
  • 来自专栏一个有趣的灵魂W

    MOD043km的hdf数据转为tif

    3K.A2018001.0320.061.2018003202214.hdf') 代码如下: import gdal, osr import numpy as np import os import rasterio from rasterio.warp import calculate_default_transform, reproject, Resampling from rasterio import crs

    2.1K41发布于 2020-09-15
  • 来自专栏疯狂学习GIS

    C++将h5转tif:支持高分数据等szip压缩的图像

    , nullptr); u_int16_t *band_data_0 = &data_0[0]; poDstDS->GetRasterBand(1)->RasterIO GDT_UInt16, 0, 0); u_int16_t *band_data_1 = &data_1[0]; poDstDS->GetRasterBand(2)->RasterIO GDT_UInt16, 0, 0); u_int16_t *band_data_2 = &data_2[0]; poDstDS->GetRasterBand(3)->RasterIO 使用gdal库创建一个新的TIFF文件,并使用RasterIO方法将每个波段的数据写入到TIFF文件中。 size, band_num, GDT_UInt16, nullptr); u_int16_t *band_data_0 = &data_0[0]; poDstDS->GetRasterBand(1)->RasterIO

    66110编辑于 2024-12-19
  • 来自专栏气python风雨

    多年暴雨tif数据集合成为一个nc数据

    我们需要首先定义一个包含多个 TIF 文件路径的列表,并使用 rioxarray.open_rasterio 函数打开这些文件,得到相应的 xarray 数据集。 RainStormChina/RainStormChina/2019/StormLevel2019.tif'] 读取文件 In [13]: import rioxarray dataset = rioxarray.open_rasterio 2019-01-01', freq='AS') for file in file_list: for i in time_coord: xds = rioxarray.open_rasterio 神奇海螺说zip的魔术可以帮忙 xds_list1=[] for file, time in zip(file_list, time_coord): xds = rioxarray.open_rasterio

    80110编辑于 2024-06-20
  • 来自专栏点点GIS

    地科Python数据分析案例 | 绘制黄土高原局部区域的沟壑覆盖度分析图

    # 调用dde模型库中的Project Raster模型 import numpy as np from rasterio.warp import calculate_default_transform , reproject, Resampling from rasterio import crs import rasterio def pydde_rasterProject_run(src_file , EPSG_Code, tag_file): tag_crs = crs.CRS.from_epsg(EPSG_Code) with rasterio.open(src_file) =0) # Ignore nodata # 读取山地阴影图 hs = rxr.open_rasterio(outHS) hs = hs[0] hs = hs.where(hs.values! max_depth=None, callback=my_callback ) outFill = temp_dir + "Fill.tif" fill_image = rxr.open_rasterio

    1.7K30编辑于 2023-11-03
  • 来自专栏磐创AI技术团队的专栏

    地理空间数据的时间序列分析

    为了处理光栅数据,我使用了rasterio库。 # import libraries import os import rasterio import matplotlib.pyplot as plt import numpy as np import 将首先使用rasterio加载一个随机图像,然后使用matplotlib功能绘制它。 # load in raster data rf = rasterio.open('. [] # loop through each raster for file in os.listdir(tsFolderPath): # read the files rf = rasterio.open

    86910编辑于 2024-04-28
  • 来自专栏气python风雨

    使用 EarthPy 堆叠和裁剪tif栅格数据

    as rio from rasterio.plot import plotting_extent import geopandas as gpd import earthpy as et import Stack 函数还返回两个对象,一个数组和一个 RasterIO 配置文件。做 肯定会在变量中同时捕获。 该功能还 需要 Rasterio 对象的空间变换,可以通过访问 Rasterio 配置文件中的 ''“transform”'' 键。 此函数获取 Rasterio 对象并将其裁剪为提供的 空间范围。 In [45]: # Open Landsat image as a Rasterio object in order to crop it stack_band_paths = glob.glob('

    61410编辑于 2024-06-20
  • 来自专栏给永远比拿愉快

    GDAL入门-使用GDAL进行遥感影像NDVI的计算(C++版本)

    * imgSizeX); // 进行NDWI的计算 for (int i = 0; i < imgSizeY; i++) { raseterBandRed->RasterIO GF_Read, 0, i, imgSizeX, 1, bufferBlockRed, imgSizeX, 1, GDT_UInt32, 0, 0); raseterBandNIR->RasterIO bufferBlockRed[j] - bufferBlockNIR[j]) / (bufferBlockRed[j] + bufferBlockNIR[j]); outputRasterBand->RasterIO

    4.4K60发布于 2019-01-22
  • 来自专栏DevOps

    影像瓦片切割

    GetProjectionRef returns nullptr" << std::endl; return false; } //GDALRasterIOExtraArg exterArg; //INIT_RASTERIO_EXTRA_ARG bandCount; GByte *imgBuf = new GByte[imgBufNum]; memset(imgBuf, 0, imgBufNum); //读取N列瓦片影像 srcDataset->RasterIO + srcStart + nRowTileWidth + j * storeWidth + i * tilesize, tileSizeX); } } poDstDS->RasterIO bandCount; GByte *imgBuf = new GByte[imgBufNum]; memset(imgBuf,0, imgBufNum); //读取N列瓦片影像 srcDataset->RasterIO imgBuf + srcStart + nRowTileWidth + j* storeWidth + i * tilesize, tileSizeX); } } poDstDS->RasterIO

    62310编辑于 2024-03-29
领券