public static bool PrjTransf(string srcFile, PrjEnvelope srcEnvelope, Dictionary <string, H5T.H5Type> dataSets, string dstFile, PrjEnvelope dstEnvelope, float dstResoultion) { Action <int, string> progressTracker = null; string[] args = new string[3]; string datasetstr = string.Empty; foreach (string itemdest in dataSets.Keys) { datasetstr += itemdest + ","; } datasetstr = datasetstr.Remove(datasetstr.LastIndexOf(',')); args[0] = string.Format("datasets ={0}", datasetstr); args[1] = string.Format("geoinfo={0},{1},{2},{3},1000.000,1000.000", srcEnvelope.MinX, srcEnvelope.MaxX, srcEnvelope.MinY, srcEnvelope.MaxY); args[2] = "proj4 = +proj=sinu +lon_0=0 +x_0=0 +y_0=0 +a=6371007.181 +b=6371007.181 +units=m +no_defs"; ISpatialReference dstSpatialRef = SpatialReference.GetDefault(); FilePrjSettings prjSetting = new FilePrjSettings(); IRasterDataProvider prd = GeoDataDriver.Open(srcFile, args) as IRasterDataProvider; if (prd != null) { prjSetting.OutEnvelope = dstEnvelope; prjSetting.OutResolutionX = dstResoultion; prjSetting.OutResolutionY = dstResoultion; prjSetting.OutPathAndFileName = dstFile; ProjectedFileTransform proj = new ProjectedFileTransform(); proj.ProjectNew(prd, prjSetting, dstSpatialRef, progressTracker, dataSets); prd.Dispose(); return(true); } return(false); }
public void TestProj() { IRasterDataProvider srcRaster = null; try { IFileProjector proj = FileProjector.GetFileProjectByName("NOAA_1BD"); srcRaster = GetSrcRaster(); FilePrjSettings prjSetting = GetPrjSetting(srcRaster); ISpatialReference dstSpatialRef = SpatialReference.GetDefault(); //默认的WGS84等经纬度投影。 proj.Project(srcRaster, prjSetting, dstSpatialRef, _progressCallback); Console.WriteLine(); } finally { if (srcRaster != null) { if (srcRaster.BandProvider != null) { srcRaster.BandProvider.Dispose(); } srcRaster.Dispose(); } } }
private IPrjSettingsEditor GetSettingEditor(FilePrjSettings settings) { using (IComponentLoader <IPrjSettingsEditor> loader = new ComponentLoader <IPrjSettingsEditor>()) { IPrjSettingsEditor[] editors = null;// loader.LoadComponents(Configer.GEODO_RSS_DIR_FILEPRJECTORS); foreach (IPrjSettingsEditor ed in editors) { if (ed.IsSupport(settings.GetType())) { return(ed); } } } return(null); }
private void button3_Click(object sender, EventArgs e) { IFileProjector[] prjs = FileProjector.LoadAllFileProjectors(); Console.WriteLine("..."); IFileProjector prj = FileProjector.GetFileProjectByName("SINGLEFILE"); FilePrjSettings settings = prj.CreateDefaultPrjSettings(); IPrjSettingsEditor editor = GetSettingEditor(settings); if (editor != null) { editor.Apply(settings); } // }
/// <summary> /// 通用MODIS 正弦数据产品投影转换 /// </summary> /// <param name="file">文件名</param> /// <param name="env">范围</param> /// <param name="res">分辨率</param> /// <returns></returns> public string PrjMODSIN(string file, string outdir, PrjEnvelope env, float res, string regionNam, Action <int, string> progressTracker) { //根据文件名解析tile号nh,nv UInt16 nh = 0; UInt16 nv = 0; string fnam = Path.GetFileNameWithoutExtension(file).ToLower(); string[] parts = fnam.Split(new char[] { '.' }); foreach (string part in parts) { if (part.Contains("h") & part.Contains("v")) { nh = Convert.ToUInt16(part.Substring(1, 2)); nv = Convert.ToUInt16(part.Substring(4, 2)); } } //计算图像四角坐标; double minX = -20015109.354 + nh * 1111950.5196666666; double maxX = -20015109.354 + (nh + 1) * 1111950.5196666666; double maxY = -10007554.677 + (18 - nv) * 1111950.5196666666; double minY = -10007554.677 + (18 - nv - 1) * 1111950.5196666666; string[] args = new string[3]; args[0] = "datasets = 0"; args[1] = "geoinfo=" + Convert.ToString(minX) + "," + Convert.ToString(maxX) + "," + Convert.ToString(minY) + "," + Convert.ToString(maxY) + ",1000.000,1000.000"; args[2] = "proj4 = +proj=sinu +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs"; ISpatialReference dstSpatialRef = SpatialReference.GetDefault(); FilePrjSettings prjSetting = new FilePrjSettings(); using (IRasterDataProvider prd = GeoDataDriver.Open(file, args) as IRasterDataProvider) { prjSetting.OutEnvelope = env; prjSetting.OutResolutionX = res; prjSetting.OutResolutionY = res; prjSetting.OutFormat = "LDF"; prjSetting.OutPathAndFileName = outdir + "\\" + Path.GetFileNameWithoutExtension(file) + "_" + regionNam + "_LST.ldf"; ProjectedFileTransform proj = new ProjectedFileTransform(); proj.Project(prd, prjSetting, dstSpatialRef, progressTracker); } return(prjSetting.OutPathAndFileName); }
/// <summary> /// 本示例 将一个tiff投影转换为一个等经纬度的tiff /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button19_Click(object sender, EventArgs e) { string filename = SelectFile("选择数据"); if (filename == null) { return; } ProjectedFileTransform trans = new ProjectedFileTransform(); IRasterDataProvider srcRaster = GeoDataDriver.Open(filename) as IRasterDataProvider; //输入数据,必须是已经投影的数据。 FilePrjSettings prjSettings = new FilePrjSettings(); prjSettings.OutBandNos = null; //从1开始的波段号,为空代表全波段 prjSettings.OutFormat = "TIFF"; //输出格式(输入LDF或者TIFF),空值代表LDF prjSettings.OutPathAndFileName = @"E:\testG.tiff"; //输出文件名,必须提供,完整的全路径文件名 //prjSettings.OutEnvelope = new PrjEnvelope(-180,180,-80,80); //输出地理范围,空值代表全数据 //prjSettings.OutResolutionX = 0.01f; //实际的输出分辨率。不填或0代表与输入数据分辨率一致 //prjSettings.OutResolutionY = 0.01f; ISpatialReference dstSpatialRef = SpatialReference.GetDefault(); //目标投影 Action <int, string> progressCallback = new Action <int, string>(OutProgress); //进度条 trans.Project(srcRaster, prjSettings, dstSpatialRef, progressCallback); }
private static void ConvertHdf4To5BySds <T>(Hdf4FileAttrs hdf4FileAttrs, int nyf5, int nxf5, int k, int rank, H5FileId fileId, string sdName, HDF4Helper.DataTypeDefinitions dtaDefinitions, Action <string, int, int> messageAction, SEnvelope envelopeNew, T fillValue, float dstResolution, ISpatialReference dstSpatialReference, ref UInt16[] rows, ref UInt16[] cols, ref Size srcStepSize, ref Size outSize) { T[,] data = new T[nyf5, nxf5]; H5DataSetId dsetId = null; T[,] dataNew = null; SDataByProject <T> dataByProject = null; try { for (int i = 0; i < hdf4FileAttrs.Count; i++) { Hdf4FileAttr hdf4FileAttr = hdf4FileAttrs[i]; if (messageAction != null) { messageAction(String.Format("正在转换数据集 {0}", sdName), k, i); } H4SDS sd = hdf4FileAttr.H4File.Datasets[k]; GetDataByHdf4(sd, rank, hdf4FileAttr, data); } dataNew = data; if (outSize.IsEmpty) { outSize = new Size(nxf5, nyf5); } if (dstSpatialReference != null && dstSpatialReference.IsSame(SpatialReference.GetDefault())) { if (rows == null && cols == null) { PrjEnvelope srcEnvelope = new PrjEnvelope(hdf4FileAttrs.Hdf4FileAttr.Envelope.XMin, hdf4FileAttrs.Hdf4FileAttr.Envelope.XMax, hdf4FileAttrs.Hdf4FileAttr.Envelope.YMin, hdf4FileAttrs.Hdf4FileAttr.Envelope.YMax); PrjEnvelope outenvelpoe = new PrjEnvelope(envelopeNew.XMin, envelopeNew.XMax, envelopeNew.YMin, envelopeNew.YMax); FilePrjSettings prjSetting = new FilePrjSettings(); prjSetting.OutEnvelope = outenvelpoe; prjSetting.OutResolutionX = dstResolution; prjSetting.OutResolutionY = dstResolution; outSize = prjSetting.OutSize; Size inSize = new Size(hdf4FileAttrs.Hdf4FileAttr.XDim, hdf4FileAttrs.Hdf4FileAttr.YDim); float dstResoultion = dstResolution; float srcResoultionX = (float)(hdf4FileAttrs.Hdf4FileAttr.CellWidth); float srcResoultionY = (float)(hdf4FileAttrs.Hdf4FileAttr.CellHeight); dataByProject = GetDataByProject <T>(dataNew, srcEnvelope, outenvelpoe, inSize, outSize, dstResoultion, srcResoultionX, srcResoultionY, fillValue, dstSpatialReference, out rows, out cols, out srcStepSize); } else { T[,] dstData = new T[outSize.Height, outSize.Width]; dataByProject = DoProject <T>(dataNew, fillValue, ref outSize, ref srcStepSize, dstData, rows, cols); } if (dataByProject != null) { dataNew = dataByProject.Data; } } long[] dims = new long[rank]; dims[0] = Convert.ToInt64(outSize.Height); dims[1] = Convert.ToInt64(outSize.Width); H5DataSpaceId dspaceId = H5S.create_simple(rank, dims); H5T.H5Type h5Type = Utility.GetH5Type(dtaDefinitions); // Define datatype for the data in the file. H5DataTypeId dtypeId = H5T.copy(h5Type); // Create the data set DATASETNAME. dsetId = H5D.create(fileId, sdName, dtypeId, dspaceId); // Write the one-dimensional data set array H5D.write(dsetId, new H5DataTypeId(h5Type), new H5Array <T>(dataNew));//H5A HDFAttributeDef[] attributeDef5s = hdf4FileAttrs[0].DatasetsAttributeDefs[k]; foreach (HDFAttributeDef attributeDef5 in attributeDef5s) { WriteHdfAttributes.WriteHdfAttribute(dsetId, attributeDef5); } } finally { // Close dataset and file. if (dsetId != null) { H5D.close(dsetId); } if (data != null) { data = null; } if (dataNew != null) { dataNew = null; } GC.Collect(); } }