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); }
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 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 string CreateNewColorTable(IRasterDataProvider prd, string fname, Action <int, string> progressTracker) { double minValue, maxValue; prd.GetRasterBand(1).ComputeMinMax(out minValue, out maxValue, false, progressTracker); IMaxMinValueComputer computer = MaxMinValueComputerFactory.GetMaxMinValueComputer(prd.DataType); IRasterBand[] bands = new IRasterBand[1] { prd.GetRasterBand(1) }; double[] minValues = new double[1]; double[] maxValues = new double[1]; double[] meanValues = new double[1]; computer.Compute(bands, null, out minValues, out maxValues, out meanValues, progressTracker); double pRatio = 1 / Math.Abs(maxValues[0]); double mRatio = 1 / Math.Abs(minValues[0]); if (maxValues[0] >= 0 && minValues[0] <= 0) { _ratio = pRatio > mRatio ? mRatio : pRatio; int width = bands[0].Width; int height = bands[0].Height; double[] oldband = new double[width * height]; unsafe { fixed(Double *ptr = oldband) { IntPtr bufferPtr = new IntPtr(ptr); bands[0].Read(0, 0, width, height, bufferPtr, enumDataType.Double, width, height); } } double[] newband = new double[width * height]; for (int i = 0; i < newband.Length; i++) { newband[i] = oldband[i] * _ratio; } //string name = Path.ChangeExtension(fname,".ldf"); string tempf = Path.GetFileNameWithoutExtension(fname) + string.Format("_{0}_{1}.ldf", _ratio.ToString("F2"), DateTime.Now.ToString("yyyyMMddHHmm")); tempf = Path.Combine(Path.GetDirectoryName(fname), tempf); if (File.Exists(tempf)) { File.Delete(tempf); } using (IRasterDataProvider tempraster = CreateRaster(tempf, prd, fname)) { IRasterBand newband1 = tempraster.GetRasterBand(1); unsafe { fixed(Double *ptr = newband) { IntPtr bufferPtr = new IntPtr(ptr); newband1.Write(0, 0, width, height, bufferPtr, enumDataType.Double, width, height); } } } return(tempf); } return(null); }