已经使用其他方法获取了输出点的坐标,如何将其保存在了一个名为 output_poin的列表中
时间: 2024-03-06 20:48:35 浏览: 30
如果你已经使用其他方法获取了输出点的坐标,并将其保存在了一个名为 `output_points` 的列表中,你可以使用以下代码将输出点的坐标转换为像素坐标:
```python
import gdal
import numpy as np
# 打开影像文件
ds = gdal.Open("image.tif")
# 获取影像的地理空间信息
geo_transform = ds.GetGeoTransform()
# 将输出点的坐标转换为图像上的坐标
output_points = np.array(output_points)
x, y = output_points[:, 0], output_points[:, 1]
pixel_x = (x - geo_transform[0]) / geo_transform[1]
pixel_y = (y - geo_transform[3]) / geo_transform[5]
# 将像素坐标四舍五入为整数
pixel_x = np.round(pixel_x).astype(int)
pixel_y = np.round(pixel_y).astype(int)
# 保存输出点的像素坐标
output_pixel_points = np.column_stack((pixel_x, pixel_y))
```
这段代码首先使用 GDAL 库打开原始影像文件,并获取其地理空间信息。然后,将输出点的坐标转换为图像上的坐标,并将其四舍五入为整数。最后,将 `pixel_x` 和 `pixel_y` 数组合并为一个二维数组,并将其保存在 `output_pixel_points` 变量中。
请注意,这段代码中的 `image.tif` 是一个示例文件名,你需要将其替换为你实际使用的原始影像文件名。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)