在 Python 中将 GeoTIFF 转换为 JPEG 并提取 GeoTIFF 标头
我正在制作一个 Python 脚本,它将读取 GeoTIFF 文件,并执行以下两项操作:将 GeoTIFF 转换为静态 JPEG(尺寸小得多),并创建一个包含 GeoTIFF 标头的单独文本文件。
使用 Python GDAL API,我能够获取脚本来打开 GeoTIFF 文件并打印详细信息,例如 RasterXSize
、RasterYSize
、RasterCount 等。
问题在于保存 JPEG。我研究了 driver.CreateCopy() 方法,但是,它所做的只是创建一个非常大的空白且无法打开的 JPEG 文件。
另外,哪种方法检索我可以保存到文件中的所有 GeoTIFF 标头?
我既不是 GeoTIFF 专家,也不是 GDAL 专家,非常感谢您的帮助!
I am making a Python script which will read in a GeoTIFF file, and will do both: convert the GeoTIFF into a static JPEG (that is much smaller in size), and create a separate text file which contains the GeoTIFF headers.
Using the Python GDAL API, I am able to get the script to open a GeoTIFF file, and print details, such as the RasterXSize
, RasterYSize
, RasterCount
, etc.
The problem is with saving a JPEG. I have researched the driver.CreateCopy()
method, however, all it does is create a very large JPEG file that is blank and can't be opened.
Also, which method retrieves all of the GeoTIFF Headers that I can save to a file?
I'm neither an expert on GeoTIFFs nor GDAL, and I greatly appreciate the assistance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我自己通过谷歌搜索找到了答案。
要保存不同质量级别的 .jpg 文件,您需要使用以下代码:
我需要的参数存储在
theDataset.GetGeoTransform()
和theDataset.GetProjection 中()
方法。特别感谢这个网站: http:// /adventuresindevelopment.blogspot.com/2008/12/python-gdal-set-jpeg-quality-values-and.html
I figured it out myself with some Googling.
To save the .jpg file with varying level of quality, you need to use the following code:
The parameters I need are stored in both the
theDataset.GetGeoTransform()
, and thetheDataset.GetProjection()
methods.Special thanks to this site: http://adventuresindevelopment.blogspot.com/2008/12/python-gdal-set-jpeg-quality-values-and.html