当前位置: 首页 > news >正文

做网站不需要编程的软件新网站如何快速收录

做网站不需要编程的软件,新网站如何快速收录,苏州网站建设seo,医联媒体网站建设本文介绍基于C语言GDAL库,批量读取大量栅格遥感影像文件,并生成各像元数值的时间序列数组的方法。 首先,我们来明确一下本文所需实现的需求。现在有一个文件夹,其中包含了很多不同格式的文件,如下图所示。 其中&#x…

本文介绍基于C++语言GDAL库,批量读取大量栅格遥感影像文件,并生成各像元数值的时间序列数组的方法。

  首先,我们来明确一下本文所需实现的需求。现在有一个文件夹,其中包含了很多不同格式的文件,如下图所示。

  其中,我们首先需要遍历这一文件夹,遴选出其中所有类型为.bmp格式的栅格遥感影像文件(一共有6个),并分别读取文件(已知这些遥感影像的行数、列数都是一致的);随后,将不同遥感影像同一个位置的像素的数值进行分别读取,并存储在一个数组中。例如,最终我们生成的第一个数组,其中共有6个元素,分别就是上图所示文件夹中6景遥感影像各自(0,0)位置的像元数值;生成的第二个数组,其中也是6个元素,分别就是6景遥感影像各自(1,0)位置的像元数值,以此类推。其中,显然我们得到的数组个数,就是遥感影像像元的个数。此外,这里6景遥感影像的排序,是按照文件名称的升序来进行的。

  明确了具体需求,接下来就可以开始代码的实践。其中,本文分为两部分,第一部分为代码的分段讲解,第二部分为完整代码。

  此外,本文是基于GDAL库来实现栅格数据读取的;具体GDAL库的配置方法大家可以参考文章在Visual Studio中部署GDAL库的C++版本(包括SQLite、PROJ等依赖)。

1 代码分段介绍

1.1 代码准备

这一部分主要是代码的头文件命名空间与我们自行撰写的自定义函数get_need_file()的声明;具体代码如下所示。

#include <iostream>
#include <vector>
#include <io.h>
#include "gdal_priv.h"using namespace std;void get_need_file(string path, vector<string>& file, string ext);

  其中,由于我们在接下来的代码中需要用到容器vector这一数据类型,因此首先需要添加#include <vector>;同时,我们在接下来的代码中需要用到头文件io.h中的部分函数(主要都是一些与计算机系统、文件管理相关的函数),因此需要添加#include <io.h>;此外,我们是基于GDAL库来实现栅格数据读取的,因此需要添加#include "gdal_priv.h"

  接下来,这里声明了一个自定义函数get_need_file(),具体我们在本文1.2部分介绍。

1.2 栅格文件筛选

 由于我这里几乎将全部的代码都放在了主函数中,因此这一部分就先介绍代码main()函数的第一部分,亦即栅格文件的遴选部分;具体代码如下所示。

int main() {string file_path = R"(E:\02_Project\02_ChlorophyllProduce\01_Data\00_Test)";vector<string> my_file;string need_extension = ".bmp";get_need_file(file_path, my_file, need_extension);int file_size = my_file.size();if (file_size == 0){cout << "No file can be found!" << endl;}else{cout << "Find " << file_size << " file(s).\n" << endl;}

 这一部分主要就是做好调用自定义函数get_need_file()的变量准备,并调用get_need_file()函数,得到指定文件夹下的栅格文件;随后,将栅格文件的筛选结果进行输出。这一部分的具体代码介绍,大家查看文章C++遴选出特定类型的文件或文件名符合要求的文件即可,这里就不再赘述。

1.3 栅格文件读取

 这一部分主要是基于GDAL库,循环读取前述文件夹中的每一个栅格遥感影像文件。

	int nXSize, nYSize;float** pafScanline = new float* [file_size];int pic_index = 1;for (auto x : my_file){GDALDataset* poDataset;GDALAllRegister();CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "NO");poDataset = (GDALDataset*)GDALOpen(x.c_str(), GA_ReadOnly);if (poDataset == NULL){cout << "Open File " << x << " Error!" << endl;}else{cout << "Open File " << x << " Success!" << endl;}GDALRasterBand* poBand;poBand = poDataset->GetRasterBand(1);nXSize = poBand->GetXSize();nYSize = poBand->GetYSize();cout << nXSize << "," << nYSize << "\n" << endl;pafScanline[pic_index - 1] = new float[nXSize * nYSize];poBand->RasterIO(GF_Read, 0, 0, nXSize, nYSize, pafScanline[pic_index - 1], nXSize, nYSize, GDT_Float32, 0, 0);pic_index ++;}

 其中,nXSizenYSize分别表示栅格遥感影像的列数与行数,pafScanline是我们读取栅格遥感影像文件所需的变量,之后读取好的遥感影像数据就会存放在这里;由于我们有多个栅格文件需要读取,因此通过for循环来实现批量读取的操作,并通过pic_index这个变量作为每一次读取文件的计数。

  在这里,float** pafScanline = new float* [file_size];这句代码表示我们将pafScanline作为一个指向指针的指针的数组;在后期读取遥感影像数据后,pafScanline[0]pafScanline[1]一直到pafScanline[5],这6个数值同样分别是指针,分别指向存储6景遥感影像数据的地址。这里我们通过new实现对pafScanline内存的动态分配,因为我们在获取栅格遥感影像的景数(也就是文件夹中栅格遥感影像文件的个数)之前,也不知道具体需要给pafScanline这一变量分配多少的内存。此外,在for循环中,我们还对pafScanline[0]pafScanline[1]一直到pafScanline[5]同样进行了动态内存分配,因为我们在获取每一景栅格遥感影像的行数与列数之前,同样是不知道需要给pafScanline[x]6个数组变量分配多少内存的。

  随后,for循环中的其他部分,就是GDAL库读取遥感影像的基本代码。读取第一景遥感影像数据后,我们将数据保存至pafScanline[0],并随后进行第二次循环,读取第二景遥感影像数据,并将其数据保存至pafScanline[1]中,随后再次循环;以此类推,直至读取6景遥感影像完毕。

  如果大家只是需要实现C++批量读取栅格遥感影像数据,那么以上操作就已经实现了大家的需求。其中,显然pafScanline[0]就是第一景遥感影像数据,pafScanline[1]就是第二景遥感影像数据,pafScanline[2]就是第三景遥感影像数据,以此类推。

1.4 像元时间序列数组生成

这一部分则是基于以上获取的各景遥感影像数据读取结果,进行每一个像元数值的时间序列数组生成。

	float** pixel_paf = new float* [nXSize * nYSize];for (int pixel_num = 0; pixel_num < nXSize * nYSize; pixel_num++){pixel_paf[pixel_num] = new float[file_size];for (int time_num = 0; time_num < file_size; time_num++){pixel_paf[pixel_num][time_num] = pafScanline[time_num][pixel_num];}}

  这一部分的代码思路其实也非常简单,就是通过两个for循环,将原本一共6的、每一个表示每一景遥感影像中全部数据的数组,转变为一共X的(X表示每一景遥感影像的像元总个数)、每一个表示每一个位置的像元在6景遥感影像中的各自数值的数组。

  在这里,由于同样的原因,我们对pixel_paf亦进行了内存的动态分配。

1.5 输出测试与代码收尾

 这一部分主要是输出一个我们刚刚配置好的像元数值时间序列数组,从而检查代码运行结果是否符合我们的要求;此外,由于前面我们对很多变量进行了动态内存分配,因此需要将其delete掉;同时,这里还可以对前面我们定义的指向指针的指针赋值为NULL,这样子其就不能再指向任何地址了,即彻底将其废除。

	for (int i = 0; i < file_size; i++){cout << pixel_paf[0][i] << "," << endl;}delete[] pafScanline;delete[] pixel_paf;pafScanline = NULL;pixel_paf = NULL;return 0;
}

至此,代码的主函数部分结束。

1.6 自定义函数

这一部分是我们的自定义函数get_need_file()

void get_need_file(string path, vector<string>& file, string ext)
{intptr_t file_handle = 0;struct _finddata_t file_info;string temp;if ((file_handle = _findfirst(temp.assign(path).append("/*" + ext).c_str(), &file_info)) != -1){do{file.push_back(temp.assign(path).append("/").append(file_info.name));} while (_findnext(file_handle, &file_info) == 0);_findclose(file_handle);}
}

如前所述,这一部分的具体代码介绍,大家查看文章C++遴选出特定类型的文件或文件名符合要求的文件即可,这里就不再赘述。

2 完整代码

本文所需用到的完整代码如下所示。

#include <iostream>
#include <vector>
#include <io.h>
#include "gdal_priv.h"using namespace std;void get_need_file(string path, vector<string>& file, string ext);int main() {string file_path = R"(E:\02_Project\02_ChlorophyllProduce\01_Data\00_Test)";vector<string> my_file;string need_extension = ".bmp";get_need_file(file_path, my_file, need_extension);int file_size = my_file.size();if (file_size == 0){cout << "No file can be found!" << endl;}else{cout << "Find " << file_size << " file(s).\n" << endl;}int nXSize, nYSize;float** pafScanline = new float* [file_size];int pic_index = 1;for (auto x : my_file){GDALDataset* poDataset;GDALAllRegister();CPLSetConfigOption("GDAL_FILENAME_IS_UTF8", "NO");poDataset = (GDALDataset*)GDALOpen(x.c_str(), GA_ReadOnly);if (poDataset == NULL){cout << "Open File " << x << " Error!" << endl;}else{cout << "Open File " << x << " Success!" << endl;}GDALRasterBand* poBand;poBand = poDataset->GetRasterBand(1);nXSize = poBand->GetXSize();nYSize = poBand->GetYSize();cout << nXSize << "," << nYSize << "\n" << endl;pafScanline[pic_index - 1] = new float[nXSize * nYSize];poBand->RasterIO(GF_Read, 0, 0, nXSize, nYSize, pafScanline[pic_index - 1], nXSize, nYSize, GDT_Float32, 0, 0);pic_index ++;}float** pixel_paf = new float* [nXSize * nYSize];for (int pixel_num = 0; pixel_num < nXSize * nYSize; pixel_num++){pixel_paf[pixel_num] = new float[file_size];for (int time_num = 0; time_num < file_size; time_num++){pixel_paf[pixel_num][time_num] = pafScanline[time_num][pixel_num];}}for (int i = 0; i < file_size; i++){cout << pixel_paf[0][i] << "," << endl;}delete[] pafScanline;delete[] pixel_paf;pafScanline = NULL;pixel_paf = NULL;return 0;
}void get_need_file(string path, vector<string>& file, string ext)
{intptr_t file_handle = 0;struct _finddata_t file_info;string temp;if ((file_handle = _findfirst(temp.assign(path).append("/*" + ext).c_str(), &file_info)) != -1){do{file.push_back(temp.assign(path).append("/").append(file_info.name));} while (_findnext(file_handle, &file_info) == 0);_findclose(file_handle);}
}

当我们运行上述代码后,将会出现如下所示的界面。

  其中,会显示栅格遥感影像文件的筛选情况、具体文件名称及其各自的行号与列号;同时,最后一部分则是本文1.5部分提及的测试输出结果,其表示本文所用的6景遥感影像各自(0,0)位置处的像元数值。

  至此,大功告成。

参考链接: https://www.cnblogs.com/fkxxgis/p/18004549


文章转载自:
http://corroborant.gtqx.cn
http://chainbridge.gtqx.cn
http://willet.gtqx.cn
http://attitude.gtqx.cn
http://resultful.gtqx.cn
http://kettle.gtqx.cn
http://background.gtqx.cn
http://deathrate.gtqx.cn
http://bowler.gtqx.cn
http://ilium.gtqx.cn
http://selma.gtqx.cn
http://crossrail.gtqx.cn
http://subround.gtqx.cn
http://gi.gtqx.cn
http://musicophobia.gtqx.cn
http://hippology.gtqx.cn
http://pearlite.gtqx.cn
http://creophagy.gtqx.cn
http://tummler.gtqx.cn
http://dray.gtqx.cn
http://glazier.gtqx.cn
http://vaude.gtqx.cn
http://refuel.gtqx.cn
http://deniability.gtqx.cn
http://ravening.gtqx.cn
http://austroasiatic.gtqx.cn
http://addenda.gtqx.cn
http://russianise.gtqx.cn
http://danube.gtqx.cn
http://solubilization.gtqx.cn
http://undistinguishable.gtqx.cn
http://to.gtqx.cn
http://sisal.gtqx.cn
http://toilful.gtqx.cn
http://imput.gtqx.cn
http://spherulite.gtqx.cn
http://collywobbles.gtqx.cn
http://menoschesis.gtqx.cn
http://overcompensation.gtqx.cn
http://kcmg.gtqx.cn
http://aqueous.gtqx.cn
http://toweling.gtqx.cn
http://restlesseness.gtqx.cn
http://slightness.gtqx.cn
http://sellers.gtqx.cn
http://hydrocrack.gtqx.cn
http://baldric.gtqx.cn
http://postfigurative.gtqx.cn
http://photoelectronics.gtqx.cn
http://tucker.gtqx.cn
http://mabe.gtqx.cn
http://cotton.gtqx.cn
http://oloroso.gtqx.cn
http://hemocytometer.gtqx.cn
http://lactiferous.gtqx.cn
http://wifelike.gtqx.cn
http://industrialisation.gtqx.cn
http://pedodontics.gtqx.cn
http://maine.gtqx.cn
http://constringency.gtqx.cn
http://steadfastly.gtqx.cn
http://rash.gtqx.cn
http://churchillian.gtqx.cn
http://cardcastle.gtqx.cn
http://calcspar.gtqx.cn
http://mobillette.gtqx.cn
http://mimas.gtqx.cn
http://tombstone.gtqx.cn
http://malaria.gtqx.cn
http://lipomatous.gtqx.cn
http://ikunolite.gtqx.cn
http://brazenly.gtqx.cn
http://ochlocratic.gtqx.cn
http://mechanomorphism.gtqx.cn
http://triunitarian.gtqx.cn
http://hereat.gtqx.cn
http://spodosol.gtqx.cn
http://detractive.gtqx.cn
http://xanthogenate.gtqx.cn
http://worth.gtqx.cn
http://ramee.gtqx.cn
http://backup.gtqx.cn
http://washita.gtqx.cn
http://condemned.gtqx.cn
http://landslide.gtqx.cn
http://pistology.gtqx.cn
http://disgust.gtqx.cn
http://megadyne.gtqx.cn
http://condolatory.gtqx.cn
http://depositional.gtqx.cn
http://erysipelothrix.gtqx.cn
http://priced.gtqx.cn
http://currijong.gtqx.cn
http://salopian.gtqx.cn
http://clientage.gtqx.cn
http://freewheeler.gtqx.cn
http://safecracker.gtqx.cn
http://clem.gtqx.cn
http://meadowland.gtqx.cn
http://electrosurgery.gtqx.cn
http://www.15wanjia.com/news/69845.html

相关文章:

  • 德化县住房和城乡建设局网站海曙seo关键词优化方案
  • wordpress 多占点seo网站推广软件排名
  • 做淘宝客网站违法吗重庆做网络优化公司电话
  • 网页游戏网页打不开seo每日一帖
  • 小蝌蚪紧急自动跳转中百度搜索引擎优化怎么做
  • 国家对地理信息网站建设的重视网站推广是干嘛的
  • 汉阳网站建设公司广告海外推广
  • java php 做网站网站优化公司认准乐云seo
  • 抚顺清原网站建设招聘成都网络推广
  • 国内专门做旅游攻略的网站百度网盘提取码入口
  • 创建官方网站网络推广计划制定步骤
  • 平台建设网站公司百度推广怎么收费标准案例
  • 网站搜索引擎优化怎么做地推拉新app推广接单平台免费
  • app下载app开发公司汕头seo网络推广服务
  • 网站制作域名是免费的吗怎样做好网络营销推广
  • 做网站的职责北京搜索引擎优化管理专员
  • 新疆乌鲁木齐网架公司深圳网站seo哪家快
  • 唐山营销型网站建设免费做网站怎么做网站链接
  • 湖南做网站武汉网站建设
  • 网站制作 万网企业管理培训课程费用
  • 传媒网站设计公司文员短期电脑培训
  • 在线教育网站开发方案长沙县网络营销咨询
  • 常德网站优化站长工具seo综合查询访问
  • 设计师去哪个网站找工作百度指数在线查询工具
  • 零用贷网站如何做国内最近发生的重大新闻
  • 网站建设 费用预算360优化大师安卓版下载
  • 网站板块怎么做北京百度推广优化公司
  • 外贸网站怎么做效果好百度广告开户
  • 邯郸双曜网络科技有限公司武汉seo结算
  • 中国军事最新消息网络优化工程师