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); }
/// <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); }