Beispiel #1
0
        protected void ResampleRaster(IRasterDataProvider srcImgRaster, IRasterDataProvider prdWriter, Action <int, string> progressCallback)
        {
            //要写成T型
            enumDataType dataType = srcImgRaster.DataType;
            Size         bufferSize = _resSettings.OutSize;
            int          srcwidth = srcImgRaster.Width, srcheight = srcImgRaster.Height;

            //执行投影
            float[] srcBandData = null, dstBandData = null;
            for (int i = 0; i < srcImgRaster.BandCount; i++)  //读取原始通道值,投影到目标区域
            {
                srcBandData = new float[srcwidth * srcwidth];
                IRasterBand srcBand = srcImgRaster.GetRasterBand(i + 1);; //
                GCHandle    srch    = GCHandle.Alloc(srcBandData, GCHandleType.Pinned);
                try
                {
                    IntPtr bufferPtr = srch.AddrOfPinnedObject();
                    srcBand.Read(0, 0, srcBand.Width, srcBand.Height, bufferPtr, dataType, srcBand.Width, srcBand.Height);
                }
                finally
                {
                    srch.Free();
                }
                AnaliysisDataPreprocess.MedianRead(srcBandData, new Size(srcwidth, srcheight), bufferSize, out dstBandData);
                IRasterBand band = prdWriter.GetRasterBand(i + 1);
                GCHandle    dsth = GCHandle.Alloc(dstBandData, GCHandleType.Pinned);
                try
                {
                    IntPtr bufferPtr = dsth.AddrOfPinnedObject();
                    band.Write(0, 0, bufferSize.Width, bufferSize.Height, bufferPtr, dataType, bufferSize.Width, bufferSize.Height);
                }
                finally
                {
                    dsth.Free();
                }
                dstBandData = null;
            }
        }
Beispiel #2
0
        /// <summary>
        /// 提取单文件的AOI区域的数据
        /// </summary>
        /// <param name="file">输入文件</param>
        /// <param name="bandNum">波段</param>
        /// <param name="fillvalue">忽略值</param>
        /// <param name="outaoiIndex">AOI在采样后外包矩形中的Index</param>
        /// <param name="subAOISize">AOI外包矩形原始大小</param>
        /// <param name="outAOISize">AOI外包矩形采样后大小</param>
        /// <param name="xoffset">AOI外包矩形在文件中的xoffset</param>
        /// <param name="yoffset">AOI外包矩形在文件中的yoffset</param>
        /// <returns></returns>
        private double[] GetResampledDataFromSubRegionOutIndex(string file, int bandNum, string[] fillvalue, int[] outaoiIndex, Size subAOISize, Size outAOISize, int xoffset, int yoffset)
        {
            bool isNeedReSample = true;

            if (subAOISize == outAOISize)
            {
                isNeedReSample = false;
            }
            double[]     standardmxi;
            enumDataType datatype   = enumDataType.Unknow;
            int          totalwidth = outaoiIndex.Length;

            using (IRasterDataProvider dataPrd = GeoDataDriver.Open(file) as IRasterDataProvider)
            {
                if (dataPrd == null)
                {
                    return(null);
                }
                datatype = dataPrd.DataType;
                switch (datatype)
                {
                case enumDataType.Byte:
                {
                    Byte[]  outDataB    = null;
                    Byte [] leftoutData = new Byte [totalwidth];
                    Byte[]  fillValues  = GetFillValues <Byte>(fillvalue, enumDataType.Byte);
                    Byte [] oriData     = GetDataValue <Byte>(dataPrd, bandNum, subAOISize.Width, subAOISize.Height, xoffset, yoffset);
                    if (isNeedReSample)
                    {
                        AnaliysisDataPreprocess.MedianRead(oriData, subAOISize, outAOISize, out outDataB);
                    }
                    else
                    {
                        outDataB = oriData;
                    }
                    for (int i = 0; i < totalwidth; i++)
                    {
                        Byte data = outDataB[outaoiIndex[i]];
                        if (fillValues != null && fillValues.LongLength > 0 && fillValues.Contains(data))
                        {
                            continue;
                        }
                        leftoutData[i] = data;
                    }
                    AnaliysisDataPreprocess.StandardDeviation(leftoutData, out standardmxi);
                    return(standardmxi);
                }

                case enumDataType.Int16:
                {
                    short[] outDataB    = null;
                    short[] leftoutData = new short[totalwidth];
                    short[] fillValues  = GetFillValues <short>(fillvalue, enumDataType.Byte);
                    short[] oriData     = GetDataValue <short>(dataPrd, bandNum, subAOISize.Width, subAOISize.Height, xoffset, yoffset);
                    if (isNeedReSample)
                    {
                        AnaliysisDataPreprocess.MedianRead(oriData, subAOISize, outAOISize, out outDataB);
                    }
                    else
                    {
                        outDataB = oriData;
                    }
                    for (int i = 0; i < totalwidth; i++)
                    {
                        short data = outDataB[outaoiIndex[i]];
                        if (fillValues != null && fillValues.LongLength > 0 && fillValues.Contains(data))
                        {
                            continue;
                        }
                        leftoutData[i] = data;
                    }
                    AnaliysisDataPreprocess.StandardDeviation(leftoutData, out standardmxi);
                    return(standardmxi);
                }

                case enumDataType.Float:
                {
                    float[] outDataB    = null;
                    float[] leftoutData = new float[totalwidth];
                    float[] fillValues  = GetFillValues <float>(fillvalue, enumDataType.Float);
                    float[] oriData     = GetDataValue <float>(dataPrd, bandNum, subAOISize.Width, subAOISize.Height, xoffset, yoffset);
                    if (isNeedReSample)
                    {
                        AnaliysisDataPreprocess.MedianRead(oriData, subAOISize, outAOISize, out outDataB);
                    }
                    else
                    {
                        outDataB = oriData;
                    }
                    for (int i = 0; i < totalwidth; i++)
                    {
                        float data = outDataB[outaoiIndex[i]];
                        if (fillValues != null && fillValues.LongLength > 0 && fillValues.Contains(data))
                        {
                            continue;
                        }
                        leftoutData[i] = data;
                    }
                    AnaliysisDataPreprocess.StandardDeviation(leftoutData, out standardmxi);
                    return(standardmxi);
                }

                default:
                    return(null);
                }
            }
        }