python - 用于在 gdal.Translate 中列出 GCP 的 Python 语法?
问题描述
我想使用 gdal.Translate 将几个 GCP 添加到 Tiff 图像,但我不知道执行此操作的正确语法。help(gdal.TranslateOptions)
告诉我我需要使用 'GCPs' kwarg,这应该是 GCP 的列表。有谁知道我将如何将 GCP 添加为列表?
我已经使用命令行和 gdal_translate 完成了这项工作,这非常简单,但我最好使用 Python 来完成这项工作,因为我的项目代码的其余部分都在 Python 中。
这是我在命令行中所做的:
gdal_translate -of GTiff -gcp 0 0 -4.717259 52.711651 -gcp 127 0 3.305363 51.733681 -gcp 0 31 -4.992584 51.498657 -gcp 127 31 2.828687 50.546162 -gcp 50 21 -1.762230 51.575226 "C:\PATH_TO_TIF\sds_001.tif" "Output_test.tif”
解决方案
这有点令人困惑,因为与命令行工具相比,Python 绑定期望参数的顺序不同。
import gdal
# x, y, lon, lat
gcps = [
(0, 0, pt1.x, pt1.y),
(width, 0, pt2.x, pt2.y),
(width, height, pt3.x, pt3.y),
(0, height, pt4.x, pt4.y),
]
ds = gdal.Open('filename.bmp')
gdal.Translate(
'filename.tiff',
ds,
outputSRS='EPSG:4326',
GCPs=[gdal.GCP(x, y, 0, pixel, line) for (pixel, line, x, y) in gcps],
)
推荐阅读
- html - 电子邮件中的按钮重定向到具有有效链接的“about:blank”
- android - 在android中使用Axios或Fetch时React Native抛出网络错误
- reactjs - React - 测试当 Jest 和 Enzyme 状态改变时组件中的条件渲染元素是否被渲染
- firebase - React-native firebase 远程配置缓存刷新
- javascript - Dynamic TreeView of a directory in React
- python - 使用 Selenium (Python) 从元素中获取文本
- python - manim 条形图中的条形值
- python-3.x - 如何访问数据集中列中的列表值列表
- google-sheets - 如何使用谷歌表格转置一组与特定输入日期相对应的单元格?
- javascript - 如何在 p5.js 中为游戏创建小地图?