像素坐标到地理坐标
csharp
dataset.bounds
BoundingBox(left=358485.0, bottom=4028985.0, right=590415.0, top=4265115.0)
dataset.xy(dataset.height // 2, dataset.width // 2)
(476550.0, 4149150.0)
dataset.transform
Affine(30.0, 0.0, 358485.0,
0.0, -30.0, 4265115.0)
dataset.transform * (0, 0)
(358485.0, 4265115.0)
dataset.transform * (dataset.width, dataset.height)
(590415.0, 4028985.0)
dataset.crs
CRS.from_epsg(32612)
批量转换
rows = np.array([0, 10, 20])
cols = np.array([0, 5, 15])
xs, ys = rasterio.transform.xy(transform, rows, cols)
地理坐标到像素坐标
csharp
x, y = (dataset.bounds.left + 100000, dataset.bounds.top - 50000)
row, col = dataset.index(x, y)
row, col
(1666, 3333)
band1[row, col]
7566
# 多个坐标转行列
xs = np.array([x1, x2, x3])
ys = np.array([y1, y2, y3])
rows, cols = rasterio.transform.rowcol(transform, xs, ys)