- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经能够使用 matplotlib 绘制和显示光栅图像。那部分是成功的。我坚持的部分是能够以某种方式保存该情节。对于 rasterio,我找到了两个有用的教程:
https://rasterio.readthedocs.io/en/latest/topics/windowed-rw.html
和
我已经计算了一个名为 NDVI 的函数,通过 matplotlib,我可以使用以下代码按照我想要的方式显示它。但是当我将文件另存为 GeoTIFF 时,桌面上的图像全黑了。我也计划重新投影数据,并且我已将该代码注释掉。
这是我的代码:
import rasterio
import matplotlib.pyplot as plt
import numpy as np
nirband = r"LC08_L1TP_015033_20170822_20170912_01_T1_B5.TIF"
redband =r"LC08_L1TP_015033_20170822_20170912_01_T1_B4.TIF"
#rasterio.windows.Window(col_off, row_off, width, height)
window = rasterio.windows.Window(2000,2000,800,600)
with rasterio.open(nirband) as src:
subset = src.read(1, window=window)
fig, ax = plt.subplots(figsize=(12,6))
plt.imshow(subset)
plt.title(f'Band 5 Subset')
with rasterio.open(nirband) as src:
nir = src.read(1, window=window)
with rasterio.open(redband) as src:
red = src.read(1, window=window)
red = red.astype(float)
nir = nir.astype(float)
np.seterr(divide='ignore', invalid='ignore')
ndvi = np.empty(nir.shape, dtype=rasterio.float32)
check = np.logical_or ( red > 0, nir > 0 )
naip_ndvi = np.where ( check, (1.0*(nir - red )) / (1.0*( nir + red )),-2 )
fig, ax = plt.subplots(figsize=(12,6))
ndvi = ax.imshow(naip_ndvi)
ax.set(title="NDVI")
with rasterio.open("LC08_L1TP_015033_20170822_20170912_01_T1_B5.TIF") as src:
naip_data_ras = src.read()
naip_meta = src.profile
with rasterio.open('MyExample.tif', 'w',**naip_meta) as dst:
dst.write(naip_ndvi, window=window)
# =============================================================================
# with rasterio.open('example.tif') as dataset:
#
# # Read the dataset's valid data mask as a ndarray.
# mask = dataset.dataset_mask()
#
# # Extract feature shapes and values from the array.
# for geom, val in rasterio.features.shapes(
# mask, transform=dataset.transform):
#
# # Transform shapes from the dataset's own coordinate
# # reference system to CRS84 (EPSG:4326).
# geom = rasterio.warp.transform_geom(
# dataset.crs, 'EPSG:4326', geom, precision=6)
#
# # Print GeoJSON shapes to stdout.
# print(geom)
# =============================================================================
这是我使用 matplotlib 时 NDVI 的样子(我想将其作为 GeoTIFF 文件保存到我的桌面):
感谢您的所有帮助!
最佳答案
您如何查看输出图像?在可以向文件添加对比度拉伸(stretch)的图像查看器、GIS 或遥感软件中? NDVI 值从 -1 到 1 - 也许值的范围太小,您的软件无法自动显示。我最近在修改 PlanetScope 图像时遇到了类似的问题 - 它使用 matplotlib 按预期显示,但 tiff 显示为黑色。
您可以尝试通过将单元格值乘以 100 来缩放输出 - 这可能有助于解决显示问题。您还可以使用可以对图像应用对比度拉伸(stretch)的软件(QGIS、esri 产品、ImageJ 或图像处理软件)来验证输出图像值
关于python - 使用 matplotlib 和 Rasterio 我正在尝试将栅格保存为 GeoTIFF 并重新投影它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53383733/
我正在编写一个需要读取 4 channel geotiff 图像的代码,在本例中为 16 位图像(数据实际上是 12 位分辨率,但以 16 位编码)。 我的主要目标是读取像素值以便稍后使用它们。来自这
我正在制作一个 Python 脚本,该脚本将读取 GeoTIFF 文件,并将执行以下操作:将 GeoTIFF 转换为静态 JPEG(尺寸小得多),并创建一个单独的文本文件,其中包含 GeoTIFF h
我想在 R 中有一个 Geotiff 图像,我该怎么做?下面是一个简单的例子。我想以 Geotiff 格式生成绘图。 require(gstat) data(meuse) coordinates(me
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 7年前关闭。 Improve thi
我正在生成 2D 统计图,并且还想生成和保存图像颜色图。平均尺寸图像的数据类型为 float32。以下示例修改自在线资源: with rasterio.open(name,'w',**profile)
我正在尝试使用 GeoTIFF-jai 库在 Java 中生成经过地理校正的光栅图像。我尝试在 SourceForge 网站上查找有关如何执行此操作的文档,但 SourceForge 说“不幸的是,该
到目前为止,我找不到更改 TIFF 文件中的 GeoTiff-TAG 的方法。我的操作系统是 Linux Lubuntu 18.04,我使用的是 Python 3.x。只是 EXIF-TAG 可以通过
如何将 GeoTIFF(单波段)图像(例如 1000 x 1000 像素)子集化为规则的正方形网格(例如 50 x 50 像素;总共 400 个网格对象);并计算每个对象的平均纬度、平均经度和平均 D
我正在尝试使用 rasterio 加载图像,修改 ndarray,然后使用与原始图像相同的空间引用系统写出。下面的函数是我尝试这样做的。但是输出的 geotiff 中缺少空间引用系统。对我做错了什么有
如何从将 geotiff 图像分成常规 block (例如 50 x 50 像素)的图像中计算每个 block 的平均纬度和平均经度。 输入数据只是图像,例如从以下位置下载:http://eoimag
我的任务是获取一个 GeoTIFF,在其中进行一些图像分割,并将其保存到新的 GeoTIFF(具有现有坐标)。如果我理解正确,坐标将保存在 GeoTIFF 元数据中。所以我从原始文件中获取元数据: F
我有一个带有地理信息的 tif。使用 gdal,我可以将光栅文件转换为数组 (numpy)。 如何获取该数组中一个条目的坐标? 最佳答案 使用仿射变换矩阵,将像素坐标映射到世界坐标。例如,使用 aff
在Python中使用GDAL,如何获取GeoTIFF文件的经纬度? GeoTIFF 似乎不存储任何坐标信息。相反,它们存储 XY 原点坐标。但是,XY 坐标不提供左上角和左下角的经纬度。 看来我需要做
我有一个 geotiff 文件。 import xarray as xr urbanData = xr.open_rasterio('myGeotiff.tif') plt.imshow(urbanD
我有一个存储在多个 GeoTIFF 中的栅格时间序列我想转换为单个 *.tif 的文件 ( NetCDF )文件。数据是uint16 . 我可能可以使用 gdal_translate使用以下方法将每个
我有一个 PNG 图像文件。我想将其转换为 GeoTiff。我安装了 QGIS 软件,但无法使用它,也不知道如何对图像进行地理配准。请帮我。有没有在线软件? 最佳答案 这是一个非常好的教程,其中包含有
我有地理引用 tiff,gdalinfo 输出: Driver: GTiff/GeoTIFF Files: generated.tiff generated.tiff.aux.xml S
我目前有一张来自 GeoTiff 文件的 171 x 171 图像(尽管在其他情况下,我可能有更大的图像)。我的目标是获取图像中的每个像素并将其转换为纬度/经度对。 我已经能够根据这篇 StackOv
我有一组 png 文件和每个文件边缘的 EPSG:3006 坐标。如何使用 Python 将这些 png 文件转换为 geotiff 文件,以便 tiff 文件包含地理元数据。 我想这可以用 Rast
我有一组 png 文件和每个文件边缘的 EPSG:3006 坐标。如何使用 Python 将这些 png 文件转换为 geotiff 文件,以便 tiff 文件包含地理元数据。 我想这可以用 Rast
我是一名优秀的程序员,十分优秀!