1.新建shp文件
地理坐标系保持和影像一致,面类型
2.打开属性表
3.添加字段
这里分类6类,点击添加值添加
添加完毕
开始人工选地物类型,制作数据集
开始标注,标注的时候可以借助谷歌地图来看
标记足够多的样本
打开面转栅格工具
设置nodata值为15
import csv
import numpy as np
import rasterio
import pandas as pd
def readTif(fileName):
try:
dataset = rasterio.open(fileName)
return dataset
except rasterio.errors.RasterioIOError:
print(f"文件 {
fileName} 无法打开")
return None
num_bands = 8
csv_head_name = [f'Band{
i}' for i in range(1, num_bands + 1)] + ['Label', 'LabelName']
labels_name = {
0: "水体", 1: "植被",2: "建筑",3: "裸地",4: "农田",5: "道路"}
ori_dataset = readTif(orgin_path)
label_dataset = readTif(sample_path)
if ori_dataset is not None and label_dataset is not None:
label_matri = label_dataset.read(1)
data_matri = ori_dataset.read()
nodata_indices = np.where(label_matri != 15) # 获取所有非 nodata 的索引
# 准备数据
data = []
for i in range(nodata_indices[0].size):
row, col = nodata_indices[0][i], nodata_indices[1][i]
label = label_matri[row, col]
band_values = data_matri[:, row, col].tolist()
label_name = labels_name.get(label, 'Unknown')
band_values