public void Reset(IRasterDataProvider dataProvider, int xBandNo, int yBandNo, int[] aoi, XYAxisEndpointValue endpointValues, LinearFitObject fitObj, Action <int, string> progressTracker) { _fitObj = fitObj; _dataProvider = dataProvider; _xBandNo = xBandNo; _yBandNo = yBandNo; _fileName = _dataProvider.fileName; _xBandName = Path.GetFileName(_fileName) + " (Band " + _xBandNo.ToString() + ")"; _yBandName = Path.GetFileName(_fileName) + " (Band " + _yBandNo.ToString() + ")"; _aoi = aoi; // IMaxMinValueComputer c = MaxMinValueComputerFactory.GetMaxMinValueComputer(dataProvider.DataType); double[] minValues = new double[2]; double[] maxValues = new double[2]; double[] meanValues = new double[2]; c.Compute(new IRasterBand[] { dataProvider.GetRasterBand(xBandNo), dataProvider.GetRasterBand(yBandNo) }, aoi, out minValues, out maxValues, out meanValues, progressTracker); _minValueXBand = endpointValues.MinX; _maxValueXBand = endpointValues.MaxX; _minValueYBand = endpointValues.MinY; _maxValueYBand = endpointValues.MaxY; _oMinValueX = minValues[0]; _oMaxValueX = maxValues[0]; // _visitor = ScatterPixelVisitorFactory.GetVisitor(_dataProvider.DataType); _visitor.Init(_dataProvider.GetRasterBand(xBandNo), _dataProvider.GetRasterBand(yBandNo)); }
public void Tran() { int center = 180; string inputFileName = @"E:\fy3c\FY3C_VIRR_20131015_1000M_global_CH6.tiff"; using (IRasterDataProvider inRaster = GeoDataDriver.Open(inputFileName) as IRasterDataProvider) { int bandCount = inRaster.BandCount; string outputFName = Path.ChangeExtension(inputFileName, ".180.tiff"); using (IRasterDataProvider outRaster = CreatOutputRaster(outputFName, inRaster, bandCount, null)) { int off = 18;//左右丢失的数据(黑边) //0-15000,18000 int leftPiex = 18000; int rightPiex = 18000;// byte[] band = new byte[(leftPiex - off) * 18000]; GCHandle handle = GCHandle.Alloc(band, GCHandleType.Pinned); for (int b = 0; b < bandCount; b++) { inRaster.GetRasterBand(b + 1).Read(off, 0, leftPiex - off, 18000, handle.AddrOfPinnedObject(), enumDataType.Byte, leftPiex - off, 18000); outRaster.GetRasterBand(b + 1).Write(rightPiex - off, 0, leftPiex - off, 18000, handle.AddrOfPinnedObject(), enumDataType.Byte, leftPiex - off, 18000); } handle.Free(); band = new byte[(rightPiex - off) * 18000]; handle = GCHandle.Alloc(band, GCHandleType.Pinned); for (int b = 0; b < bandCount; b++) { inRaster.GetRasterBand(b + 1).Read(leftPiex - off, 0, rightPiex - off, 18000, handle.AddrOfPinnedObject(), enumDataType.Byte, rightPiex - off, 18000); outRaster.GetRasterBand(b + 1).Write(off, 0, rightPiex - off, 18000, handle.AddrOfPinnedObject(), enumDataType.Byte, rightPiex - off, 18000); } handle.Free(); } } }
public void Reset(IRasterDataProvider dataProvider, int xBandNo, int yBandNo, double[] xBandInvalidValue, double[] yBandInvalidValue, int[] aoi, LinearFitObject fitObj, Action <int, string> progressTracker) { _fitObj = fitObj; _dataProvider = dataProvider; _xBandNo = xBandNo; _yBandNo = yBandNo; _fileName = _dataProvider.fileName; string[] filenames = _fileName.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); if (filenames.Length == 2) { _xBandName = Path.GetFileName(filenames[0]) + " (Band " + _xBandNo.ToString() + ")"; _yBandName = Path.GetFileName(filenames[1]) + " (Band " + _yBandNo.ToString() + ")"; _fileName = ""; } _aoi = aoi; // IMaxMinValueComputer c = MaxMinValueComputerFactory.GetMaxMinValueComputer(dataProvider.DataType); double[] minValues = new double[2]; double[] maxValues = new double[2]; double[] meanValues = new double[2]; c.Compute(new IRasterBand[] { dataProvider.GetRasterBand(xBandNo), dataProvider.GetRasterBand(yBandNo) }, aoi, new double[][] { xBandInvalidValue, yBandInvalidValue }, out minValues, out maxValues, out meanValues, progressTracker); _minValueXBand = minValues[0]; _maxValueXBand = maxValues[0]; _minValueYBand = minValues[1]; _maxValueYBand = maxValues[1]; _oMinValueX = _minValueXBand; _oMaxValueX = _maxValueXBand; // _visitor = ScatterPixelVisitorFactory.GetVisitor(_dataProvider.DataType); _visitor.Init(_dataProvider.GetRasterBand(xBandNo), _dataProvider.GetRasterBand(yBandNo)); }
private IRasterBand[] GetDstRasterBand(IRasterDataProvider dstRaster, FilePrjSettings prjSettings, int beginBandIndex) { IRasterBand[] bands = new IRasterBand[prjSettings.OutBandNos.Length]; int[] bandNos = prjSettings.OutBandNos; for (int i = beginBandIndex; i < bandNos.Length + beginBandIndex; i++) { if (dstRaster is IBandNameRaster) { int newBand = -1; if ((dstRaster as IBandNameRaster).TryGetBandNoFromBandName(bandNos[i], out newBand)) { bands[i] = dstRaster.GetRasterBand(newBand); } else { bands[i] = dstRaster.GetRasterBand(bandNos[i]); } } else { bands[i] = dstRaster.GetRasterBand(bandNos[i]); } } return(bands); }
public Dictionary <int, RasterQuickStatResult> Compute(IRasterDataProvider dataProvider, int[] aoi, int[] bandNos, Action <int, string> progressTracker) { if (dataProvider == null) { throw new ArgumentNullException("dataProvider"); } if (bandNos == null || bandNos.Length == 0) { throw new ArgumentNullException("bandNos"); } int minBandNo = bandNos.Min(), maxBandNo = bandNos.Max(); if (minBandNo < 1 || maxBandNo > dataProvider.BandCount) { throw new IndexOutOfRangeException("bandNo"); } // double[] minValues = new double[bandNos.Length]; double[] maxValues = new double[bandNos.Length]; double[] meanValues = new double[bandNos.Length]; IMaxMinValueComputer computer = MaxMinValueComputerFactory.GetMaxMinValueComputer(dataProvider.DataType); IRasterBand[] srcRasters = new IRasterBand[bandNos.Length]; for (int i = 0; i < bandNos.Length; i++) { srcRasters[i] = dataProvider.GetRasterBand(bandNos[i]); } // computer.Compute(srcRasters, aoi, out minValues, out maxValues, out meanValues, progressTracker); // Dictionary <int, RasterQuickStatResult> results = new Dictionary <int, RasterQuickStatResult>(); List <IRasterBand> rasterBands = new List <IRasterBand>(); int b = 0; foreach (int bandNo in bandNos) { IRasterBand rstBand = dataProvider.GetRasterBand(bandNo); rasterBands.Add(rstBand); RasterQuickStatResult result = BuildStatResult(rstBand, minValues[b], maxValues[b], meanValues[b]); if (result != null) { results.Add(bandNo, result); } b++; } // IHistogramComputer histogramComputer = HistogramComputerFactory.GetHistogramComputer(dataProvider.DataType); // if (aoi == null || aoi.Length == 0) { histogramComputer.Compute(rasterBands.ToArray(), results.Values.ToArray(), progressTracker); } else { histogramComputer.Compute(rasterBands.ToArray(), aoi, results.Values.ToArray(), progressTracker); } // return(results); }
private static unsafe void ConvertFile() { string file = @"G:\工程项目\气象局现场\SmartRelease\trunk\SystemData\FY2NOM\FY2E_latlon22882288.raw"; IRasterDataProvider dataPrd = null; try { dataPrd = GeoDataDriver.Open(file) as IRasterDataProvider; string outfile = @"D:\1.raw"; IRasterBand band = dataPrd.GetRasterBand(1); IRasterBand band2 = dataPrd.GetRasterBand(2); float[] buffer = new float[band.Width * band.Height]; fixed(float *ptr = buffer) { IntPtr bufferPtr = new IntPtr(ptr); band.Read(0, 0, dataPrd.Width, dataPrd.Height, bufferPtr, enumDataType.Float, dataPrd.Width, dataPrd.Height); } float[] buffer2 = new float[band.Width * band.Height]; fixed(float *ptr = buffer2) { IntPtr bufferPtr = new IntPtr(ptr); band2.Read(0, 0, dataPrd.Width, dataPrd.Height, bufferPtr, enumDataType.Float, dataPrd.Width, dataPrd.Height); } using (FileStream fs = new FileStream(outfile, FileMode.Create, FileAccess.Write)) { using (BinaryWriter br = new BinaryWriter(fs)) { for (int i = 0; i < buffer.Length; i++) { if (buffer[i] == 300f) { br.Write(buffer[i]); } else { br.Write(buffer[i] + 7.5f); } } for (int i = 0; i < buffer.Length; i++) { br.Write(buffer2[i]); } } } } finally { if (dataPrd != null) { dataPrd.Dispose(); } } }
private void GetData(ICanvas canvas) { //ICoordinateTransform coordTran = canvas.CoordTransform; Point[] linePts = new Point[2] { new Point(_beginPoint.RasterX, _beginPoint.RasterY), new Point(_endPoint.RasterX, _endPoint.RasterY) }; //获取采样点的值 double width; double angle = GetAngle(linePts[0].X, linePts[0].Y, linePts[1].X, linePts[1].Y, out width); Point[] dataPts = GetPointsAtLine(new PointF(linePts[0].X, linePts[0].Y), new PointF(linePts[1].X, linePts[1].Y), width, 1); if (dataPts.Length == 0) { return; } IRasterDrawing drawing = canvas.PrimaryDrawObject as IRasterDrawing; IRasterDataProvider raster = drawing.DataProviderCopy; List <Point> dataPtList = new List <Point>(); for (int i = 0; i < dataPts.Length; i++) { if (dataPts[i].X < 0 || dataPts[i].Y < 0 || dataPts[i].X >= raster.Width || dataPts[i].Y >= raster.Height) { continue; } dataPtList.Add(dataPts[i]); } if (dataPtList.Count == 0) { return; } dataPts = dataPtList.ToArray(); int[] bandNos = drawing.SelectedBandNos; _profileData.Clear(); if (bandNos.Length == 1) { IRasterBand band = raster.GetRasterBand(bandNos[0]); RasterProfileData data = GetDataAtPoints(dataPts, band); _profileData.Add(data); } else if (bandNos.Length == 3) { for (int i = 0; i < bandNos.Length; i++) { IRasterBand band = raster.GetRasterBand(bandNos[i]); RasterProfileData data = GetDataAtPoints(dataPts, band); _profileData.Add(data); } } }
public unsafe void CopyBlockToEmptyFile() { int xSize = 512; int ySize = 512; int bandCount = 20; string fname = "d:\\Ldf_Write_GeoDo.ldf"; IRasterDataDriver drv = GeoDataDriver.GetDriverByName("LDF") as IRasterDataDriver; IRasterDataProvider dstPrd = CreateEmptyFile(fname, drv, xSize, ySize, bandCount); IRasterDataProvider srcPrd = OpenLdfFile(_originalFname); UInt16[] buffer = new UInt16[xSize * ySize]; long lostTime = 0; fixed(UInt16 *ptr = buffer) { IntPtr butterPtr = new IntPtr(ptr); for (int b = 1; b <= bandCount; b++) { srcPrd.GetRasterBand(b).Read(200, 200, xSize, ySize, butterPtr, enumDataType.UInt16, xSize, ySize); Stopwatch sw = new Stopwatch(); sw.Start(); dstPrd.GetRasterBand(b).Write(0, 0, xSize, ySize, butterPtr, enumDataType.UInt16, xSize, ySize); sw.Stop(); lostTime += sw.ElapsedMilliseconds; } } srcPrd.Dispose(); dstPrd.Dispose(); Console.WriteLine("Time Only Write:" + lostTime.ToString()); }
public void DoGenerateContourLines(IRasterDataProvider dataProvider, int bandNo, int[] aoi, double[] contourValues, int sample, string shpFileName) { try { try { IContourGenerateTool tool = new ContourGenerateTool(); tool.IsOutputUncompleted = false; tool.Sample = sample; ContourLine[] cntLines = tool.Generate(dataProvider.GetRasterBand(bandNo), contourValues, aoi, _progressTracker); if (cntLines == null || cntLines.Length == 0) { PrintInfo("不存在符合指定条件的等值线!"); return; } if (shpFileName != null) { TryExport2ShapeFile(dataProvider, cntLines, shpFileName); } } finally { } } finally { } }
private void btnStat_Click(object sender, EventArgs e) { if (_dataProvider == null) { return; } try { IRasterBand band = _dataProvider.GetRasterBand(BandNo); double minValue, maxValue; string str = "正在统计({0}%)..."; band.ComputeMinMax(out minValue, out maxValue, false, (pro, tip) => { btnStat.Text = string.Format(str, pro); btnStat.Refresh(); }); txtMinValue.Text = minValue.ToString("0.####"); txtMaxValue.Text = maxValue.ToString("0.####"); } finally { btnStat.Text = "统计"; } }
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(); } } }
private void Cut(IRasterDataProvider srcDataProvider, IRasterDataProvider dstDataProvider, CutArgument args, BlockItem item, Action <int, string> progressTracker) { int rowsOfBlock; byte[] buffer = TryBuildBlockBuffer(dstDataProvider, out rowsOfBlock); int bRow = 0; int eRow = rowsOfBlock; int actualRows = 0; GCHandle handle = GCHandle.Alloc(_buffer, GCHandleType.Pinned); int srcX = item.Left; int srcY = item.Top; try { IntPtr ptr = handle.AddrOfPinnedObject(); do { actualRows = eRow - bRow; // foreach (int bNo in args.BandNos) { srcDataProvider.GetRasterBand(bNo).Read(srcX, srcY + bRow, item.Width, actualRows, ptr, srcDataProvider.DataType, dstDataProvider.Width, actualRows); dstDataProvider.GetRasterBand(bNo).Write(0, bRow, dstDataProvider.Width, actualRows, ptr, dstDataProvider.DataType, dstDataProvider.Width, actualRows); } // bRow += rowsOfBlock; eRow = Math.Min(bRow + rowsOfBlock, srcDataProvider.Height); }while (eRow < dstDataProvider.Height); } finally { handle.Free(); } }
private IRasterBand WriteCacheFile(double[] data, string fileName, int width, int height, out IRasterDataProvider cacheWriter) { string[] options = new string[] { "INTERLEAVE=BSQ", "VERSION=LDF", "WITHHDR=TRUE", }; if (_outLdfDriver == null) { _outLdfDriver = GeoDataDriver.GetDriverByName("LDF") as IRasterDataDriver; } cacheWriter = _outLdfDriver.Create(fileName, width, height, 1, enumDataType.Double, options) as IRasterDataProvider; IRasterBand band = cacheWriter.GetRasterBand(1); { unsafe { fixed(double *ptr = data) { IntPtr bufferPtr = new IntPtr(ptr); band.Write(0, 0, width, height, bufferPtr, enumDataType.Double, width, height); } } } return(band); }
private T[] ReadBandBuffer(IRasterDataProvider dataProvider, IntPtr rowPtr, int bandNo, int width, int height, int progressOffset, Action <int> progress) { T[] buffer = new T[width * height]; int rowSize = width * DataTypeHelper.SizeOf(dataProvider.DataType); GCHandle handle = GCHandle.Alloc(buffer, GCHandleType.Pinned); try { IntPtr dstptr = handle.AddrOfPinnedObject(); int sample = Math.Min(_dataProvider.Width / width, _dataProvider.Height / height); IRasterBand band = dataProvider.GetRasterBand(bandNo); int offset = 0; for (int r = 0; r < height; r++, offset += rowSize) { band.Read(0, r * sample, _dataProvider.Width, 1, rowPtr, dataProvider.DataType, width, 1); IntPtr dst = IntPtr.Add(dstptr, offset); WinAPI.MemoryCopy(dst, rowPtr, rowSize); progress(progressOffset + r); } return(buffer); } finally { handle.Free(); } }
private void BuildInternalBuffer(string fileName) { IRasterDataDriver drv = GeoDataDriver.GetDriverByName("MEM") as IRasterDataDriver; _dataProvider = drv.Create(fileName, vData.Width, vData.Height, 1, vData.DataType, GetOptions()); _rasterBand = _dataProvider.GetRasterBand(1); }
public unsafe void ReadMvgFile_noOffset_Bigger() { IGeoDataDriver drv = GeoDataDriver.GetDriverByName("MVG"); IRasterDataProvider prd = drv.Open(_fname, enumDataProviderAccess.ReadOnly) as IRasterDataProvider; Assert.NotNull(prd); IRasterBand band = prd.GetRasterBand(1); Assert.NotNull(band); Int16[] data = new Int16[prd.Width * 2 * prd.Height]; Console.WriteLine("prd.Width = " + prd.Width); Console.WriteLine("prd.Height = " + prd.Height); Console.WriteLine("band.Width = " + band.Width); Console.WriteLine("band.Height= " + band.Height); fixed(Int16 *ptr = data) { IntPtr buffer = new IntPtr(ptr); band.Read(0, 0, prd.Width, prd.Height, buffer, enumDataType.Int16, prd.Width * 2, prd.Height); } string dstFname = @"e:\mvg";//@"C:\工作\3.13\read"; WriteBandToFile(data, dstFname + "_bigger" + "_read" + ".dat"); prd.Dispose(); drv.Dispose(); }
public unsafe void ReadMvgFileNormal() { // _fname = @"C:\工作\3.13\SNW_DBLV_FY3A_VIRR_1000M_NULL_P001_200911131356.mvg"; IGeoDataDriver drv = GeoDataDriver.GetDriverByName("MVG"); IRasterDataProvider prd = drv.Open(_fname, enumDataProviderAccess.ReadOnly) as IRasterDataProvider; Assert.NotNull(prd); IRasterBand band = prd.GetRasterBand(1); Assert.NotNull(band); Int16[] data = new Int16[prd.Width * prd.Height]; Console.WriteLine("prd.Width = " + prd.Width); Console.WriteLine("prd.Height = " + prd.Height); Console.WriteLine("band.Width = " + band.Width); Console.WriteLine("band.Height= " + band.Height); fixed(Int16 *ptr = data) { IntPtr buffer = new IntPtr(ptr); band.Read(0, 0, prd.Width, prd.Height, buffer, enumDataType.Int16, prd.Width, prd.Height); } string dstFname = @"e:\mvg";//@"C:\工作\3.13\read"; WriteBandToFile(data, dstFname + "_normal" + "_read" + ".dat"); prd.Dispose(); drv.Dispose(); }
private void WriteData(float[] data, string fileName, int width, int height) { string[] options = new string[] { "INTERLEAVE=BSQ", "VERSION=LDF", "WITHHDR=TRUE", }; if (_outLdfDriver == null) { _outLdfDriver = GeoDataDriver.GetDriverByName("LDF") as IRasterDataDriver; } IRasterDataProvider cacheWriter = _outLdfDriver.Create(fileName, width, height, 1, enumDataType.Float, options) as IRasterDataProvider; { using (IRasterBand band = cacheWriter.GetRasterBand(1)) { unsafe { fixed(float *ptr = data) { IntPtr bufferPtr = new IntPtr(ptr); band.Write(0, 0, width, height, bufferPtr, enumDataType.Float, width, height); } } } } _solarZenithCacheRaster = cacheWriter; }
private void BuildCalcBuffer(string fileName) { IRasterDataDriver drv = GeoDataDriver.GetDriverByName("MEM") as IRasterDataDriver; _outputCalcDataProvider = drv.Create(fileName, vData.Width, vData.Height, 1, CalcType, GetOptions()); _outputCalcRasterBand = _outputCalcDataProvider.GetRasterBand(1); }
public void Compute(IRasterDataProvider dataProvider, string expression, string outDriver, string outFile, Action <int, string> progressTracker) { if (dataProvider == null || string.IsNullOrWhiteSpace(expression) || string.IsNullOrWhiteSpace(outDriver) || string.IsNullOrWhiteSpace(outFile)) { throw new ArgumentNullException(); } IGeoDataDriver driver = GeoDataDriver.GetDriverByName(outDriver); if (driver == null) { throw new Exception("driver '" + outDriver + "' is not existed."); } IRasterDataProvider dstProvider = CreateDstDataProvider(driver as IRasterDataDriver, outFile, dataProvider); if (dataProvider == null) { throw new Exception("use '" + outDriver + "'create RasterDataProvider is failed."); } try { Compute(dataProvider, expression, dstProvider.GetRasterBand(1), progressTracker); } finally { dstProvider.Dispose(); driver.Dispose(); } }
public unsafe void WriteWithSample() { int xSize = 512; int ySize = 512; int bandCount = 20; int dstWith = 2000; int dstHeight = 2000; string fname = "d:\\Ldf_Write_GeoDo_Sample.ldf"; IRasterDataDriver drv = GeoDataDriver.GetDriverByName("LDF") as IRasterDataDriver; IRasterDataProvider dstPrd = CreateEmptyFile(fname, drv, dstWith, dstHeight, bandCount); IRasterDataProvider srcPrd = OpenLdfFile(_originalFname); UInt16[] buffer = new UInt16[xSize * ySize]; fixed(UInt16 *ptr = buffer) { IntPtr butterPtr = new IntPtr(ptr); for (int b = 1; b <= bandCount; b++) { srcPrd.GetRasterBand(b).Read(200, 200, xSize, ySize, butterPtr, enumDataType.UInt16, xSize, ySize); dstPrd.GetRasterBand(b).Write(0, 0, dstWith, dstHeight, butterPtr, enumDataType.UInt16, xSize, ySize); } } srcPrd.Dispose(); dstPrd.Dispose(); }
public void GetBandData() { string fname = "d:\\NOAA18_AVHRR_CHINA_L1_20090806_N3_1000M.dat"; IRasterDataDriver drv = GeoDataDriver.GetDriverByName("GDAL") as IRasterDataDriver; IRasterDataProvider prd = drv.Open(fname, enumDataProviderAccess.ReadOnly) as IRasterDataProvider;// GeoDataDriver.Open(fname) as IRasterDataProvider; IRasterBand rb = prd.GetRasterBand(3); UInt16[] buffer = new UInt16[prd.Width * prd.Height]; unsafe { fixed(UInt16 *ptr = buffer) { IntPtr bufferPtr = new IntPtr(ptr); //prd.Read(0, 0, prd.Width, prd.Height, bufferPtr, enumDataType.UInt16, prd.Width, prd.Height, 1, new int[] { 1 }, enumInterleave.BSQ); rb.Read(0, 0, prd.Width, prd.Height, bufferPtr, enumDataType.UInt16, prd.Width, prd.Height); } } string filename = "d:\\d.dat"; FileStream fs = new FileStream(filename, FileMode.Create); BinaryWriter bw = new BinaryWriter(fs); for (int i = 0; i < buffer.Length; i++) { bw.Write(buffer[i]); } fs.Close(); }
private unsafe void SaveToDBLVFile(string inputFileName, string outputDir, float[] ndviValue) { int width, height; width = height = GetFileSize(inputFileName); string dblvFilename = Path.Combine(outputDir, GetFileName(inputFileName, "BAG", "DBLV")); using (IRasterDataProvider outProvider = CreatOutputRaster(dblvFilename, enumDataType.Int16, width, height)) { Int16[] dblvValues = new Int16[width]; fixed(Int16 *outPtr = dblvValues) { //写数据 for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { if (ndviValue[i * width + j] == -9999) { dblvValues[j] = 0; } else { dblvValues[j] = 1; } } IntPtr outBuffer = new IntPtr(outPtr); outProvider.GetRasterBand(1).Write(0, i, width, 1, outBuffer, enumDataType.Int16, width, 1); } } } }
private void WriteDataToLDF <T>(IRasterDataProvider prdWriter, enumDataType dataType, int outWidth, int rowStep, int oRow, T[] dstBandData, int b, double dataweight, float zoom) { IRasterBand band = null; for (int i = 0; i < dstBandData.Length; i++) { dstBandData[i] = (T)Convert.ChangeType(Convert.ToDouble(dstBandData[i]) * dataweight * zoom, typeof(T)); } try { band = prdWriter.GetRasterBand(b + 1); GCHandle h = GCHandle.Alloc(dstBandData, GCHandleType.Pinned); try { IntPtr bufferPtr = h.AddrOfPinnedObject(); band.Write(0, oRow, outWidth, rowStep, bufferPtr, dataType, outWidth, rowStep); } finally { h.Free(); } } finally { //这里不能释放,由于大部分band是记录在RasterDataProvider中的数组中的,如果释放后,下次取就会出错 //if (band!=null&&band is IGDALRasterBand) //{ // band.Dispose(); //} } }
private unsafe void Byte_IDWinterpolation(IRasterDataProvider rasDestPrd, double resolutionX, double resolutionY, int nWidth, int nHeight, CoordEnvelope CoordEnv, Action <int, string> progressCallback) { byte[] lineArray = new byte[nWidth]; fixed(byte *linePtr = lineArray) { IntPtr lineBuffer = new IntPtr(linePtr); for (int i = 0; i < nHeight; i++) { double crtY = CoordEnv.MaxY - resolutionY * i - resolutionY / 2; for (int j = 0; j < nWidth; j++) { double crtX = CoordEnv.MinX + resolutionX * j + resolutionX / 2; lineArray[j] = Convert.ToByte(CalPointValue(crtX, crtY)); } rasDestPrd.GetRasterBand(1).Write(0, i, nWidth, 1, lineBuffer, enumDataType.Byte, nWidth, 1); double dPercent = 100.0 * (i + 1) / nHeight; if (progressCallback != null) { progressCallback(Convert.ToInt32(dPercent), "空间插值完成" + Convert.ToInt32(dPercent) + "%"); } } } }
private void WriteDataToLDF <T>(IRasterDataProvider prdWriter, enumDataType dataType, int outWidth, int rowStep, int oRow, T[] dstBandData, int b) { IRasterBand band = null; try { band = prdWriter.GetRasterBand(b + 1); GCHandle h = GCHandle.Alloc(dstBandData, GCHandleType.Pinned); try { IntPtr bufferPtr = h.AddrOfPinnedObject(); band.Write(0, oRow, outWidth, rowStep, bufferPtr, dataType, outWidth, rowStep); } finally { h.Free(); } } finally { //这里不能释放,由于大部分band是记录在RasterDataProvider中的数组中的,如果释放后,下次取就会出错 //if (band!=null&&band is IGDALRasterBand) //{ // band.Dispose(); //} } }
private void button11_Click(object sender, EventArgs e) { IRasterDataProvider prd = GetRasterDataProvider(); string fname = prd.fileName; // IContourGenerateTool tool = new ContourGenerateTool(); double[] contourValues = new double[] { 0.15d }; // Stopwatch sw = new Stopwatch(); sw.Start(); // ContourLine[] cLines = tool.Generate(prd.GetRasterBand(1), contourValues, (pro, stip) => { Text = pro.ToString() + "%," + stip; } ); // sw.Stop(); Text = "GenerateContour: " + sw.ElapsedMilliseconds.ToString(); // DrawContourLine(prd, cLines); // prd.Dispose(); // Text = "GenerateContour: " + sw.ElapsedMilliseconds.ToString() + ",and drawed."; }
private void BuildInternalBuffer(string _fileName) { IRasterDataDriver drv = GeoDataDriver.GetDriverByName("MEM") as IRasterDataDriver; _dataProvider = drv.Create(_fileName, _size.Width, _size.Height, 1, GetDataType(), GetOptions()); _rasterValues = _dataProvider.GetRasterBand(1); }
public void ToRaster(string[] cloudsatfiles, int bandNo, int heightLevel, IRasterDataProvider oraster) { _cloudsatfiles = cloudsatfiles; _bandNo = bandNo; _band = oraster.GetRasterBand(1); _heightLevel = heightLevel; int ox = oraster.Width; int oy = oraster.Height; float resolutionx = oraster.ResolutionX; float resolutiony = oraster.ResolutionY; Size osize = new Size(oraster.Width, oraster.Height); GeoDo.RSS.Core.DF.CoordEnvelope env = oraster.CoordEnvelope; short[] refValues = new short[ox * oy]; for (int i = 0; i < _cloudsatfiles.Length; i++) { float[] latitudes; float[] longitudes; int h; string fullfilename = _cloudsatfiles[i]; int cou, minX, maxX; short[] datas = null; int level = _heightLevel;// int xn; using (CloudsatDataProvider raster = GeoDataDriver.Open(fullfilename) as CloudsatDataProvider) { CloudSatRasterBand band = raster.GetRasterBand(_bandNo) as CloudSatRasterBand; h = band.Height;//37081 latitudes = raster.ReadVdata("Latitude", null, 0, h) as float[]; longitudes = raster.ReadVdata("Longitude", null, 0, h) as float[]; cou = 0; minX = 0; maxX = h; IntersectEnvelope(latitudes, longitudes, env, ref cou, ref minX, ref maxX); xn = maxX - minX + 1; datas = readData(new int[] { minX, level }, new int[] { xn, 1 }, band); } if (cou > 0 && (minX != 0 || maxX != h)) { float[] lats = new float[xn]; float[] longs = new float[xn]; Buffer.BlockCopy(latitudes, minX * 4, lats, 0, xn * 4); Buffer.BlockCopy(longitudes, minX * 4, longs, 0, xn * 4); latitudes = lats; longitudes = longs; } PointProjection.PointToRasterInt16(longitudes, latitudes, datas, env, resolutionx, resolutiony, osize, ref refValues); } GCHandle handle = GCHandle.Alloc(refValues, GCHandleType.Pinned); try { _band.Write(0, 0, ox, oy, handle.AddrOfPinnedObject(), enumDataType.Int16, ox, oy); } finally { handle.Free(); } }
private unsafe void DoBandLevelTask(BandLevelTask bandLevelTask) { _isDoingLargerTask = true; try { string fname = _cacheNameHelper.GetCacheFilename(_cacheFolder, bandLevelTask.BandNo, bandLevelTask.Level.No); using (FileStream fs = new FileStream(fname, FileMode.Create, FileAccess.ReadWrite, FileShare.Read)) { using (BinaryWriter bw = new BinaryWriter(fs)) { IRasterBand band = _dataProvider.GetRasterBand(bandLevelTask.BandNo); int tCount = bandLevelTask.Level.Tiles.Length; TileId[] tiles = bandLevelTask.Level.Tiles; TileId tile; LevelId lv = bandLevelTask.Level; byte[] data = new byte[_tileBufferSize]; fixed(byte *ptr = data) { IntPtr buffer = new IntPtr(ptr); for (int i = 0; i < tCount; i++) { tile = tiles[i]; band.Read( (int)(_tileSize * tile.Col / lv.Scale), (int)(_tileSize * tile.Row / lv.Scale), (int)(tile.Width / lv.Scale), (int)(tile.Height / lv.Scale), buffer, _dataProvider.DataType, tile.Width, tile.Height); bw.Write(data); // if (_needPauseLargerTask) { Console.WriteLine("需要暂停长任务。"); _needPauseLargerTask = false; } } } } } } finally { _isDoingLargerTask = false; } }