1. 功能简介
时间序列数据(time series data)是在不同时间上收集到的数据,这类数据是按时间顺序收集到的,用于所描述现象随时间变化的情况。当前随着遥感卫星技术日新月异的发展,遥感卫星的重访周期越来越短,外加历史数据的积累,产生了海量的遥感时间序列数据产品,这些数据真实地反映了地表在一段时间范围内的动态变化情况,成为了遥感影像信息提取和分析的重要数据参考。
[洞庭湖春、夏、秋、冬季影像图]
PIE支持长时间序列卫星影像数据的加载和动态显示,并且提供了便利的控制方式。
2. 功能实现说明
2.1 实现思路及原理说明
第一步 |
构建长时间序列图层对象。 |
第二步 |
针对每一时间点数据读取为栅格图层 |
第三步 |
将栅格图层添加至长时间序列图层对象中 |
2.2 核心接口与方法
接口/类 |
方法 |
说明 |
Carto.IAnimationLayer |
AddLayer() |
增加图层 |
Start() |
开始图层播放 |
|
Pause() |
暂停图层播放 |
|
Resume() |
继续播放 |
|
SetInterval(int msec) |
设置播放间隔 |
|
Carto.AnimationLayer |
|
长时间序列图层类 |
2.3 示例代码
项目名称 |
百度云盘地址下/PIE示例程序/08.打开长时间序列数据 |
项目位置 |
百度云盘地址下/D:\PIE示例数据\栅格数据\长时间序列数据 |
代码位置 |
百度云盘地址下/PIE视频教程/08. 打开长时间序列数据.avi |
示例代码 |
|
1 方法(一) 2 3 //时间序列文件 4 5 IList<string> hdfList = new List<string>(); 6 7 hdfList.Add(@"D:\FY4A\AGRI\L1\FDI\DISK\2018\20180515\" + "FY4A-_AGRI--_N_DISK_1047E_L1-_FDI-_MULT_NOM_20180515000000_20180515001459_4000M_V0001.HDF"); 8 9 hdfList.Add(@"D:\FY4A\AGRI\L1\FDI\DISK\2018\20180515\" + "FY4A-_AGRI--_N_DISK_1047E_L1-_FDI-_MULT_NOM_20180515010000_20180515011459_4000M_V0001.HDF"); 10 11 hdfList.Add(@"D:\FY4A\AGRI\L1\FDI\DISK\2018\20180515\" + 12 13 "FY4A-_AGRI--_N_DISK_1047E_L1-_FDI-_MULT_NOM_20180515020000_20180515021459_4000M_V0001.HDF"); 14 15 16 17 ISpatialReference spatialReference = new ProjectedCoordinateSystem();//目标空间参考 18 19 spatialReference.ImportFromUserInput("+proj=geos +h=35785863 +a=6378137.0 +b=6356752.3 +lon_0=104.7 +no_defs"); 20 21 //构建长时间序列图层 22 23 IAnimationLayer animationLayer = new AnimationLayer(); 24 25 int i = 0; 26 27 foreach (string file in hdfList) 28 29 { 30 31 string channelName = "NOMChannel13";//波段名称 32 33 string tempTif = System.IO.Path.GetDirectoryName(file) + "\\NOMChannel13_" + i.ToString() + ".tiff";//输出tiff路径 34 35 i++; 36 37 IRasterLayer rasterLayer = OpenStaticData(file, channelName, tempTif, spatialReference);// OpenStaticData方法定义在下方 38 39 if (rasterLayer != null) 40 41 { 42 43 animationLayer.AddLayer(rasterLayer as ILayer); 44 45 } 46 47 } 48 49 ILayer pLayer = animationLayer as ILayer; 50 51 pLayer.Name = "长时间序列图层"; 52 53 //添加至地图并刷新视图 54 55 mapControlMain.FocusMap.AddLayer(pLayer); 56 57 mapControlMain.ActiveView.PartialRefresh(ViewDrawPhaseType.ViewAll); 58 59 60 61 方法(二) 62 63 /// <summary> 64 65 /// 打开风云4A、风云2G等静止卫星数据,读取指定波段数据为tiff 66 67 /// </summary> 68 69 /// <param name="filePath">hdf路径</param> 70 71 /// <param name="channelName">波段通道名称</param> 72 73 /// <param name="tiffPath">生成tiff路径</param> 74 75 /// <param name="spatialReference">空间参考</param> 76 77 /// <returns></returns> 78 79 private IRasterLayer OpenStaticData(string filePath, string channelName, string tiffPath, ISpatialReference spatialReference) 80 81 { 82 83 IRasterLayer rasteLayer = null; 84 85 try 86 87 { 88 89 //打开MultiDataset 90 91 IMultiDataset hdfDataset = PIE.DataSource.DatasetFactory.OpenDataset(filePath, OpenMode.ReadOnly) as IMultiDataset; 92 93 if (hdfDataset != null) 94 95 { 96 97 //遍历,查找指定通道的Dataset,进行数据格式转换 98 99 for (int i = 0; i < hdfDataset.GetDatasetCount(); i++) 100 101 { 102 103 IDataset pTempDataset = hdfDataset.GetDataset(i); 104 105 if (pTempDataset.Name == channelName) 106 107 { 108 109 //将RasterDataset写入指定tiff 110 111 IRasterDataset hdfRasterDatasetBand = pTempDataset as IRasterDataset; 112 113 114 115 int nWidth = hdfRasterDatasetBand.GetRasterXSize(); 116 117 int nHeight = hdfRasterDatasetBand.GetRasterYSize(); 118 119 120 121 PixelDataType eDateType = hdfRasterDatasetBand.GetRasterBand(0).GetRasterDataType(); 122 123 int count = hdfRasterDatasetBand.GetBandCount(); 124 125 126 127 int[] bandMap = new int[count]; 128 129 for (int j = 0; j < count; j++) 130 131 { 132 133 bandMap[j] = j + 1; 134 135 } 136 137 string[] tempList = null; 138 139 IPixelBuffer pixBuffer = hdfRasterDatasetBand.Read(0, 0, nWidth, nHeight, nWidth, nHeight, bandMap); 140 141 //创建输出栅格数据集 142 143 IRasterDataset tifRasterDataset = DatasetFactory.CreateRasterDataset(tiffPath, nWidth, nHeight, count, eDateType, "GTiff", tempList); 144 145 bool flag = tifRasterDataset.Write(0, 0, nWidth, nHeight, pixBuffer.GetData_Ref(), nWidth, nHeight, eDateType, count, bandMap); 146 147 tifRasterDataset.SpatialReference = spatialReference; 148 149 tifRasterDataset.GetRasterBand(0).SetNoDataValue(65535); 150 151 152 153 //六参数,根据输入坐标的不同需要进行动态设置,本示例代码以风云4A-4000m的数据作为实验数据。 154 155 int beginLineNum = 0; 156 157 int nReslution = 4000; 158 159 string beginlineNumStr = hdfDataset.GetMetadataItem("Begin_Line_Number", ""); 160 161 if (string.IsNullOrEmpty(beginlineNumStr)) 162 163 { 164 165 beginlineNumStr = hdfDataset.GetMetadataItem("geospatial_lat_lon_extent_begin_line_number", ""); 166 167 if (string.IsNullOrEmpty(beginlineNumStr)) beginLineNum = 183; 168 169 } 170 171 172 173 if (!string.IsNullOrEmpty(beginlineNumStr)) 174 175 { 176 177 StringBuilder sb = new StringBuilder(); 178 179 foreach (char charStr in beginlineNumStr) 180 181 { 182 183 if ((charStr >= '0' && charStr <= '9') || charStr == ' ' || charStr == '-') sb.Append(charStr); 184 185 } 186 187 bool result = int.TryParse(sb.ToString(), out beginLineNum); 188 189 } 190 191 double[] geoTransform = new double[6]; 192 193 geoTransform[0] = -5496000; 194 195 geoTransform[1] = nReslution; 196 197 geoTransform[2] = 0; 198 199 geoTransform[3] = 5496000 - beginLineNum * nReslution; 200 201 geoTransform[4] = 0; 202 203 geoTransform[5] = -nReslution; 204 205 tifRasterDataset.SetGeoTransform(geoTransform); 206 207 208 209 (tifRasterDataset as IDisposable).Dispose(); 210 211 (hdfRasterDatasetBand as IDisposable).Dispose(); 212 213 (pixBuffer as IDisposable).Dispose(); 214 215 216 217 rasteLayer = PIE.Carto.LayerFactory.CreateDefaultLayer(tiffPath) as IRasterLayer; 218 219 break; 220 221 } 222 223 } 224 225 } 226 227 } 228 229 catch (Exception ex) 230 231 { 232 233 rasteLayer = null; 234 235 } 236 237 return rasteLayer; 238 239 } |
2.4 示例截图