遥感影像生成tfw文件

遥感影像生成tfw文件输入一个带仿射六参数的影像 生成 tfw 文件 include iostream include gdal h include gdal priv h include streambuf include fstream include iomanip boolcreateTF char imagePath 创建 tfw 文件程序 intmain intargc char argv iomanip fstream streambuf gdal priv h gdal h iostream

输入一个带仿射六参数的影像,生成tfw文件。

#include  
     #include  
     #include  
     #include  
     #include  
     #include  
     bool createTFW(char* imagePath);//创建tfw文件程序 int main(int argc,char*argv[]) { 
    cout << "程序功能:传入一张影像的绝对路径,生成这张影像的tfw文件!" << endl; cout << "V1.0 zph 2021.6.9" << endl; char* imagePath = argv[1]; createTFW(imagePath); return 0; } bool createTFW(char* imagePath) { 
    CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "NO"); // 支持中文路径 GDALAllRegister(); //注册所有的驱动  GDALDataset *poDataset; //GDAL数据集  poDataset = (GDALDataset *)GDALOpen(imagePath, GA_ReadOnly); if (poDataset == NULL) { 
    cout << "fail in open files!!!" << endl; return false; } double gt[6]; GDALGetGeoTransform(poDataset, gt); cout << "gt:";//预览 for (auto value : gt) cout << value << " "; cout << endl; fstream tfw; string tmpname = imagePath; tmpname = tmpname.substr(0, tmpname.find_last_of('.') + 1) + "tfw"; tfw.open(tmpname, ios::out); tfw << fixed; tfw << setprecision(10);//保留5位小数 tfw << gt[1] << endl; tfw << gt[2] << endl; tfw << gt[4] << endl; tfw << gt[5] << endl; tfw << gt[0] << endl; tfw << gt[3] << endl; tfw.close(); // 清空资源 delete poDataset; printf("Success create %s!\n", tmpname.c_str()); return true; } 
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/227456.html原文链接:https://javaforall.net

(0)
上一篇 2026年3月16日 下午9:16
下一篇 2026年3月16日 下午9:17


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号