PIE SDK開啟長時間序列資料
阿新 • • 發佈:2018-12-19
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 }View Code |
2.4 示例截圖