问题:现在我有一些点坐标数据和一幅带有地理信息的遥感影像,如何提取这些点对应的遥感影像的光谱信息呢?
废话不多说,直接上码:
先导入一些包
import rasterio
import numpy as np
import os
import pandas as pd
from pyproj import Transformer
先定义函数
# 提取单张影像的像素值的函数
def extract_pixel_values_single_image(image_path, points_df):
with rasterio.open(image_path) as src:
transform = src.transform
band1 = src.read(1)
vals = []
for _, row in points_df.iterrows():
col, row = ~transform * (row['Longitude_degree'], row['Latitude_degree'])
col, row = int(col), int(row)
vals.append(band1[row, col])
return vals
单张影像提取
如果是单张影像,直接利用这个函数即可,函数中band1 = src.read(1)是读取的第一个波段,参数image_path是遥感影像的路径,points_df是对应的点数据,这里Longitude_degree是经度所在列名,Latitude_degree是纬度所在列名
如