private SortedDictionary <string, StatAreaItem> StatTemplate <T>(IRasterDataProvider[] rasters, string tempFile, Func <T, bool> func, bool isCombinSameDay)//计算最大覆盖 { using (IRasterDataProvider tempRaster = RasterDataDriver.Open(tempFile) as IRasterDataProvider) { return(StatTemplate <T>(rasters, tempRaster, func, isCombinSameDay)); } }
private void button4_Click(object sender, EventArgs e) { //string dataFile1 = "K:\\待更新\\异常文件\\MOD06_L2.A2001051.1515.hdf"; //string dataFile2 = "K:\\待更新\\异常文件\\MOD06_L2.A2001051.1515.hdf"; //string dataFile3 = "K:\\待更新\\异常文件\\MOD06_L2.A2001051.1515.hdf"; //string dataFile4 = "K:\\待更新\\异常文件\\MOD06_L2.A2001051.1515.hdf"; string dataSet = "Cloud_Optical_Thickness"; string[] openArgs = new string[] { "datasets=" + dataSet }; string dir = "K:\\待更新\\异常文件"; string[] dataFiles = Directory.GetFiles(dir, "MOD06_L2*.HDF", SearchOption.AllDirectories); foreach (string dataFile in dataFiles) { try { using (IRasterDataProvider mainRaster = RasterDataDriver.Open(dataFile, openArgs) as IRasterDataProvider) { if (mainRaster != null) { continue; } } } catch (System.Exception ex) { continue; } } }
private void TryCreateLDFFile(string bandfname, int bandNO, int xSize, int ySize, float[] buffer, string[] options, enumDataType dataType) { string dstDir = Path.GetDirectoryName(bandfname); if (!Directory.Exists(dstDir)) { Directory.CreateDirectory(dstDir); } if (File.Exists(bandfname)) { File.Delete(bandfname); } IRasterDataDriver driver = RasterDataDriver.GetDriverByName("LDF") as IRasterDataDriver; using (IRasterDataProvider bandRaster = driver.Create(bandfname, xSize, ySize, 1, dataType, options) as IRasterDataProvider) { GCHandle handle = GCHandle.Alloc(buffer, GCHandleType.Pinned); try { bandRaster.GetRasterBand(1).Write(0, 0, xSize, ySize, handle.AddrOfPinnedObject(), enumDataType.Float, xSize, ySize); } finally { handle.Free(); } } }
/// <summary> /// 多文件统计覆盖面积和累积面积 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="rasterFiles"></param> /// <param name="templateName">China_XjRaster|China_LandRaster</param> /// <param name="func"></param> /// <returns></returns> public SortedDictionary <string, StatAreaItem> Stat <T>(string[] rasterFiles, string templateName, Func <T, bool> func, bool isCombinSameDay) { List <IRasterDataProvider> rasters = new List <IRasterDataProvider>(); try { for (int i = 0; i < rasterFiles.Length; i++) { IRasterDataProvider dRaster = RasterDataDriver.Open(rasterFiles[i]) as IRasterDataProvider; if (dRaster != null) { rasters.Add(dRaster); } } if (rasters.Count == 0) { return(null); } return(Stat <T>(rasters.ToArray(), templateName, func, isCombinSameDay)); } catch { return(null); } finally { for (int i = 0; i < rasters.Count; i++) { rasters[i].Dispose(); } } }
/// <summary> /// 单文件统计面积 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="rasterFile"></param> /// <param name="templateName"></param> /// <param name="func"></param> /// <returns></returns> public SortedDictionary <string, double> Stat <T>(string rasterFile, string templateName, Func <T, bool> func) { if (string.IsNullOrWhiteSpace(rasterFile)) { return(null); } IRasterDataProvider dRaster = null; try { dRaster = RasterDataDriver.Open(rasterFile) as IRasterDataProvider; if (dRaster == null) { return(null); } return(Stat <T>(dRaster, templateName, func)); } finally { if (dRaster != null) { dRaster.Dispose(); } } }
private void InputRegisterFile(string file) { string fileExt = Path.GetExtension(file); fileExt = fileExt.ToLower(); switch (fileExt) { case ".ldf": IRasterDataProvider prd = RasterDataDriver.Open(file) as IRasterDataProvider; if (prd == null) { break; } _spatial = prd.SpatialRef; textBox2.Text = file; //textBox3.Text = prd.CoordEnvelope.MinX.ToString(); //textBox4.Text = prd.CoordEnvelope.MaxY.ToString(); //textBox7.Text = (prd.CoordEnvelope.Width / _imgSize.Width).ToString(); //textBox8.Text = (prd.CoordEnvelope.Height / _imgSize.Height).ToString(); doubleTextBox1.Value = prd.CoordEnvelope.MinX; doubleTextBox2.Value = prd.CoordEnvelope.MaxY; doubleTextBox5.Value = (prd.CoordEnvelope.Width / _imgSize.Width); doubleTextBox6.Value = (prd.CoordEnvelope.Height / _imgSize.Height); break; case ".hdr": break; default: break; } }
private static DataIdentify GetDataIdentify(string fname) { using (IRasterDataProvider prd = RasterDataDriver.Open(fname) as IRasterDataProvider) { return(prd == null ? null : prd.DataIdentify); } }
protected IRasterDataProvider CreateOutM_BandRaster(string outFileName, RasterMaper[] inrasterMaper, int bandcount) { IRasterDataDriver raster = RasterDataDriver.GetDriverByName("LDF") as IRasterDataDriver; CoordEnvelope outEnv = null; foreach (RasterMaper inRaster in inrasterMaper) { if (outEnv == null) { outEnv = inRaster.Raster.CoordEnvelope; } else { outEnv.Union(inRaster.Raster.CoordEnvelope); } } float resX = inrasterMaper[0].Raster.ResolutionX; float resY = inrasterMaper[0].Raster.ResolutionY; int width = (int)(Math.Round(outEnv.Width / resX)); int height = (int)(Math.Round(outEnv.Height / resY)); string mapInfo = outEnv.ToMapInfoString(new Size(width, height)); string[] optionString = new string[] { "INTERLEAVE=BSQ", "VERSION=LDF", "WITHHDR=TRUE", "SPATIALREF=" + inrasterMaper[0].Raster.SpatialRef == null?"":("SPATIALREF=" + inrasterMaper[0].Raster.SpatialRef.ToProj4String()), "MAPINFO={" + 1 + "," + 1 + "}:{" + outEnv.MinX + "," + outEnv.MaxY + "}:{" + resX + "," + resY + "}" }; RasterDataProvider outRaster = raster.Create(outFileName, width, height, bandcount, enumDataType.UInt16, optionString) as RasterDataProvider; return(outRaster); }
public static IRasterDataProvider CreateRaster(string outFileName, IRasterDataProvider referProvider, string fname) { int width = referProvider.Width; int height = referProvider.Height; Project.ISpatialReference spatialRef = referProvider.SpatialRef; enumDataType datatype = referProvider.DataType; List <string> options = new List <string>(); options.Add("INTERLEAVE=BSQ"); options.Add("VERSION=LDF"); options.Add("WITHHDR=TRUE"); options.Add("SPATIALREF=" + spatialRef.ToProj4String()); options.Add("MAPINFO={" + 1 + "," + 1 + "}:{" + referProvider.CoordEnvelope.MinX + "," + referProvider.CoordEnvelope.MaxY + "}:{" + referProvider.ResolutionX + "," + referProvider.ResolutionY + "}"); //=env.ToMapInfoString(new Size(width, height)); string hdrfile = HdrFile.GetHdrFileName(Path.ChangeExtension(fname, ".hdr")); if (!string.IsNullOrWhiteSpace(hdrfile) && File.Exists(hdrfile)) { HdrFile hdr = HdrFile.LoadFrom(hdrfile); if (hdr != null && hdr.BandNames != null) { options.Add("BANDNAMES=" + string.Join(",", hdr.BandNames)); } } if (!Directory.Exists(Path.GetDirectoryName(outFileName))) { Directory.CreateDirectory(Path.GetDirectoryName(outFileName)); } IRasterDataDriver raster = RasterDataDriver.GetDriverByName("LDF") as IRasterDataDriver; RasterDataProvider outRaster = raster.Create(outFileName, width, height, 1, datatype, options.ToArray()) as RasterDataProvider; return(outRaster); }
//以下为一些辅助帮助类 public static IRasterDataProvider CreateRaster(string outFileName, CoordEnvelope env, float resolutionX, float resolutionY, int bandCount, IRasterDataProvider referProvider) { //int bandCount = referProvider.BandCount; //CoordEnvelope outEnv = referProvider.CoordEnvelope; //float resX = referProvider.ResolutionX; //float resY = referProvider.ResolutionY; int width = (int)(Math.Round(env.Width / resolutionX)); int height = (int)(Math.Round(env.Height / resolutionY)); Project.ISpatialReference spatialRef = referProvider.SpatialRef; enumDataType datatype = referProvider.DataType; List <string> options = new List <string>(); options.Add("INTERLEAVE=BSQ"); options.Add("VERSION=LDF"); options.Add("WITHHDR=TRUE"); options.Add("SPATIALREF=" + spatialRef.ToProj4String()); options.Add("MAPINFO={" + 1 + "," + 1 + "}:{" + env.MinX + "," + env.MaxY + "}:{" + resolutionX + "," + resolutionY + "}"); //=env.ToMapInfoString(new Size(width, height)); string hdrfile = HdrFile.GetHdrFileName(referProvider.fileName); if (!string.IsNullOrWhiteSpace(hdrfile) && File.Exists(hdrfile)) { HdrFile hdr = HdrFile.LoadFrom(hdrfile); if (hdr != null && hdr.BandNames != null) { options.Add("BANDNAMES=" + string.Join(",", hdr.BandNames)); } } CheckAndCreateDir(Path.GetDirectoryName(outFileName)); IRasterDataDriver raster = RasterDataDriver.GetDriverByName("LDF") as IRasterDataDriver; RasterDataProvider outRaster = raster.Create(outFileName, width, height, bandCount, datatype, options.ToArray()) as RasterDataProvider; return(outRaster); }
internal IRasterDataProvider MosaicToFile(string mosaicFilename) { IRasterDataProvider mosaicFileRaster = null; try { if (File.Exists(mosaicFilename)) { mosaicFileRaster = RasterDataDriver.Open(mosaicFilename, enumDataProviderAccess.Update, null) as IRasterDataProvider; if (mosaicFileRaster.BandCount != fileRaster.BandCount) { mosaicFileRaster.Dispose(); mosaicFileRaster = CreateMosaicFile(mosaicFilename, inArg); } } else { mosaicFileRaster = CreateMosaicFile(mosaicFilename, inArg); } if (mosaicFileRaster == null) { return(null); } RasterMoasicProcesser mo = new RasterMoasicProcesser(); //mo.Moasic(new IRasterDataProvider[] { fileRaster }, mosaicFileRaster, true, new string[] { "0" }, action); mo.MoasicSimple(fileRaster, mosaicFileRaster, true, new string[] { "0" }, action); return(mosaicFileRaster); } finally { } }
protected IRasterDataProvider CreateOutRaster(string outFileName, RasterMaper[] inrasterMaper) { IRasterDataDriver raster = RasterDataDriver.GetDriverByName("MEM") as IRasterDataDriver; CoordEnvelope outEnv = null; foreach (RasterMaper inRaster in inrasterMaper) { if (outEnv == null) { outEnv = inRaster.Raster.CoordEnvelope; } else { outEnv.Union(inRaster.Raster.CoordEnvelope); } } float resX = inrasterMaper[0].Raster.ResolutionX; float resY = inrasterMaper[0].Raster.ResolutionY; int width = (int)(Math.Round(outEnv.Width / resX)); int height = (int)(Math.Round(outEnv.Height / resY)); string mapInfo = outEnv.ToMapInfoString(new Size(width, height)); RasterDataProvider outRaster = raster.Create(outFileName, width, height, 1, enumDataType.Int16, mapInfo) as RasterDataProvider; return(outRaster); }
/// <summary> /// 全球火点LDF转换Dat /// </summary> public void writeGFR() { IRasterDataProvider dp = RasterDataDriver.Open(@"L:\新演示数据\01_火情\全球火点\FIR_FREQ_FY3B_VIRR_1D_GBAL_PXXX_1000KM_201304250941.ldf") as IRasterDataProvider; Size size = new Size(dp.Width, dp.Height); IPixelFeatureMapper <Int16> result = new MemPixelFeatureMapper <Int16>("FIR", dp.Width * dp.Height, size, dp.CoordEnvelope, dp.SpatialRef); RasterIdentify id = new RasterIdentify(dp.fileName); id.ThemeIdentify = "CMA"; id.ProductIdentify = "FIR"; id.SubProductIdentify = "GFRF"; id.IsOutput2WorkspaceDir = true; IArgumentProvider ap = new ArgumentProvider(dp, null); RasterPixelsVisitor <UInt16> visitor = new RasterPixelsVisitor <UInt16>(ap); visitor.VisitPixel(new int[] { 1 }, (index, values) => { result.Put(index, (Int16)values[0]); }); using (IInterestedRaster <Int16> iir = new InterestedRaster <Int16>(id, size, dp.CoordEnvelope.Clone(), dp.SpatialRef)) { iir.Put(result); string filename = iir.FileName; } }
private IRasterDataProvider CreateOutRaster(string outFileName, RasterMaper[] inrasterMaper, int extHeaderLength) { IRasterDataDriver raster = RasterDataDriver.GetDriverByName("MEM") as IRasterDataDriver; CoordEnvelope outEnv = null; float resX = inrasterMaper[0].Raster.ResolutionX; float resY = inrasterMaper[0].Raster.ResolutionY; foreach (RasterMaper inRaster in inrasterMaper) { if (outEnv == null) { outEnv = inRaster.Raster.CoordEnvelope; } else { outEnv = outEnv.Union(inRaster.Raster.CoordEnvelope); } if (resX < inRaster.Raster.ResolutionX) { resX = inRaster.Raster.ResolutionX; } if (resY < inRaster.Raster.ResolutionY) { resY = inRaster.Raster.ResolutionY; } } int width = (int)(Math.Round(outEnv.Width / resX)); int height = (int)(Math.Round(outEnv.Height / resY)); string mapInfo = outEnv.ToMapInfoString(new Size(width, height)); RasterDataProvider outRaster = raster.Create(outFileName, width, height, 1, enumDataType.UInt16, mapInfo, "EXTHEADERSIZE=" + extHeaderLength) as RasterDataProvider; return(outRaster); }
/// <summary> /// 根据栅格文件名查找图像增强方案文件路径 /// </summary> /// <param name="rasterName"></param> /// <param name="productName"></param> /// <returns></returns> private static string GetEnhanceFileByRasterFileName(string rasterName, string productName) { using (IRasterDataProvider prd = RasterDataDriver.Open(rasterName) as IRasterDataProvider) { //首先判断是栅格文件再执行 return(GetEnhanceNameByRasterFileName(prd, productName)); } }
private SortedDictionary <string, double> StatRasterTemplate <T>(IRasterDataProvider raster, string tempFile, Func <T, bool> func)//计算最大覆盖 { using (IRasterDataProvider tempRaster = RasterDataDriver.Open(tempFile) as IRasterDataProvider) { SortedDictionary <string, double> result = new SortedDictionary <string, double>(); StatRasterTemplate(raster, tempRaster, func, ref result); return(result); } }
private IRasterDataProvider CreateRaster(string outFileName, IRasterDataProvider inRaster) { IRasterDataDriver raster = RasterDataDriver.GetDriverByName("MEM") as IRasterDataDriver; CoordEnvelope outEnv = inRaster.CoordEnvelope.Clone(); string mapInfo = outEnv.ToMapInfoString(new Size(inRaster.Width, inRaster.Height)); RasterDataProvider outRaster = raster.Create(outFileName, inRaster.Width, inRaster.Height, 1, enumDataType.Int16, mapInfo) as RasterDataProvider; return(outRaster); }
/// <summary> /// H2A_RM2B /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button7_Click(object sender, EventArgs e) { Action <int, string> progress = new Action <int, string>(OutProgress); string dir = textBox1.Text; string outDir = textBox2.Text; string[] files = Directory.GetFiles(dir, "*.h5"); StringBuilder msgInfo = new StringBuilder(); for (int i = 0; i < files.Length; i++) { FY3L2L3FilePrjSettings setting = new FY3L2L3FilePrjSettings(); setting.OutFormat = "LDF"; setting.OutResolutionX = 0.25f; setting.OutResolutionY = 0.25f; //扩展:经纬度数据集的放大倍数 Dictionary <string, double> args = new Dictionary <string, double>(); args.Add("xzoom", 0.000001d); args.Add("yzoom", 0.000001d); setting.ExtArgs = new object[] { args }; IRasterDataProvider mainRaster = null; IRasterDataProvider locationRaster = null; string file = files[i]; try { progress((int)((i + 1f) / files.Length * 100), null); string[] openArgs = new string[] { "datasets=" + "Res0_ap,Res0_cl,Res0_ic,Res0_sst,Res0_ssw,Res0_wv,Res10_sst,Res10_ssw,Res18_ap,Res18_cl,Res18_ic,Res18_ssw,Res18_wv,Res6_sst" }; mainRaster = RasterDataDriver.Open(file, openArgs) as IRasterDataProvider; string[] locationArgs = new string[] { "datasets=" + "Long_of_Observation_Point,Lat_of_Observation_Point", "geodatasets=" + "Long_of_Observation_Point,Lat_of_Observation_Point" }; locationRaster = RasterDataDriver.Open(file, locationArgs) as IRasterDataProvider; if (locationRaster == null || locationRaster.BandCount == 0) { msgInfo.AppendLine("经纬度HDF数据文件,不存在经纬度数据集[Longitude,Latitude]" + file); return; } string outFilename = Path.Combine(outDir, Path.GetFileNameWithoutExtension(file) + ".LDF"); setting.OutPathAndFileName = outFilename; setting.LocationFile = locationRaster; FY3L2L3FileProjector projector = new FY3L2L3FileProjector(); projector.Project(mainRaster, setting, SpatialReference.GetDefault(), null); } finally { if (mainRaster != null) { mainRaster.Dispose(); mainRaster = null; } if (locationRaster != null) { locationRaster.Dispose(); locationRaster = null; } } } }
private Dictionary <string, SortedDictionary <string, double> > StatByRasterTemplate <T>(IRasterDataProvider raster, string tempFile, Dictionary <string, Func <T, bool> > multiFilter, bool weight, float weightZoom, string vectorTemplate) where T : struct, IConvertible { using (IRasterDataProvider tempRaster = RasterDataDriver.Open(tempFile) as IRasterDataProvider) { Dictionary <string, SortedDictionary <string, double> > result = new Dictionary <string, SortedDictionary <string, double> >(); result = StatByRasterTemplate(raster, tempRaster, multiFilter, weight, weightZoom, vectorTemplate); return(result); } }
protected IRasterDataProvider CreateOutRaster(string outFileName, RasterMaper[] inrasterMaper, float resolution) { string dir = Path.GetDirectoryName(outFileName); if (!string.IsNullOrEmpty(dir)) { if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } } IRasterDataDriver raster = RasterDataDriver.GetDriverByName("MEM") as IRasterDataDriver; CoordEnvelope outEnv = null; foreach (RasterMaper inRaster in inrasterMaper) { if (outEnv == null) { outEnv = inRaster.Raster.CoordEnvelope; } else { outEnv = outEnv.Union(inRaster.Raster.CoordEnvelope); } } float resX, resY; if (resolution != 0f) { resX = resolution; resY = resolution; } else { resX = inrasterMaper[0].Raster.ResolutionX; resY = inrasterMaper[0].Raster.ResolutionY; for (int i = 1; i < inrasterMaper.Length; i++) { if (resX > inrasterMaper[i].Raster.ResolutionX) { resX = inrasterMaper[i].Raster.ResolutionX; } if (resY > inrasterMaper[i].Raster.ResolutionY) { resY = inrasterMaper[i].Raster.ResolutionY; } } } int width = (int)(Math.Round(outEnv.Width / resX)); int height = (int)(Math.Round(outEnv.Height / resY)); string mapInfo = outEnv.ToMapInfoString(new Size(width, height)); RasterDataProvider outRaster = raster.Create(outFileName, width, height, 1, enumDataType.Int16, mapInfo) as RasterDataProvider; return(outRaster); }
internal Dictionary <string, SortedDictionary <string, double> > Stat <T>(string rasterFile, string templateName, Dictionary <string, Func <T, bool> > multiFilter, bool weight, float weightZoom, string vectorTemplate) where T : struct, IConvertible { if (string.IsNullOrWhiteSpace(rasterFile)) { return(null); } using (IRasterDataProvider dRaster = RasterDataDriver.Open(rasterFile) as IRasterDataProvider) { return(Stat <T>(dRaster, templateName, multiFilter, weight, weightZoom, vectorTemplate)); } }
private void TryGetInfosFromRasterProvider(string fname) { string extension = Path.GetExtension(fname).ToUpper(); foreach (string ext in EXTENSIONS) { if (extension == ext) { return; } } if (!File.Exists(fname)) { return; } IRasterDataProvider prd = null; IGeoDataDriver id = null; try { prd = RasterDataDriver.Open(fname) as IRasterDataProvider; if (prd != null) { _projectName = GetProjectionIdentify(prd.SpatialRef.GeographicsCoordSystem.Name); DataIdentify df = prd.DataIdentify; if (string.IsNullOrEmpty(Satellite) || Satellite.ToUpper() == "NUL") { Satellite = df.Satellite; } if (string.IsNullOrEmpty(Sensor) || Sensor.ToUpper() == "NUL") { Sensor = df.Sensor; } if (OrbitDateTime == DateTime.MinValue) { OrbitDateTime = df.OrbitDateTime; } if (string.IsNullOrWhiteSpace(Resolution) || Resolution == "NULL") { Resolution = TryGetResolution(prd.ResolutionX); } } } catch { } finally { if (prd != null) { prd.Dispose(); } } }
public bool CreateRaster(string outFileName, int bandCount, enumDataType datatype, IRasterDataProvider referProvider) { CoordEnvelope env = referProvider.CoordEnvelope; float resX = referProvider.ResolutionX; float resY = referProvider.ResolutionY; int width = referProvider.Width; int height = referProvider.Height; Project.ISpatialReference spatialRef = referProvider.SpatialRef; List <string> options = new List <string>(); options.Add("INTERLEAVE=BSQ"); options.Add("VERSION=LDF"); options.Add("WITHHDR=TRUE"); options.Add("SPATIALREF=" + spatialRef.ToProj4String()); options.Add("MAPINFO={" + 1 + "," + 1 + "}:{" + env.MinX + "," + env.MaxY + "}:{" + resX + "," + resY + "}"); //=env.ToMapInfoString(new Size(width, height)); options.Add("BANDNAMES= " + "red,nir,fir"); if (!Directory.Exists(Path.GetDirectoryName(outFileName))) { Directory.CreateDirectory(Path.GetDirectoryName(outFileName)); } using (IRasterDataDriver raster = RasterDataDriver.GetDriverByName("LDF") as IRasterDataDriver) { using (RasterDataProvider outRaster = raster.Create(outFileName, width, height, bandCount, datatype, options.ToArray()) as RasterDataProvider) { unsafe { fixed(UInt16 *ptr = output[0]) { IntPtr buffer = new IntPtr(ptr); outRaster.GetRasterBand(1).Write(0, 0, width, height, buffer, enumDataType.UInt16, width, height); } fixed(UInt16 *ptr = output[1]) { IntPtr buffer = new IntPtr(ptr); outRaster.GetRasterBand(2).Write(0, 0, width, height, buffer, enumDataType.UInt16, width, height); } fixed(UInt16 *ptr = output[2]) { IntPtr buffer = new IntPtr(ptr); outRaster.GetRasterBand(3).Write(0, 0, width, height, buffer, enumDataType.UInt16, width, height); } } return(true); } } }
private IRasterDataProvider CreateMosaicRaster(string filename, GeoInfo geoHeader, int bandCount, ISpatialReference spatialRef) { IRasterDataProvider outRaster = null; if (File.Exists(filename)) { outRaster = GeoDataDriver.Open(filename, enumDataProviderAccess.Update, null) as IRasterDataProvider; } else { float resX = 0.01f; float resY = 0.01f; float ltX = 65; float ltY = 60; int width = 8000; int height = 7000; if (geoHeader == null) { return(null); } resX = geoHeader.ResX; resY = geoHeader.ResY; ltX = geoHeader.LtX; ltY = geoHeader.LtY; width = geoHeader.Width; height = geoHeader.Height; if (spatialRef == null) { spatialRef = SpatialReference.GetDefault(); } string dir = Path.GetDirectoryName(filename); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } IRasterDataDriver raster = RasterDataDriver.GetDriverByName("LDF") as IRasterDataDriver; string bandNames = "";//CreateBandNames(bandcount); string[] options = new string[] { "INTERLEAVE=BSQ", "VERSION=LDF", "WITHHDR=TRUE", "SPATIALREF=" + spatialRef.ToProj4String(), "MAPINFO={" + 1 + "," + 1 + "}:{" + ltX + "," + ltY + "}:{" + resX + "," + resY + "}", "BANDNAMES=" + bandNames }; outRaster = raster.Create(filename, width, height, bandCount, enumDataType.UInt16, options) as RasterDataProvider; string outSolarZenithFile = Path.ChangeExtension(filename, ".SolarZenith.ldf"); using (RasterDataProvider outSolarZenithRaster = raster.Create(outSolarZenithFile, width, height, 1, enumDataType.UInt16, options) as RasterDataProvider) { } } return(outRaster); }
/// <summary> /// H2A_SM2B /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button6_Click(object sender, EventArgs e) { Action <int, string> progress = new Action <int, string>(OutProgress); string dir = textBox1.Text; string outDir = textBox2.Text; string[] files = Directory.GetFiles(dir, "*.h5"); StringBuilder msgInfo = new StringBuilder(); for (int i = 0; i < files.Length; i++) { IRasterDataProvider mainRaster = null; IRasterDataProvider locationRaster = null; string file = files[i]; try { progress((int)((i + 1f) / files.Length * 100), null); string[] openArgs = new string[] { "datasets=" + "wind_dir_selection,wind_speed_selection" }; mainRaster = RasterDataDriver.Open(file, openArgs) as IRasterDataProvider; string[] locationArgs = new string[] { "datasets=" + "wvc_lon,wvc_lat", "geodatasets=" + "wvc_lon,wvc_lat" }; locationRaster = RasterDataDriver.Open(file, locationArgs) as IRasterDataProvider; if (locationRaster == null || locationRaster.BandCount == 0) { msgInfo.AppendLine("经纬度HDF数据文件,不存在经纬度数据集[Longitude,Latitude]" + file); return; } string outFilename = Path.Combine(outDir, Path.GetFileNameWithoutExtension(file) + ".LDF"); FY3L2L3FilePrjSettings setting = new FY3L2L3FilePrjSettings(); setting.ExtArgs = new object[] { "360" }; //360代表,大于180度的经纬度值,实际需要转换 setting.LocationFile = locationRaster; setting.OutFormat = "LDF"; setting.OutPathAndFileName = outFilename; setting.OutResolutionX = 0.25f; setting.OutResolutionY = 0.25f; FY3L2L3FileProjector projector = new FY3L2L3FileProjector(); projector.Project(mainRaster, setting, SpatialReference.GetDefault(), null); } finally { if (mainRaster != null) { mainRaster.Dispose(); mainRaster = null; } if (locationRaster != null) { locationRaster.Dispose(); locationRaster = null; } } } }
private IExtractResult ISOTAlgorithm() { int FarInfraredCH = (int)_argumentProvider.GetArg("FarInfrared"); double FarInfraredZoom = (double)_argumentProvider.GetArg("FarInfrared_Zoom"); int smaping = (int)_argumentProvider.GetArg("Smaping"); int tempratureMin = (int)(((int)_argumentProvider.GetArg("TempratureMin") + 273) * FarInfraredZoom); int tempratureMax = (int)(((int)_argumentProvider.GetArg("TempratureMax") + 273) * FarInfraredZoom); int interval = (int)((int)_argumentProvider.GetArg("IntervalMax") * FarInfraredZoom); bool isOutputUncompleted = (bool)_argumentProvider.GetArg("IsOutputUncompleted"); string filename = _argumentProvider.GetArg("CurrentRasterFile") as string; using (IRasterDataProvider rasterProvider = RasterDataDriver.Open(filename) as IRasterDataProvider) { if (rasterProvider != null) { IBandNameRaster bandNameRaster = rasterProvider as IBandNameRaster; FarInfraredCH = TryGetBandNo(bandNameRaster, "FarInfrared"); } } if (FarInfraredCH == -1) { PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。"); return(null); } if (_argumentProvider.DataProvider == null) { PrintInfo("获取文件错误,可能是没有打开影像文件。"); return(null); } try { //生成等值线shp文件 string shpFile = GenISOTFiename(filename); //bool isOutputUncompleted = true; GenerateContourLines gcl = new GenerateContourLines(_progressTracker, _contextMessage); gcl.DoGenerateContourLines(_argumentProvider.DataProvider, FarInfraredCH, _argumentProvider.AOI, interval, tempratureMin, tempratureMax, smaping, shpFile, isOutputUncompleted); if (!File.Exists(shpFile)) { PrintInfo("生成等值线数据失败。"); return(null); } //根据等值线的配色表,生成等值线shp付色方案mcd文件,_legendItems CreateLegendItems(shpFile); CreateMcd(shpFile); return(new FileExtractResult(_subProductDef.Identify, shpFile, true)); } finally { } }
private IRasterDataProvider CreateOutRaster(string outFileName, int bandCount) { IRasterDataDriver raster = RasterDataDriver.GetDriverByName("LDF") as IRasterDataDriver; CoordEnvelope outEnv = _dataProvider.CoordEnvelope; float resX = _dataProvider.ResolutionX; float resY = _dataProvider.ResolutionY; int width = (int)(Math.Round(outEnv.Width / resX)); int height = (int)(Math.Round(outEnv.Height / resY)); string mapInfo = outEnv.ToMapInfoString(new Size(width, height)); RasterDataProvider outRaster = raster.Create(outFileName, width, height, bandCount, _dataProvider.DataType, mapInfo) as RasterDataProvider; return(outRaster); }
private void DirectReadGeo(int xOffset, int yOffset, int xSize, int ySize, IntPtr buffer, enumDataType dataType, int xBufferSize, int yBufferSize, int bandno) { string latlonFilename = TryFindGeoFile(); if (!File.Exists(latlonFilename)) { return; } using (IRasterDataProvider raster = RasterDataDriver.Open(latlonFilename) as IRasterDataProvider) { raster.GetRasterBand(bandno).Read(xOffset, yOffset, xSize, ySize, buffer, dataType, xBufferSize, yBufferSize); } }
private void btnOpenFile_Click(object sender, EventArgs e) { if (_maskObj != null) { _maskObj.Dispose(); } _datValue = null; using (OpenFileDialog dlg = new OpenFileDialog()) { dlg.Filter = "SMART Raster(*.dat)|*.dat|矢量数据(*.shp)|*.shp"; dlg.InitialDirectory = Path.Combine(MifEnvironment.GetWorkspaceDir(), "\\FLD"); if (dlg.ShowDialog() == DialogResult.OK) { string filename = dlg.FileName; string extName = Path.GetExtension(filename).ToUpper(); switch (extName) { case ".SHP": LoadMaskTemplateFromShapeFile(filename); if (_maskObj != null) { txtFileName.Text = _maskObj.FieldNames[0]; } _filename = filename; return; case ".DAT": using (IRasterDataProvider udr = RasterDataDriver.Open(dlg.FileName) as IRasterDataProvider) { //if (udr == null || ((Math.Abs(Math.Round(udr.CoordEnvelope.MinX, 4) - Math.Round(_leftUpCoord.X, 4)) > udr.ResolutionX // || Math.Abs(Math.Round(udr.CoordEnvelope.MaxY, 4) - Math.Round(_leftUpCoord.Y, 4)) > udr.ResolutionY) // || udr.Width != _size.Width // || udr.Height != _size.Height // || udr.ResolutionX - _resolution > 1.0E-15 // || udr.ResolutionY - _resolution > 1.0E-15)) //{ // //MsgBox.ShowInfo("选择的背景水体与当前水体位置信息不一致,请重新选择!"); // return; //} txtFileName.Text = Path.GetFileNameWithoutExtension(filename); _filename = filename; } break; default: return; } } } }
private IRasterDataProvider CreateOutRaster(RasterMaper rm) { RasterIdentify ri = new RasterIdentify(rm.Raster.fileName); ri.ProductIdentify = _subProductDef.ProductDef.Identify; ri.SubProductIdentify = _subProductDef.Identify; string outFileName = ri.ToWksFullFileName(".dat"); IRasterDataDriver raster = RasterDataDriver.GetDriverByName("MEM") as IRasterDataDriver; CoordEnvelope outEnv = rm.Raster.CoordEnvelope; string mapInfo = outEnv.ToMapInfoString(new Size(rm.Raster.Width, rm.Raster.Height)); RasterDataProvider outRaster = raster.Create(outFileName, rm.Raster.Width, rm.Raster.Height, 1, enumDataType.Int16, mapInfo) as RasterDataProvider; return(outRaster); }