示例#1
0
        public unsafe IExtractResult Do(string productIdentify, string subProductIdentify, IRasterDataProvider dataProvider, string filename, out string error)
        {
            error = string.Empty;
            if (!CanDo(productIdentify, subProductIdentify, filename, out error))
            {
                return(null);
            }
            if (_transDef == null)
            {
                _transDef = (new MVGXMLParser()).GetTransDef();
            }
            ProductDef       product    = _transDef.GetProductBySmartProductIdentify(productIdentify);
            SubProductDef    subProduct = product.GetSubProductBySmartIdentfy(subProductIdentify);
            IGeoDataProvider provider   = GeoDataDriver.Open(filename, enumDataProviderAccess.ReadOnly, null);

            if (provider != null)
            {
                MvgDataProvider mvgProvider = provider as MvgDataProvider;
                if (mvgProvider == null)
                {
                    error = "MVG转换尚不支持文件【" + Path.GetFileName(filename) + "】!";
                    return(null);
                }
                float  xResolution = dataProvider.ResolutionX, mvgXResolution = (float)mvgProvider.CoordEnvelope.Width / mvgProvider.Width;
                float  yResolution = dataProvider.ResolutionY, mvgYResolution = (float)mvgProvider.CoordEnvelope.Height / mvgProvider.Height;
                int    width = dataProvider.Width, mvgWidth = mvgProvider.Width;
                double minX = dataProvider.CoordEnvelope.MinX, mvgMinX = mvgProvider.CoordEnvelope.MinX;
                double maxY = dataProvider.CoordEnvelope.MaxY, mvgMaxY = mvgProvider.CoordEnvelope.MaxY;
                int    xIndex = 0;
                int    yIndex = 0;
                if (dataProvider.DataType == enumDataType.UInt16)
                {
                    Int16[] dataBlock = new Int16[mvgProvider.Width * mvgProvider.Height];
                    fixed(Int16 *buffer = dataBlock)
                    {
                        IntPtr ptr = new IntPtr(buffer);

                        mvgProvider.Read(0, 0, mvgProvider.Width, mvgProvider.Height, ptr, enumDataType.Int16, mvgProvider.Width, mvgProvider.Height, 1, new int[] { 1 }, enumInterleave.BSQ);
                    }

                    Dictionary <Int16, Int16>    dic     = subProduct.GetTableDic <Int16, Int16>();
                    IPixelIndexMapper            map     = PixelIndexMapperFactory.CreatePixelIndexMapper(productIdentify + "_" + subProductIdentify, width, dataProvider.Height, dataProvider.CoordEnvelope, dataProvider.SpatialRef);
                    RasterPixelsVisitor <UInt16> visitor = new RasterPixelsVisitor <UInt16>(new ArgumentProvider(dataProvider, null));
                    visitor.VisitPixel(new int[] { 1 }, (index, values) =>
                    {
                        xIndex = (int)Math.Round((minX + (index % width * xResolution) - mvgMinX) / mvgXResolution);
                        yIndex = (int)Math.Round((mvgMaxY - (maxY - (index / width * yResolution))) / mvgYResolution);
                        if (xIndex >= 0 && yIndex >= 0 && yIndex * mvgWidth + xIndex < dataBlock.Length)
                        {
                            if (dic.ContainsKey(dataBlock[yIndex * mvgWidth + xIndex]))
                            {
                                map.Put(index);
                            }
                        }
                    });
                    return(map);
                }
            }
            return(null);
        }
示例#2
0
        private IExtractResult FIRGAlgorithm()
        {
            IRasterDataProvider prd            = _argumentProvider.DataProvider;
            IBandNameRaster     bandNameRaster = prd as IBandNameRaster;
            int    VisibleCH        = TryGetBandNo(bandNameRaster, "Visible");
            int    NearInfraredCH   = TryGetBandNo(bandNameRaster, "NearInfrared");
            int    FarInfraredCH    = TryGetBandNo(bandNameRaster, "FarInfrared");
            double VisibleZoom      = (double)_argumentProvider.GetArg("Visible_Zoom");
            double NearInfraredZoom = (double)_argumentProvider.GetArg("NearInfrared_Zoom");
            double FarInfraredZoom  = (double)_argumentProvider.GetArg("FarInfrared_Zoom");

            if (VisibleCH == -1 || FarInfraredCH == -1 || NearInfraredCH == -1)
            {
                PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。");
                return(null);
            }

            string express = string.Format(@"NDVI(band{1},band{0})  <= var_NDVIMax &&
                                             band{0}/" + VisibleZoom + @"f <= var_VisibleMax &&
                                             band{1}/" + NearInfraredZoom + @"f <= var_NearInfraredMax &&
                                             band{2}/" + FarInfraredZoom + @"f >= var_FarInfraredMin",
                                           VisibleCH, NearInfraredCH, FarInfraredCH);

            int[] bandNos = new int[] { VisibleCH, NearInfraredCH, FarInfraredCH };
            IThresholdExtracter <Int16> extracter = new SimpleThresholdExtracter <Int16>();

            extracter.Reset(_argumentProvider, bandNos, express);

            IPixelIndexMapper result = PixelIndexMapperFactory.CreatePixelIndexMapper("FIRE", prd.Width, prd.Height, prd.CoordEnvelope, prd.SpatialRef);

            extracter.Extract(result);
            result.Tag = new FirGFeatureCollection("火区辅助信息", GetDisplayInfo(VisibleCH, NearInfraredCH, FarInfraredCH));
            return(result);
        }
示例#3
0
        private IExtractResult ThresholdExtractMersi()
        {
            IBandNameRaster bandNameRaster    = _argumentProvider.DataProvider as IBandNameRaster;
            int             ShortInfraredCH   = TryGetBandNo(bandNameRaster, "ShortInfrared");
            int             FarInfrared11CH   = TryGetBandNo(bandNameRaster, "FarInfrared11");
            int             VisibleCH         = TryGetBandNo(bandNameRaster, "Visible");
            double          VisibleZoom       = (double)_argumentProvider.GetArg("Visible_Zoom");
            double          FarInfrared11Zoom = (double)_argumentProvider.GetArg("FarInfrared11_Zoom");
            double          ShortInfraredZoom = (double)_argumentProvider.GetArg("ShortInfrared_Zoom");

            if (FarInfrared11CH == -1 || VisibleCH == -1 || ShortInfraredCH == -1)
            {
                PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。");
                return(null);
            }

            string express = string.Format(@" band{0}/" + VisibleZoom + @"f  > var_VisibleMin && band{0}/" + VisibleZoom + @"f  < var_VisibleMax &&
                                              band{1}/" + FarInfrared11Zoom + @"f  > var_FarInfrared11Min && band{1}/" + FarInfrared11Zoom + @"f  < var_FarInfrared11Max && 
                                              band{2}/" + ShortInfraredZoom + @"f  > var_NearInfraredMin && band{2}/" + ShortInfraredZoom + @"f  < var_NearInfraredMax && 
                                              NDVI(band{0},band{2}) > var_NDSIMin && NDVI(band{0},band{2}) < var_NDSIMax",
                                           VisibleCH, FarInfrared11CH, ShortInfraredCH);

            int[] bandNos = new int[] { VisibleCH, FarInfrared11CH, ShortInfraredCH };
            IThresholdExtracter <UInt16> extracter = new SimpleThresholdExtracter <UInt16>();

            extracter.Reset(_argumentProvider, bandNos, express);
            IRasterDataProvider prd    = _argumentProvider.DataProvider;
            IPixelIndexMapper   result = PixelIndexMapperFactory.CreatePixelIndexMapper("FOG", prd.Width, prd.Height, prd.CoordEnvelope, prd.SpatialRef);

            extracter.Extract(result);
            return(result);
        }
示例#4
0
        private IExtractResult ThresholdExtractRGB()
        {
            IBandNameRaster bandNameRaster = _argumentProvider.DataProvider as IBandNameRaster;
            int             RedCH          = TryGetBandNo(bandNameRaster, "Red");
            double          RedZoom        = (double)_argumentProvider.GetArg("Red_Zoom");

            if (RedCH == -1)
            {
                PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。");
                return(null);
            }

            int    GreenCH   = TryGetBandNo(bandNameRaster, "Green");
            double GreenZoom = (double)_argumentProvider.GetArg("Green_Zoom");

            if (GreenCH == -1)
            {
                PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。");
                return(null);
            }

            int    BlueCH   = TryGetBandNo(bandNameRaster, "Blue");
            double BlueZoom = (double)_argumentProvider.GetArg("Blue_Zoom");

            if (BlueCH == -1)
            {
                PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。");
                return(null);
            }
            string express = string.Format(@"(band{0}/" + RedZoom + @"f  > var_RedMin && band{0}/" + RedZoom + @"f  < var_RedMax)&&
                                            (band{1}/" + GreenZoom + @"f  > var_GreenMin && band{1}/" + GreenZoom + @"f  < var_GreenMax)&&
                                            (band{2}/" + BlueZoom + @"f  > var_BlueMin && band{2}/" + BlueZoom + @"f  < var_BlueMax)", RedCH, GreenCH, BlueCH);

            try
            {
                int[] bandNos = new int[] { RedCH, GreenCH, BlueCH };
                if (_argumentProvider.DataProvider.DataType == enumDataType.Byte)
                {
                    IThresholdExtracter <byte> extracter = new SimpleThresholdExtracter <byte>();//这里如果用uint16时候,系统会出现崩溃
                    extracter.Reset(_argumentProvider, bandNos, express);
                    IRasterDataProvider prd    = _argumentProvider.DataProvider;
                    IPixelIndexMapper   result = PixelIndexMapperFactory.CreatePixelIndexMapper("FOG", prd.Width, prd.Height, prd.CoordEnvelope, prd.SpatialRef);
                    extracter.Extract(result);
                    return(result);
                }
                else
                {
                    PrintInfo("非真彩色数据,数据类型不是byte的。");
                    return(null);
                }
            }
            catch (Exception ex)
            {
                PrintInfo(ex.Message);
                return(null);
            }
        }
示例#5
0
        public override IExtractResult Make(Action <int, string> progressTracker, IContextMessage contextMessage)
        {
            _contextMessage = contextMessage;
            if (_argumentProvider == null || _argumentProvider.DataProvider == null)
            {
                return(null);
            }
            string algname = _argumentProvider.GetArg("AlgorithmName").ToString();

            if (string.IsNullOrEmpty(algname))
            {
                PrintInfo("参数\"AlgorithmName\"为空。");
                return(null);
            }
            if (algname == "SNWExtract")
            {
                IBandNameRaster bandNameRaster = _argumentProvider.DataProvider as IBandNameRaster;
                int             visiBandNo     = TryGetBandNo(bandNameRaster, "Visible");
                int             sIBandNo       = TryGetBandNo(bandNameRaster, "ShortInfrared");
                int             fIBandNo       = TryGetBandNo(bandNameRaster, "FarInfrared");
                double          visiBandZoom   = (double)_argumentProvider.GetArg("Visible_Zoom");
                double          siBandZoom     = (double)_argumentProvider.GetArg("ShortInfrared_Zoom");
                double          fiBandZoom     = (double)_argumentProvider.GetArg("FarInfrared_Zoom");
                if (visiBandNo <= 0 || sIBandNo <= 0 || fIBandNo <= 0 || visiBandZoom <= 0 || siBandZoom <= 0 || fiBandZoom <= 0)
                {
                    PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。");
                    return(null);
                }
                string express = string.Format(@"(band{1}/{4}f > var_ShortInfraredMin) && (band{1}/{4}f< var_ShortInfraredMax) && 
                                (band{2}/{5}f< var_FarInfraredMax) && (band{2}/{5}f > var_FarInfraredMin) && (band{0}/{3}f> var_VisibleMin) && 
                                ((float)(band{0}/{3}f-band{1}/{4}f)/(band{0}/{3}f+band{1}/{4}f)> var_NDSIMin) && 
                                ((float)(band{0}/{3}f-band{1}/{4}f)/(band{0}/{3}f+band{1}/{4}f)< var_NDSIMax)&&
                                (band{0}/{3}f< var_VisibleMax)", visiBandNo, sIBandNo, fIBandNo, visiBandZoom, siBandZoom, fiBandZoom);
                int[]  bandNos = new int[] { visiBandNo, sIBandNo, fIBandNo };
                IThresholdExtracter <UInt16> extracter = new SimpleThresholdExtracter <UInt16>();
                extracter.Reset(_argumentProvider, bandNos, express);
                int width  = _argumentProvider.DataProvider.Width;
                int height = _argumentProvider.DataProvider.Height;
                IPixelIndexMapper result = PixelIndexMapperFactory.CreatePixelIndexMapper("SNW", width, height, _argumentProvider.DataProvider.CoordEnvelope, _argumentProvider.DataProvider.SpatialRef);
                try
                {
                    SnwFeatureCollection featureInfo = SnwDisplayInfo.GetDisplayInfo(_argumentProvider, visiBandNo, sIBandNo, fIBandNo);
                    result.Tag = featureInfo;
                }
                catch
                {
                    result.Tag = new SnwFeatureCollection("积雪辅助信息计算失败", null);
                }
                extracter.Extract(result);
                return(result);
            }
            else
            {
                PrintInfo("指定的算法\"" + algname + "\"没有实现。");
                return(null);
            }
        }
示例#6
0
        private IPixelIndexMapper DoMake(string express, int[] bandNos, double[] bandZooms)
        {
            IInterestedPixelExtracter extracter = CreateThresholdExtracter(_argumentProvider.DataProvider.DataType);
            Size size = new Size(_argumentProvider.DataProvider.Width, _argumentProvider.DataProvider.Height);
            IPixelIndexMapper result = PixelIndexMapperFactory.CreatePixelIndexMapper("FIR", size.Width, size.Height, _argumentProvider.DataProvider.CoordEnvelope, _argumentProvider.DataProvider.SpatialRef);

            extracter.Reset(_argumentProvider, bandNos, express);
            extracter.Extract(result);
            return(result);
        }
示例#7
0
 private void CreateMapper(IArgumentProvider argProvider)
 {
     if (_candidateFirPixels != null)
     {
         _candidateFirPixels.Dispose();
     }
     if (_waitingFirPixels != null)
     {
         _waitingFirPixels.Dispose();
     }
     _candidateFirPixels = PixelIndexMapperFactory.CreatePixelIndexMapper("FIR", argProvider.DataProvider.Width, argProvider.DataProvider.Height, argProvider.DataProvider.CoordEnvelope, argProvider.DataProvider.SpatialRef);
     _waitingFirPixels   = PixelIndexMapperFactory.CreatePixelIndexMapper("FIR", argProvider.DataProvider.Width, argProvider.DataProvider.Height, argProvider.DataProvider.CoordEnvelope, argProvider.DataProvider.SpatialRef);
 }
示例#8
0
        private unsafe IPixelIndexMapper CreataPixelMapper(string currDBLV, out List <int> vertifyIndexiex)
        {
            IPixelIndexMapper dblvInfo = null;

            vertifyIndexiex = new List <int>();
            using (IRasterDataProvider gd = GeoDataDriver.Open(currDBLV) as IRasterDataProvider)
            {
                string fiifFile = GetFirePointIndeiex.GetFireIndexiexFilename(currDBLV);
                dblvInfo = PixelIndexMapperFactory.CreatePixelIndexMapper("FIR", gd.Width, gd.Height, gd.CoordEnvelope, gd.SpatialRef);
                int[] indexiex = null;
                if (!string.IsNullOrEmpty(fiifFile))
                {
                    GetFirePointIndeiex.ReadFireIndexiexFilename(_argumentProvider, out indexiex);
                    dblvInfo.Put(indexiex);
                }
                Int16[]     dataBlock = new Int16[gd.Width * gd.Height];
                IRasterBand band      = gd.GetRasterBand(1);
                fixed(Int16 *buffer = dataBlock)
                {
                    IntPtr ptr = new IntPtr(buffer);

                    band.Read(0, 0, gd.Width, gd.Height, ptr, enumDataType.Int16, gd.Width, gd.Height);
                }

                int length = dataBlock.Length;
                if (string.IsNullOrEmpty(fiifFile))
                {
                    for (int i = 0; i < length; i++)
                    {
                        if (dataBlock[i] == (Int16)1)
                        {
                            dblvInfo.Put(i);
                            vertifyIndexiex.Add(i);
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < length; i++)
                    {
                        if (dataBlock[i] == (Int16)1)
                        {
                            vertifyIndexiex.Add(i);
                        }
                    }
                }
            }
            return(dblvInfo);
        }
示例#9
0
        private void SandExtructTest(string fname, Dictionary <string, object> args, string express, int[] bandNos, string saveName)
        {
            //构造参数提供者
            IRasterDataProvider prd    = GeoDataDriver.Open(fname) as IRasterDataProvider;
            ArgumentProvider    argprd = new ArgumentProvider(prd, args);
            //构造判识表达式
            //构造基于阈值的判识器
            IThresholdExtracter <UInt16> extracter = new SimpleThresholdExtracter <UInt16>();

            extracter.Reset(argprd, bandNos, express);
            //判识
            result = PixelIndexMapperFactory.CreatePixelIndexMapper("DST", prd.Width, prd.Height, prd.CoordEnvelope, prd.SpatialRef);
            Stopwatch sw = new Stopwatch();

            sw.Start();
            extracter.Extract(result);
            idxs = result.Indexes.ToArray();
            sw.Stop();
            Text = sw.ElapsedMilliseconds.ToString();
            //判识结果生成二值位图
            IBinaryBitmapBuilder builder = new BinaryBitmapBuilder();
            Size   bmSize = new Size(prd.Width / 2, prd.Height / 2);
            Bitmap bitmap = builder.CreateBinaryBitmap(bmSize, Color.Red, Color.White);

            builder.Fill(idxs, new Size(prd.Width, prd.Height), ref bitmap);
            bitmap.Save(saveName, ImageFormat.Png);
            //判识结果永久保存
            RasterIdentify id = new RasterIdentify();

            id.ThemeIdentify      = "CMA";
            id.ProductIdentify    = "SANDDUST";
            id.SubProductIdentify = "2VAL";
            id.Satellite          = "FY3A";
            id.Sensor             = "MERSI";
            id.Resolution         = "1000M";
            id.OrbitDateTime      = DateTime.Now.Subtract(new TimeSpan(1, 0, 0, 0, 0));
            id.GenerateDateTime   = DateTime.Now;
            IInterestedRaster <UInt16> iir = new InterestedRaster <UInt16>(id, new Size(prd.Width, prd.Height), prd.CoordEnvelope.Clone());

            iir.Put(idxs, 1);
            iir.Dispose();
        }
示例#10
0
        public override IExtractResult Make(Action <int, string> progressTracker)
        {
            if (_argumentProvider == null || _argumentProvider.DataProvider == null)
            {
                return(null);
            }
            string algname = _argumentProvider.GetArg("AlgorithmName").ToString();

            if (string.IsNullOrEmpty(algname))
            {
                return(null);
            }
            if (algname == "AquaticExtract")
            {
                int    visiBandNo   = (int)_argumentProvider.GetArg("Visible");
                int    sIBandNo     = (int)_argumentProvider.GetArg("ShortInfrared");
                int    fIBandNo     = (int)_argumentProvider.GetArg("FarInfrared");
                double visiBandZoom = (double)_argumentProvider.GetArg("Visible_Zoom");
                double siBandZoom   = (double)_argumentProvider.GetArg("ShortInfrared_Zoom");
                double fiBandZoom   = (double)_argumentProvider.GetArg("FarInfrared_Zoom");
                if (visiBandNo <= 0 || sIBandNo <= 0 || fIBandNo <= 0 || visiBandZoom == 0 || siBandZoom == 0 || fiBandZoom == 0)
                {
                    return(null);
                }
                string express = string.Format(@"((band{2}/{5}f-band{0}/{3}f)==0 || {3}==0||{4}==0||{5}==0)? 
                                 false :((float)(band{1}/{4}f-band{0}/{3}f)/(band{2}/{5}f-band{0}/{3}f)< var_AquaExtractMax 
                                 && (float)(band{1}/{4}f-band{0}/{3}f)/(band{2}/{5}f-band{0}/{3}f)>var_AquaExtractMin)",
                                               visiBandNo, sIBandNo, fIBandNo, visiBandZoom, siBandZoom, fiBandZoom);
                int[] bandNos = new int[] { visiBandNo, sIBandNo, fIBandNo };
                IThresholdExtracter <UInt16> extracter = new SimpleThresholdExtracter <UInt16>();
                extracter.Reset(_argumentProvider, bandNos, express);
                int width  = _argumentProvider.DataProvider.Width;
                int height = _argumentProvider.DataProvider.Height;
                IPixelIndexMapper memResult = PixelIndexMapperFactory.CreatePixelIndexMapper("BAG", width, height, _argumentProvider.DataProvider.CoordEnvelope, _argumentProvider.DataProvider.SpatialRef);
                extracter.Extract(memResult);
                return(memResult);
            }
            return(null);
        }
示例#11
0
        private IExtractResult GenerateExtractResult(string gfrFile, IRasterDataProvider dataPrd)
        {
            IPixelIndexMapper result   = PixelIndexMapperFactory.CreatePixelIndexMapper("FIR", dataPrd.Width, dataPrd.Height, dataPrd.CoordEnvelope, dataPrd.SpatialRef);
            Dataset           _dataset = Gdal.Open(gfrFile, Access.GA_ReadOnly);

            if (_dataset.RasterCount == 0)
            {
                return(result);
            }
            else
            {
                CoordEnvelope envelope = dataPrd.CoordEnvelope.Clone();
                double        maxX     = envelope.MaxX;
                double        minX     = envelope.MinX;
                double        maxY     = envelope.MaxY;
                double        minY     = envelope.MinY;
                using (IVectorFeatureDataReader dr = VectorDataReaderFactory.GetUniversalDataReader(gfrFile) as IVectorFeatureDataReader)
                {
                    Feature[] features = dr.FetchFeatures();
                    for (int i = 0; i < features.Length; i++)
                    {
                        double x, y;
                        if (double.TryParse(features[i].FieldValues[4], out x) && double.TryParse(features[i].FieldValues[3], out y))
                        {
                            if (IsInRange(minX, maxX, x) && IsInRange(minY, maxY, y))
                            {
                                int index = GetIndex(x, y);
                                if (index >= result.Count)
                                {
                                    break;
                                }
                                result.Put(index);
                            }
                        }
                    }
                }
                return(result);
            }
        }
示例#12
0
        private IExtractResult ThresholdAlgorithm_FY2()
        {
            IBandNameRaster bandNameRaster = _argumentProvider.DataProvider as IBandNameRaster;
            int             VisibleCH      = TryGetBandNo(bandNameRaster, "Visible");
            double          VisibleZoom    = (double)_argumentProvider.GetArg("Visible_Zoom");

            if (VisibleCH == -1)
            {
                PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。");
                return(null);
            }

            string express = string.Format(@"band{0}/" + VisibleZoom + @"f  > var_VisibleMin && band{0}/" + VisibleZoom + @"f  < var_VisibleMax", VisibleCH);

            try
            {
                int[] bandNos = new int[] { VisibleCH };
                if (_argumentProvider.DataProvider.DataType == enumDataType.Byte)
                {
                    IThresholdExtracter <byte> extracter = new SimpleThresholdExtracter <byte>();//这里如果用uint16时候,系统会出现崩溃
                    extracter.Reset(_argumentProvider, bandNos, express);
                    IRasterDataProvider prd    = _argumentProvider.DataProvider;
                    IPixelIndexMapper   result = PixelIndexMapperFactory.CreatePixelIndexMapper("FOG", prd.Width, prd.Height, prd.CoordEnvelope, prd.SpatialRef);
                    extracter.Extract(result);
                    return(result);
                }
                else
                {
                    PrintInfo("非静止星数据,数据类型不是byte的。");
                    return(null);
                }
            }
            catch (Exception ex)
            {
                PrintInfo(ex.Message);
                return(null);
            }
        }
示例#13
0
        public override IExtractResult Make(Action <int, string> progressTracker)
        {
            if (_argumentProvider == null || _argumentProvider.DataProvider == null)
            {
                return(null);
            }
            IBandNameRaster bandNameRaster = _argumentProvider.DataProvider as IBandNameRaster;

            if (_argumentProvider.GetArg("AlgorithmName").ToString() == "Cloud")
            {
                string express = "";
                int[]  bandNos = null;
                bandNos    = new int[3];
                bandNos[0] = TryGetBandNo(bandNameRaster, "Visible");
                bandNos[1] = TryGetBandNo(bandNameRaster, "NearInfrared");
                bandNos[2] = TryGetBandNo(bandNameRaster, "FarInfrared");
                double visibleZoom            = (double)_argumentProvider.GetArg("NearInfrared_Zoom");
                double nearZoom               = (double)_argumentProvider.GetArg("Visible_Zoom");
                double farZoom                = (double)_argumentProvider.GetArg("FarInfrared_Zoom");
                string nearInfraredMin        = _argumentProvider.GetArg("NearInfraredMin").ToString();
                string nearInfraredMax        = _argumentProvider.GetArg("NearInfraredMax").ToString();
                string nearInfraredVisibleMin = _argumentProvider.GetArg("NearInfraredVisibleMin").ToString();
                string nearInfraredVisibleMax = _argumentProvider.GetArg("NearInfraredVisibleMax").ToString();
                string farInfraredMin         = _argumentProvider.GetArg("FarInfraredMin").ToString();
                string farInfraredMax         = _argumentProvider.GetArg("FarInfraredMax").ToString();
                express = string.Format(@"(band{0}/{3}>{6}*10)&&(band{0}/{3}<{7}*10)&&(((float)band{1}/{4})/(band{0}/{3})>{8})&&(((float)band{1}/{4})/(band{0}/{3})<{9})&&(band{2}/{5}>{10}*10)&&(band{2}/{5}<{11}*10)", bandNos[0], bandNos[1], bandNos[2], visibleZoom, nearZoom, farZoom, nearInfraredMin, nearInfraredMax, nearInfraredVisibleMin, nearInfraredVisibleMax, farInfraredMin, farInfraredMax);
                IThresholdExtracter <UInt16> extracter = new SimpleThresholdExtracter <UInt16>();
                extracter.Reset(_argumentProvider, bandNos, express);
                IRasterDataProvider prd       = _argumentProvider.DataProvider;
                IPixelIndexMapper   resultFLD = PixelIndexMapperFactory.CreatePixelIndexMapper("FLD", prd.Width, prd.Height, prd.CoordEnvelope, prd.SpatialRef);
                extracter.Extract(resultFLD);
                return(resultFLD);
            }
            else
            {
                return(null);
            }
        }
示例#14
0
        public IExtractResult GetBAG()
        {
            double        visiBandRoom = (double)_argumentProvider.GetArg("Visible_Zoom");
            double        niBandRoom   = (double)_argumentProvider.GetArg("NearInfrared_Zoom");
            bool          needcloud    = (bool)_argumentProvider.GetArg("isAppCloud");
            UCSetNearTool uccontrl     = _argumentProvider.GetArg("UCSetNearTool") as UCSetNearTool;

            if (uccontrl.ckbone.Checked)
            {
                uccontrl.btnGetAOIIndex(null, null);
            }
            MinNear = double.Parse(uccontrl.txtnearmin.Text) * 100;//放大调节 跟界面参数设置有关
            IRasterDataProvider prd = _argumentProvider.DataProvider;

            if (prd == null)
            {
                PrintInfo("未能获取当前影像数据。");
                return(null);
            }
            IBandNameRaster bandNameRaster = prd as IBandNameRaster;
            int             visiBandNo     = TryGetBandNo(bandNameRaster, "Visible");
            int             niBandNo       = TryGetBandNo(bandNameRaster, "NearInfrared");
            int             shortBandNo    = TryGetBandNo(bandNameRaster, "ShortInfrared");

            if (visiBandNo == -1 || niBandNo == -1 || visiBandRoom == -1 || niBandRoom == -1)
            {
                PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。");
                return(null);
            }
            string express      = string.Format("band{0}/{1}f" + " >= " + MinNear, niBandNo, niBandRoom);
            string cloudexpress = GetCloudExpress();

            if (needcloud)
            {
                express = string.Format("{0} && ({1})", express, cloudexpress);
            }
            int[] bandNos = new int[] { visiBandNo, niBandNo, shortBandNo };
            IThresholdExtracter <UInt16> extracter = new SimpleThresholdExtracter <UInt16>();

            extracter.Reset(_argumentProvider, bandNos, express);
            int width  = prd.Width;
            int height = prd.Height;
            IPixelIndexMapper memResult = PixelIndexMapperFactory.CreatePixelIndexMapper("BAG", width, height, prd.CoordEnvelope, prd.SpatialRef);

            extracter.Extract(memResult);

            memResult.Tag = new BagFeatureCollection("蓝藻辅助信息", GetDisplayInfo(memResult, visiBandNo, niBandNo));
            //计算NDVI文件
            IPixelFeatureMapper <float> ndvi = null;

            try
            {
                ndvi = ComputeNDVIResult(_argumentProvider.DataProvider, memResult, visiBandNo, niBandNo);
                IExtractResultBase bPCDResult = CreatPixelCoverRate(ndvi);
                ExtractResultArray results    = new ExtractResultArray("BAG_BINS");
                results.Add(memResult);
                //results.Add(ndvi);
                results.Add(bPCDResult);
                return(results);
            }
            finally
            {
                if (ndvi != null)
                {
                    ndvi.Dispose();
                }
            }
        }
示例#15
0
        public override IExtractResult Make(Action <int, string> progressTracker, IContextMessage contextMessage)
        {
            _contextMessage = contextMessage;
            string     express = "";
            List <int> bandNos = new List <int>();

            if (_argumentProvider == null || _argumentProvider.DataProvider == null)
            {
                return(null);
            }
            IBandNameRaster bandNameRaster = _argumentProvider.DataProvider as IBandNameRaster;
            object          obj            = _argumentProvider.GetArg("AlgorithmName");
            string          argName        = obj == null ? null : obj.ToString();

            if (string.IsNullOrEmpty(argName))
            {
                PrintInfo("参数\"AlgorithmName\"为空。");
                return(null);
            }
            switch (argName)
            {
            case "SunDay1":
            {
                int    bandNo           = TryGetBandNo(bandNameRaster, "NearInfrared");
                double nearInfraredZoom = (double)_argumentProvider.GetArg("NearInfrared_Zoom");
                //配置文件中设置为float类型,但有时为float类型,有时为double型
                //double shortInfraredMin = (double)_argumentProvider.GetArg("ShortInfraredMin");
                //double shortInfraredMax = (double)_argumentProvider.GetArg("ShortInfraredMax");
                if (bandNo <= 0 || nearInfraredZoom == 0)
                {
                    PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。");
                    return(null);
                }
                bandNos.Add(bandNo);
                express = "(band" + bandNo + "/" + nearInfraredZoom + ">" + _argumentProvider.GetArg("ShortInfraredMin") + ")&&(band" + bandNo + "/" + nearInfraredZoom + "<" + _argumentProvider.GetArg("ShortInfraredMax") + ")";
                break;
            }

            case "SunDay2":
            {
                int    visibleNo        = TryGetBandNo(bandNameRaster, "Visible");
                int    nearInfraredNo   = TryGetBandNo(bandNameRaster, "NearInfrared");
                double visibleZoom      = (double)_argumentProvider.GetArg("Visible_Zoom");
                double nearInfraredZoom = (double)_argumentProvider.GetArg("NearInfrared_Zoom");
                if (visibleNo <= 0 || nearInfraredNo <= 0 || visibleZoom == 0 || nearInfraredZoom == 0)
                {
                    PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。");
                    return(null);
                }
                bandNos.Add(visibleNo);
                bandNos.Add(nearInfraredNo);
                express = "((band" + nearInfraredNo + "/" + nearInfraredZoom + "-band" + visibleNo + "/" + visibleZoom + ")<" + _argumentProvider.GetArg("NearInfraredVisibleMax")
                          + " && (band" + nearInfraredNo + "/" + nearInfraredZoom + ")<" + _argumentProvider.GetArg("NearInfraredMax")
                          + " && (band" + visibleNo + "/" + visibleZoom + ")<" + _argumentProvider.GetArg("VisibleMax")
                          + ")";
                break;
            }

            case "Night":
            {
                int    nightFarInfraredNo   = TryGetBandNo(bandNameRaster, "FarInfrared");
                double nightFarInfraredZoom = (double)_argumentProvider.GetArg("FarInfrared_Zoom");
                if (nightFarInfraredNo <= 0)
                {
                    PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。");
                    return(null);
                }
                bandNos.Add(nightFarInfraredNo);
                express = "((band" + nightFarInfraredNo + "/" + nightFarInfraredZoom + ")>" + _argumentProvider.GetArg("FarInfraredMin") + @" &&
                                    (band" + nightFarInfraredNo + "/" + nightFarInfraredZoom + ")<" + _argumentProvider.GetArg("FarInfraredMax") + ")";
                break;
            }

            case "ThinCloud":
            {
                int    visibleNo        = TryGetBandNo(bandNameRaster, "Visible");
                int    nearInfraredNo   = TryGetBandNo(bandNameRaster, "NearInfrared");
                double visibleZoom      = (double)_argumentProvider.GetArg("Visible_Zoom");
                double nearInfraredZoom = (double)_argumentProvider.GetArg("NearInfrared_Zoom");
                if (visibleNo <= 0 || nearInfraredNo <= 0 || visibleZoom == 0 || nearInfraredZoom == 0)
                {
                    PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。");
                    return(null);
                }
                bandNos.Add(visibleNo);
                bandNos.Add(nearInfraredNo);
                express = "(band" + visibleNo + "==0)?false:((((float)band" + nearInfraredNo + "/" + nearInfraredZoom + ")/(band" + visibleNo + "/" + visibleZoom + ")>" + _argumentProvider.GetArg("NearInfraredVisibleMin") + ")&&(((float)band" + nearInfraredNo + "/" + nearInfraredZoom + ")/(band" + visibleNo + "/" + visibleZoom + ")<" + _argumentProvider.GetArg("NearInfraredVisibleMax") + "))";
                break;
            }

            case "Fog":
            {
                int    middleInfraredNo      = TryGetBandNo(bandNameRaster, "MiddleInfrared");
                int    farInfraredNo         = TryGetBandNo(bandNameRaster, "FarInfrared");
                double fogMiddleInfraredZoom = (double)_argumentProvider.GetArg("MiddleInfrared_Zoom");
                double fogFarInfraredZoom    = (double)_argumentProvider.GetArg("FarInfrared_Zoom");
                if (middleInfraredNo <= 0 || farInfraredNo <= 0 || fogFarInfraredZoom == 0 || fogMiddleInfraredZoom == 0)
                {
                    PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。");
                    return(null);
                }
                object midFar = _argumentProvider.GetArg("MiddleInfraredFarInfrared");
                float  value  = float.MinValue;
                if (!float.TryParse(midFar.ToString(), out value))
                {
                    PrintInfo("亮温差不在合法范围内,请重新获取。");
                    return(null);
                }
                bandNos.Add(middleInfraredNo);
                bandNos.Add(farInfraredNo);
                express = "(band" + middleInfraredNo + "/" + fogMiddleInfraredZoom + "-band" + farInfraredNo + "/" + fogFarInfraredZoom + ")>" + value;
                break;
            }

            case "NDVI":
            {
                int    visibleNo              = TryGetBandNo(bandNameRaster, "Visible");
                int    nearInfraredNo         = TryGetBandNo(bandNameRaster, "NearInfrared");
                double ndviVisibleZoom        = (double)_argumentProvider.GetArg("Visible_Zoom");
                double ndvitcNearInfraredZoom = (double)_argumentProvider.GetArg("NearInfrared_Zoom");
                if (visibleNo <= 0 || nearInfraredNo <= 0 || ndvitcNearInfraredZoom == 0 || ndvitcNearInfraredZoom == 0)
                {
                    PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。");
                    return(null);
                }
                bandNos.Add(visibleNo);
                bandNos.Add(nearInfraredNo);
                express = "(band" + nearInfraredNo + "/" + ndvitcNearInfraredZoom + "+band" + visibleNo + "/" + ndviVisibleZoom + ")==0?false:((band" + nearInfraredNo + "/" + ndvitcNearInfraredZoom + "-band" + visibleNo + "/" + ndviVisibleZoom + ")" + " /(float)(band" + nearInfraredNo + "/" + ndvitcNearInfraredZoom + "+band" + visibleNo + "/" + ndviVisibleZoom + ")>" + _argumentProvider.GetArg("VisibleNearInfraredMin") + ")&&((band" + nearInfraredNo + "/" + ndvitcNearInfraredZoom + "-band" + visibleNo + "/" + ndviVisibleZoom + ")" + "/(float)(band" + nearInfraredNo + "/" + ndvitcNearInfraredZoom + "+band" + visibleNo + "/" + ndviVisibleZoom + ")<" + _argumentProvider.GetArg("VisibleNearInfraredMax") + ")";
                break;
            }

            case "GFProcess":
            {
                int    bandNo   = TryGetBandNo(bandNameRaster, "band");
                double bandZoom = (double)_argumentProvider.GetArg("band_Zoom");
                if (bandNo <= 0 || bandZoom <= 0)
                {
                    PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。");
                    return(null);
                }
                bandNos.Add(bandNo);
                express = "((band" + bandNo + "/" + bandZoom + ")>=" + _argumentProvider.GetArg("band1Min") + ")&&((band" + bandNo + "/" + bandZoom + ")<" + _argumentProvider.GetArg("band1Max") + ")";
                break;
            }

            default:
            {
                PrintInfo("指定的算法\"" + argName + "\"没有实现。");
                return(null);
            }
            }
            IThresholdExtracter <UInt16> extracter = new SimpleThresholdExtracter <UInt16>();

            extracter.Reset(_argumentProvider, bandNos.ToArray(), express);
            IRasterDataProvider prd       = _argumentProvider.DataProvider;
            IPixelIndexMapper   resultFLD = PixelIndexMapperFactory.CreatePixelIndexMapper("FLD", prd.Width, prd.Height, prd.CoordEnvelope, prd.SpatialRef);

            extracter.Extract(resultFLD);

            CreateStageAreaInfo();
            return(resultFLD);
        }
示例#16
0
        private void 海陆模板_Click(object sender, EventArgs e)
        {
            using (VectorAOITemplate v = VectorAOITemplateFactory.GetAOITemplate("海陆模版")) //贝尔湖
            {
                Size size;
                IRasterDataProvider prd;
                Envelope            evp = GetEnvelope(out size, out prd);
                Stopwatch           sw  = new Stopwatch();
                sw.Start();
                landAoi = v.GetAOI(evp, size);
                //
                int[] reverseAOI = AOIHelper.Reverse(landAoi, size);
                //IBinaryBitmapBuilder b = new BinaryBitmapBuilder();
                //Bitmap bm = b.CreateBinaryBitmap(size, Color.Red, Color.Black);
                //b.Fill(reverseAOI, size, ref bm);
                //对陆地区域使用陆地判识算法
                Dictionary <string, object> args = new Dictionary <string, object>();
                //args.Add("a", 28);
                //args.Add("b", 78);
                //args.Add("c", 245);
                //args.Add("d", 293);
                //args.Add("f", 28);
                //args.Add("g", 0);
                //args.Add("h", 15);
                //args.Add("i", 250);
                //构造判识表达式
                //string express = "((band2/10f) > var_a) && (band2/10f < var_b) && (band5/10f > var_c) && (band5/10f < var_d) && "
                //               + "(band6/10f > var_f) && ((band6 - band2)>var_g)  && ((band6/10f - band5/10f + var_i)>var_h)";
                ////band2:可见光,0.525~0.575(波长范围)
                ////band5:远红外,10.3~11.55
                ////band6:短波红外,1.60~1.69
                //int[] bandNos = new int[] { 2, 5, 6 };
                ////构造栅格计算判识器
                //ArgumentsProvider argprd = new ArgumentsProvider(prd, args);
                //argprd.AOI = reverseAOI;
                //IThresholdExtracter<UInt16> extracter = new SimpleThresholdExtracter<UInt16>();
                //extracter.Reset(argprd, bandNos, express);
                ////判识
                //landResult = new MemPixelIndexMapper("SAND", 1000);
                //extracter.Extract(landResult);
                //landInd = landResult.Indexes.ToArray();

                //对海洋区域使用海洋判识算法
                args.Clear();
                args.Add("a", 8);
                args.Add("b", 26);
                args.Add("c", 265);
                args.Add("d", 283);
                args.Add("e", -10);
                args.Add("f", 0);
                string express = "(band2/10f > var_a) && (band2/10f < var_b) && (band5/10f > var_c) && (band5/10f < var_d) && "
                                 + "(band6/10f > var_a)&& ((band6/10f - band4/10f)>var_e) &&((band2/10f - band4/10f )>var_f)";
                int[]            bandNos = new int[] { 2, 5, 6, 4 };
                ArgumentProvider argprd  = new ArgumentProvider(prd, args);
                argprd.AOI = reverseAOI;
                IThresholdExtracter <UInt16> extracter = new SimpleThresholdExtracter <UInt16>();
                extracter.Reset(argprd, bandNos, express);
                //判识
                seaResult = PixelIndexMapperFactory.CreatePixelIndexMapper("DST", prd.Width, prd.Height, prd.CoordEnvelope, prd.SpatialRef);
                extracter.Extract(seaResult);
                seaIdx = seaResult.Indexes.ToArray();

                //
                IBinaryBitmapBuilder builder = new BinaryBitmapBuilder();
                Size   bmSize = new Size(prd.Width / 2, prd.Height / 2);
                Bitmap bitmap = builder.CreateBinaryBitmap(bmSize, Color.Red, Color.White);
                builder.Fill(landInd, new Size(prd.Width, prd.Height), ref bitmap);
                bitmap.Save("h:\\陆地沙尘.png", ImageFormat.Png);
                builder.Fill(seaIdx, new Size(prd.Width, prd.Height), ref bitmap);
                bitmap.Save("h:\\海洋沙尘.png", ImageFormat.Png);
                //
                RasterIdentify id = new RasterIdentify();
                id.ThemeIdentify      = "CMA";
                id.ProductIdentify    = "SAND";
                id.SubProductIdentify = "2VAL";
                id.Satellite          = "FY3A";
                id.Sensor             = "MERSI";
                id.Resolution         = "1000M";
                id.OrbitDateTime      = DateTime.Now.Subtract(new TimeSpan(1, 0, 0, 0, 0));
                id.GenerateDateTime   = DateTime.Now;
                IInterestedRaster <UInt16> iir = new InterestedRaster <UInt16>(id, new Size(prd.Width, prd.Height), prd.CoordEnvelope.Clone());
                iir.Put(landInd, 1);
                iir.Put(seaIdx, 1);
                sw.Stop();
                Text = sw.ElapsedMilliseconds.ToString();
                iir.Dispose();
            }


            ////取海洋矢量作为AOI,使用海洋的判识算法
            //Dictionary<string, object> seaargs = new Dictionary<string, object>();
            //seaargs.Add("sa", 8);
            //seaargs.Add("sb", 26);
            //seaargs.Add("sc", 265);
            //seaargs.Add("sd", 283);
            //seaargs.Add("se", -10);
            //seaargs.Add("sf", 0);
            //string seaExpress = "(band2/10f > var_sa) && (band2/10f < var_sb) && (band5/10f > var_sc) && (band5/10f < var_sd) && "
            //                  + "(band6/10f > var_sa)&& ((band6/10f - band4/10f)>var_se) &&((band2/10f - band4/10f )>var_sf)";
            //int[] seabandNos = new int[] { 2, 5, 6, 4 };
            //ArgumentsProvider seaargprd = new ArgumentsProvider(prd, seaargs);
            ////构造判识表达式
            ////构造基于阈值的判识器
            //IThresholdExtracter<UInt16> seaextracter = new SimpleThresholdExtracter<UInt16>();
            //seaextracter.Reset(seaargprd, seabandNos, seaExpress);
            ////判识
            //IPixelIndexMapper searesult = new MemPixelIndexMapper("SAND", 1000);
            //seaextracter.Extract(searesult);
            //int[] seaidxs = searesult.Indexes.ToArray();


            //将两者判识的idex合并
        }
示例#17
0
        /// <summary>
        /// 蓝藻云判识实现
        ///
        /// </summary>
        /// <returns></returns>
        private IExtractResult BAGAlgorithm()
        {
            Dictionary <string, string> dic = Obj2Dic(_curArguments.GetArg("ArgumentSetting"));
            //可见光波段
            int VisibleCH = Obj2int(_curArguments.GetArg("Visible"));
            //近红外波段
            int NearInfraredCH = Obj2int(_curArguments.GetArg("NearInfrared"));
            //短波红外波段
            int ShortInfraredCH = Obj2int(_curArguments.GetArg("ShortInfrared"));

            bool IsPrintFeature = bool.Parse(dic["PrintFeature"]);

            IBandNameRaster bandNameRaster = _argumentProvider.DataProvider as IBandNameRaster;

            //尝试根据当前卫星载荷数据自动匹配波段信息
            if (bandNameRaster != null)
            {
                int newbandNo = -1;
                if (bandNameRaster.TryGetBandNoFromBandName(VisibleCH, out newbandNo))
                {
                    VisibleCH = newbandNo;
                }
                if (bandNameRaster.TryGetBandNoFromBandName(NearInfraredCH, out newbandNo))
                {
                    NearInfraredCH = newbandNo;
                }
                if (bandNameRaster.TryGetBandNoFromBandName(ShortInfraredCH, out newbandNo))
                {
                    ShortInfraredCH = newbandNo;
                }
            }
            //获取放大倍数信息
            double VisibleZoom       = Obj2Double(_curArguments.GetArg("Visible_Zoom"));
            double NearInfraredZoom  = Obj2Double(_curArguments.GetArg("NearInfrared_Zoom"));
            double ShortInfraredZoom = Obj2Double(_curArguments.GetArg("ShortInfrared_Zoom"));
            //获取界面配置值
            double minvisiable     = double.Parse(dic["MinVisiable"]);
            double minnearinfrared = double.Parse(dic["MinNearInFrared"]);
            double maxnsvi         = double.Parse(dic["MaxNSVI"]);
            double minndvi         = double.Parse(dic["MinNDVI"]);


            //云判识增加 近红外/短波红外>c 的判断
            // c=nsvi
            string nsvi = dic.ContainsKey("NSVI") ? dic["NSVI"] : string.Empty;

            if (VisibleCH == -1)
            {
                PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。");
                return(null);
            }
            int bandCount = _curArguments.DataProvider == null ? -1 : _curArguments.DataProvider.BandCount;


            List <int>    bandNos = new List <int>();
            StringBuilder express = new StringBuilder();

            //波段信息
            bandNos.Add(VisibleCH);
            bandNos.Add(NearInfraredCH);
            bandNos.Add(ShortInfraredCH);
            express.Append(string.Format("(band{0}/{1}f" + " >= " + minvisiable + ")||", VisibleCH, VisibleZoom));
            express.Append(string.Format("((band{0}/{1}f)/(band{2}/{3}f)" + "  <= " + maxnsvi + " && ", NearInfraredCH, NearInfraredZoom, ShortInfraredCH, ShortInfraredZoom));
            express.Append(string.Format("band{0}/{1}f" + " >= " + minnearinfrared + " && ", NearInfraredCH, NearInfraredZoom));
            express.Append(string.Format("(float)((band{2}/{1}f - band{0}/{3}f) / (band{2}/{1}f+band{0}/{3}f)) >= " + minndvi + ")", VisibleCH, VisibleZoom, NearInfraredCH, NearInfraredZoom));
            IThresholdExtracter <Int16> extracter = new SimpleThresholdExtracter <Int16>();

            extracter.Reset(_curArguments, bandNos.ToArray(), express.ToString());
            IRasterDataProvider prd    = _curArguments.DataProvider;
            IPixelIndexMapper   result = PixelIndexMapperFactory.CreatePixelIndexMapper("0CLM", prd.Width, prd.Height, prd.CoordEnvelope, prd.SpatialRef);

            if (IsPrintFeature)
            {
                result.Tag = new CLMFeatureCollection("云辅助信息", GetBagDisplayInfo(VisibleCH, ShortInfraredCH, NearInfraredCH, prd));
            }
            extracter.Extract(result);
            return(result);
        }
示例#18
0
        private IPixelIndexMapper GetBinaryValuesMapper(IRasterDataProvider prd, IMonitoringProduct product, IMonitoringSubProduct subProduct)
        {
            string name = GetName(product, subProduct);

            return(PixelIndexMapperFactory.CreatePixelIndexMapper(name, prd.Width, prd.Height, prd.CoordEnvelope, prd.SpatialRef));
        }
示例#19
0
        private IExtractResult CLMAlgorithm()
        {
            Dictionary <string, string> dic = Obj2Dic(_curArguments.GetArg("ArgumentSetting"));
            //可见光波段
            int VisibleCH = Obj2int(_curArguments.GetArg("Visible"));
            //远红外波段
            int FarInfraredCH = Obj2int(_curArguments.GetArg("FarInfrared"));
            //近红外波段
            int NearInfrared  = Obj2int(_curArguments.GetArg("NearInfrared"));
            int NDSIVisibleCH = Obj2int(_curArguments.GetArg("NDSIVisible"));
            //短波红外波段
            int             NDSIShortInfraredCH = Obj2int(_curArguments.GetArg("NDSIShortInfrared"));
            IBandNameRaster bandNameRaster      = _argumentProvider.DataProvider as IBandNameRaster;

            if (bandNameRaster != null)
            {
                int newbandNo = -1;
                if (bandNameRaster.TryGetBandNoFromBandName(VisibleCH, out newbandNo))
                {
                    VisibleCH = newbandNo;
                }
                if (bandNameRaster.TryGetBandNoFromBandName(FarInfraredCH, out newbandNo))
                {
                    FarInfraredCH = newbandNo;
                }
                if (bandNameRaster.TryGetBandNoFromBandName(NDSIVisibleCH, out newbandNo))
                {
                    NDSIVisibleCH = newbandNo;
                }
                if (bandNameRaster.TryGetBandNoFromBandName(NDSIShortInfraredCH, out newbandNo))
                {
                    NDSIShortInfraredCH = newbandNo;
                }
            }
            double VisibleZoom           = Obj2Double(_curArguments.GetArg("Visible_Zoom"));
            double FarInfraredZoom       = Obj2Double(_curArguments.GetArg("FarInfrared_Zoom"));
            double NDSIVisibleZoom       = Obj2Double(_curArguments.GetArg("NDSIVisible_Zoom"));
            double NDSIShortInfraredZoom = Obj2Double(_curArguments.GetArg("NDSIShortInfrared_Zoom"));
            //近红外放大倍数
            double NearInfraredZoom   = Obj2Double(_curArguments.GetArg("NearInfrared_Zoom"));
            string useNDSIStr         = dic.ContainsKey("UseNDSI") ? dic["UseNDSI"] : string.Empty;
            bool   useNDSI            = string.IsNullOrEmpty(useNDSIStr) ? false : bool.Parse(useNDSIStr);
            string PrintFeatrueStr    = dic.ContainsKey("PrintFeatrue") ? dic["PrintFeatrue"] : string.Empty;
            bool   PrintFeatrue       = string.IsNullOrEmpty(PrintFeatrueStr) ? false : bool.Parse(PrintFeatrueStr);
            string ndsiMin            = dic.ContainsKey("NDSIMin") ? dic["NDSIMin"] : string.Empty;
            string ndsiMax            = dic.ContainsKey("NDSIMax") ? dic["NDSIMax"] : string.Empty;
            string useNearVisiableStr = dic.ContainsKey("UseNearVisiable") ? dic["UseNearVisiable"] : string.Empty;
            bool   useNearVisiable    = string.IsNullOrEmpty(useNearVisiableStr) ? false : bool.Parse(useNearVisiableStr);
            string nearVisiableMin    = dic.ContainsKey("NearVisableMin") ? dic["NearVisableMin"] : string.Empty;
            string nearVisiableMax    = dic.ContainsKey("NearVisableMax") ? dic["NearVisableMax"] : string.Empty;
            string visibleMin         = dic.ContainsKey("VisibleMin") ? dic["VisibleMin"] : string.Empty;
            string useFarInfraredStr  = dic.ContainsKey("UseFarInfrared") ? dic["UseFarInfrared"] : string.Empty;
            bool   useFarInfrared     = string.IsNullOrEmpty(useFarInfraredStr) ? false : bool.Parse(useFarInfraredStr);
            string farInfraredMax     = dic.ContainsKey("FarInfraredMax") ? dic["FarInfraredMax"] : string.Empty;
            //云判识增加 近红外/短波红外>c 的判断
            // c=nsvi
            string nsvi = dic.ContainsKey("NSVI") ? dic["NSVI"] : string.Empty;

            if (VisibleCH == -1)
            {
                PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。");
                return(null);
            }
            int bandCount = _curArguments.DataProvider == null ? -1 : _curArguments.DataProvider.BandCount;

            if (useFarInfrared)
            {
                if (FarInfraredCH == -1 || (bandCount != -1 && FarInfraredCH > bandCount))
                {
                    PrintInfo("获取波段序号失败,预选的波段号大于当前影像的最大波段数。");
                    return(null);
                }
            }
            if (useNDSI)
            {
                if (bandCount != -1 && (FarInfraredCH > bandCount || NDSIVisibleCH > bandCount || NDSIShortInfraredCH > bandCount))
                {
                    PrintInfo("获取波段序号失败,预选的波段号大于当前影像的最大波段数。");
                    return(null);
                }
            }
            if (useNearVisiable)
            {
                if (VisibleCH == -1 || NDSIShortInfraredCH == -1 || (bandCount != -1 && (VisibleCH > bandCount || NDSIShortInfraredCH > bandCount)))
                {
                    PrintInfo("获取波段序号失败,预选的波段号大于当前影像的最大波段数。");
                    return(null);
                }
            }
            if (bandCount != -1 && VisibleCH > bandCount)
            {
                VisibleCH = NDSIVisibleCH;
            }

            List <int>    bandNos = new List <int>();
            StringBuilder express = new StringBuilder();

            bandNos.Add(VisibleCH);
            express.Append("band" + VisibleCH + "/" + VisibleZoom + @"f  >= " + visibleMin + " && ");
            if (useNDSI)
            {
                bandNos.Add(NDSIVisibleCH);
                bandNos.Add(NDSIShortInfraredCH);
                express.Append(string.Format(@"NDVI(band{0},band{1})  >= " + ndsiMin + @" &&
                                               NDVI(band{0},band{1})  <  " + ndsiMax + " && ",
                                             NDSIVisibleCH, NDSIShortInfraredCH));
            }
            if (useFarInfrared)
            {
                bandNos.Add(FarInfraredCH);
                express.Append("band" + FarInfraredCH + "/" + FarInfraredZoom + @"f <= " + farInfraredMax + " && ");
            }
            if (useNearVisiable)
            {
                bandNos.Add(NDSIShortInfraredCH);
                bandNos.Add(VisibleCH);
                express.Append(string.Format(@"((band{0}/" + NDSIShortInfraredZoom + "f)/(band{1}/" + VisibleZoom + "f))  >= " + nearVisiableMin + @" &&
                                               ((band{0}/" + NDSIShortInfraredZoom + "f)/(band{1}/" + VisibleZoom + "f))  <  " + nearVisiableMax + @" &&",
                                             NDSIShortInfraredCH, VisibleCH));
            }
            //增加 近红外/短波红外 >c 判识条件
            if (!string.IsNullOrEmpty(nsvi))
            {
                bandNos.Add(NearInfrared);
                bandNos.Add(NDSIShortInfraredCH);
                express.Append(string.Format(@"((band{0}/" + NearInfraredZoom + "f)/(band{1}/" + NDSIShortInfraredZoom + "f))  <= " + nsvi + @" &&",
                                             NearInfrared, NDSIShortInfraredCH));
            }

            IThresholdExtracter <Int16> extracter = new SimpleThresholdExtracter <Int16>();

            extracter.Reset(_curArguments, bandNos.ToArray(), express.ToString().Substring(0, express.Length - 3));
            IRasterDataProvider prd    = _curArguments.DataProvider;
            IPixelIndexMapper   result = PixelIndexMapperFactory.CreatePixelIndexMapper("0CLM", prd.Width, prd.Height, prd.CoordEnvelope, prd.SpatialRef);

            if (PrintFeatrue)
            {
                result.Tag = new CLMFeatureCollection("云辅助信息", GetDisplayInfo(VisibleCH, NDSIShortInfraredCH, VisibleCH, FarInfraredCH,
                                                                              useNDSI, useNearVisiable, useFarInfrared, prd));
            }
            extracter.Extract(result);
            return(result);
        }
示例#20
0
        public unsafe IExtractResult Do(string productIdentify, string subProductIdentify, IRasterDataProvider dataProvider, string filename, out string error)
        {
            error = string.Empty;
            if (!CanDo(productIdentify, subProductIdentify, filename, out error))
            {
                return(null);
            }
            if (_transDef == null)
            {
                _transDef = (new DATXMLParser()).GetTransDef();
            }
            ProductDef        product    = _transDef.GetProductBySmartProductIdentify(productIdentify);
            SubProductDef     subProduct = product.GetSubProductBySmartIdentfy(subProductIdentify);
            IPixelIndexMapper map        = null;

            RasterMaper[]       fileIns       = null;
            RasterMaper[]       fileOuts      = null;
            string              outRasterFile = null;
            IRasterDataProvider dblvPrd       = null;

            try
            {
                dblvPrd = GeoDataDriver.Open(filename) as IRasterDataProvider;
                Dictionary <Int16, Int16> dic = subProduct.GetTableDic <Int16, Int16>();
                //创建临时与当前影像大小一致的Int16类型文件
                int index = 0;
                using (IRasterDataProvider outRaster = GetTempRaster(dataProvider, "MEM", enumDataType.Int16))
                {
                    outRasterFile = outRaster.fileName;
                    map           = PixelIndexMapperFactory.CreatePixelIndexMapper(productIdentify + "_" + subProductIdentify, dataProvider.Width, dataProvider.Height, dataProvider.CoordEnvelope, dataProvider.SpatialRef);
                    List <RasterMaper> rms   = new List <RasterMaper>();
                    RasterMaper        rm    = new RasterMaper(dataProvider, new int[] { 1 });
                    RasterMaper        oldRm = new RasterMaper(dblvPrd, new int[] { 1 });
                    rms.AddRange(new RasterMaper[] { rm, oldRm });
                    //栅格数据映射
                    fileIns  = rms.ToArray();
                    fileOuts = new RasterMaper[] { new RasterMaper(outRaster, new int[] { 1 }) };
                    //创建处理模型
                    RasterProcessModel <Int16, Int16> rfr = new RasterProcessModel <Int16, Int16>(null);
                    rfr.SetRaster(fileIns, fileOuts);
                    rfr.RegisterCalcModel(new RasterCalcHandlerFun <Int16, Int16>((rvInVistor, rvOutVistor, aoi) =>
                    {
                        if (rvInVistor[1].RasterBandsData[0] == null)
                        {
                            index += rvInVistor[0].RasterBandsData[0].Length;
                            return(false);
                        }
                        else
                        {
                            for (int i = 0; i < rvInVistor[1].RasterBandsData[0].Length; i++)
                            {
                                if (dic.ContainsKey(rvInVistor[1].RasterBandsData[0][i]))
                                {
                                    map.Put(index + i);
                                }
                            }
                            index += rvInVistor[0].RasterBandsData[0].Length;
                            return(true);
                        }
                    }));
                    rfr.Excute(-1);
                }
            }
            finally
            {
                if (dblvPrd != null)
                {
                    dblvPrd.Dispose();
                }
                foreach (RasterMaper item in fileOuts)
                {
                    if (item.Raster != null)
                    {
                        item.Raster.Dispose();
                    }
                }
                if (File.Exists(outRasterFile))
                {
                    File.Delete(outRasterFile);
                }
            }
            return(map.Indexes == null || map.Indexes.Count() == 0 ? null : map);
        }
示例#21
0
 private IPixelIndexMapper GenerateHistoryResultByAOI(IPixelIndexMapper pixelMapper, int[] drawedAOI)
 {
     if (drawedAOI == null || drawedAOI.Length < 1)
     {
         return(null);
     }
     if (lstFiles.Items.Count < 1)
     {
         return(null);
     }
     foreach (string file in lstFiles.Items)
     {
         if (!File.Exists(file))
         {
             return(null);
         }
     }
     using (IRasterDataProvider prd = GeoDataDriver.Open(_currentRasterFile) as IRasterDataProvider)
     {
         List <int> aoiList = new List <int>();
         aoiList.AddRange(drawedAOI);
         IPixelIndexMapper result = PixelIndexMapperFactory.CreatePixelIndexMapper("FLD", prd.Width, prd.Height, prd.CoordEnvelope, prd.SpatialRef);
         if (pixelMapper != null && pixelMapper.Indexes.Count() > 0)
         {
             foreach (int i in pixelMapper.Indexes)
             {
                 if (aoiList.Contains(i))
                 {
                     result.Put(i);
                 }
             }
         }
         //
         IInterestedRaster <Int16> iir = null;
         try
         {
             RasterIdentify id = new RasterIdentify();
             id.ThemeIdentify      = "CMA";
             id.ProductIdentify    = "FLD";
             id.SubProductIdentify = "DBLV";
             iir = new InterestedRaster <Int16>(id, new Size(prd.Width, prd.Height), prd.CoordEnvelope.Clone());
             int[] idxs = result.Indexes.ToArray();
             iir.Put(idxs, 1);
         }
         finally
         {
             iir.Dispose();
         }
         Dictionary <string, FilePrdMap> filePrdMap = new Dictionary <string, FilePrdMap>();
         filePrdMap.Add("currentDBLV", new FilePrdMap(iir.FileName, 1, new VaildPra(Int16.MinValue, Int16.MaxValue), new int[] { 1 }));
         int index = 0;
         foreach (string file in lstFiles.Items)
         {
             filePrdMap.Add("dblv" + index, new FilePrdMap(file, 1, new VaildPra(Int16.MinValue, Int16.MaxValue), new int[] { 1 }));
             index++;
         }
         ITryCreateVirtualPrd       tryVPrd = new TryCreateVirtualPrdByMultiFile();
         IVirtualRasterDataProvider vrd     = tryVPrd.CreateVirtualRasterPRD(ref filePrdMap);
         if (vrd == null)
         {
             if (filePrdMap != null && filePrdMap.Count > 0)
             {
                 foreach (FilePrdMap value in filePrdMap.Values)
                 {
                     if (value.Prd != null)
                     {
                         value.Prd.Dispose();
                     }
                 }
             }
             return(null);
         }
         try
         {
             ArgumentProvider            ap        = new ArgumentProvider(vrd, null);
             RasterPixelsVisitor <float> rpVisitor = new RasterPixelsVisitor <float>(ap);
             int   historyCount = lstFiles.Items.Count;
             int[] bandNos      = new int[historyCount + 1];
             for (int i = 0; i < bandNos.Length; i++)
             {
                 bandNos[i] = i + 1;
             }
             int[] difArray = new int[historyCount];
             rpVisitor.VisitPixel(new Rectangle(0, 0, prd.Width, prd.Height), drawedAOI, bandNos,
                                  (idx, values) =>
             {
                 for (int i = 0; i < historyCount; i++)
                 {
                     if (values[0] != values[i + 1])
                     {
                         difArray[i]++;
                     }
                 }
             });
             int min = difArray[0], minIndex = 0;
             for (int i = 1; i < difArray.Length; i++)
             {
                 if (min > difArray[i])
                 {
                     min      = difArray[i];
                     minIndex = i;
                 }
             }
             rpVisitor.VisitPixel(bandNos,
                                  (idx, values) =>
             {
                 if (values[minIndex + 1] == 1)
                 {
                     if (!aoiList.Contains(idx))
                     {
                         result.Put(idx);
                     }
                 }
             });
             return(result);
         }
         finally
         {
             vrd.Dispose();
             if (File.Exists(iir.FileName))
             {
                 File.Delete(iir.FileName);
             }
         }
     }
 }
示例#22
0
        public override IExtractResult Make(Action <int, string> progressTracker, IContextMessage contextMessage)
        {
            _contextMessage = contextMessage;
            if (_argumentProvider == null || _argumentProvider.DataProvider == null)
            {
                return(null);
            }
            string algname = _argumentProvider.GetArg("AlgorithmName").ToString();

            if (algname == "BAGExtract_New")
            {
                //return GetBAG();
                return(GetCloudBAG());
            }

            if (!string.IsNullOrEmpty(algname))
            {
                double visiBandRoom = (double)_argumentProvider.GetArg("Visible_Zoom");
                double niBandRoom   = (double)_argumentProvider.GetArg("NearInfrared_Zoom");
                if (algname == "BAGExtract")
                {
                    MinNDVI = (double)_argumentProvider.GetArg("NDVIMin");
                    MaxNDVI = (double)_argumentProvider.GetArg("NDVIMax");
                }
                else if (algname == "BAGExtract_Test")
                {
                    UCSetNDVITool uccontrl = _argumentProvider.GetArg("ucSetNDVITool") as UCSetNDVITool;
                    if (uccontrl.ckbaoi.Checked)
                    {
                        uccontrl.btnGetAOIIndex(null, null);
                    }
                    else
                    {
                        MinNDVI = uccontrl.txtndvimin.Value;
                        MaxNDVI = uccontrl.txtndvimax.Value;
                    }
                }



                IRasterDataProvider prd = _argumentProvider.DataProvider;
                if (prd == null)
                {
                    PrintInfo("未能获取当前影像数据。");
                    return(null);
                }
                IBandNameRaster bandNameRaster = prd as IBandNameRaster;
                int             visiBandNo     = TryGetBandNo(bandNameRaster, "Visible");
                int             niBandNo       = TryGetBandNo(bandNameRaster, "NearInfrared");
                if (visiBandNo == -1 || niBandNo == -1 || visiBandRoom == -1 || niBandRoom == -1)
                {
                    PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。");
                    return(null);
                }
                string express = string.Format(@"({0}==0||{1}==0 )? false :((float)(band{3}/{1}f - band{2}/{0}f) / (band{2}/{0}f+ band{3}/{1}f) < {5})
                       && ((float)(band{3} /{1}f- band{2}/{0}f) / (band{3}/{1}f + band{2}/{0}f) > {4})", visiBandRoom, niBandRoom, visiBandNo, niBandNo, MinNDVI, MaxNDVI);
                int[]  bandNos = new int[] { visiBandNo, niBandNo };
                IThresholdExtracter <UInt16> extracter = new SimpleThresholdExtracter <UInt16>();
                extracter.Reset(_argumentProvider, bandNos, express);
                int width  = prd.Width;
                int height = prd.Height;
                IPixelIndexMapper memResult = PixelIndexMapperFactory.CreatePixelIndexMapper("BAG", width, height, prd.CoordEnvelope, prd.SpatialRef);
                extracter.Extract(memResult);
                memResult.Tag = new BagFeatureCollection("蓝藻辅助信息", GetDisplayInfo(memResult, visiBandNo, niBandNo));
                //计算NDVI文件
                IPixelFeatureMapper <float> ndvi = null;
                try
                {
                    ndvi = ComputeNDVIResult(_argumentProvider.DataProvider, memResult, visiBandNo, niBandNo);
                    IExtractResultBase bPCDResult = CreatPixelCoverRate(ndvi);
                    ExtractResultArray results    = new ExtractResultArray("BAG_BINS");
                    results.Add(memResult);
                    //results.Add(ndvi);
                    results.Add(bPCDResult);
                    return(results);
                }
                finally
                {
                    if (ndvi != null)
                    {
                        ndvi.Dispose();
                    }
                }
            }
            else
            {
                PrintInfo("指定的算法\"" + algname + "\"没有实现。");
                return(null);
            }
        }
示例#23
0
        public IExtractResult GetCloudBAG()
        {
            double niBandRoom = (double)_argumentProvider.GetArg("NearInfrared_Zoom");
            bool   needcloud  = (bool)_argumentProvider.GetArg("isAppCloud");

            UCSetNearTool uccontrl = _argumentProvider.GetArg("UCSetNearTool") as UCSetNearTool;

            if (uccontrl.ckbone.Checked)
            {
                uccontrl.btnGetAOIIndex(null, null);
            }
            string cloudfile    = GetClmFile(_argumentProvider.DataProvider);
            bool   isexistcloud = File.Exists(cloudfile);

            MinNear = double.Parse(uccontrl.txtnearmin.Text) * 100;//放大调节 跟界面参数设置有关
            IRasterDataProvider prd = _argumentProvider.DataProvider;

            if (prd == null)
            {
                PrintInfo("未能获取当前影像数据。");
                return(null);
            }
            IBandNameRaster bandNameRaster = prd as IBandNameRaster;
            int             niBandNo       = TryGetBandNo(bandNameRaster, "NearInfrared");

            if (niBandNo == -1 || niBandRoom == -1)
            {
                PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。");
                return(null);
            }
            List <RasterMaper> rms = new List <RasterMaper>();

            rms.Add(new RasterMaper(_argumentProvider.DataProvider, new int[] { niBandNo }));
            if (isexistcloud)
            {
                rms.Add(new RasterMaper(GeoDataDriver.Open(cloudfile) as IRasterDataProvider, new int[] { 1 }));
            }
            RasterIdentify rid = new RasterIdentify(_argumentProvider.DataProvider);

            rid.ProductIdentify    = "BAG";
            rid.SubProductIdentify = "DBLV";
            string outfile = rid.ToPrjWksFullFileName(".dat");
            IRasterDataProvider outRaster = null;

            outRaster = CreateOutRaster(outfile, rms.ToArray(), enumDataType.Int16);
            IPixelIndexMapper result = PixelIndexMapperFactory.CreatePixelIndexMapper("BAG", _argumentProvider.DataProvider.Width, _argumentProvider.DataProvider.Height,
                                                                                      _argumentProvider.DataProvider.CoordEnvelope, _argumentProvider.DataProvider.SpatialRef);

            try
            {
                RasterProcessModel <Int16, Int16> rfr = null;
                RasterMaper[] fileIns  = rms.ToArray();
                RasterMaper[] fileOuts = new RasterMaper[] { new RasterMaper(outRaster, new int[] { 1 }) };
                rfr = new RasterProcessModel <Int16, Int16>();
                int totalindex = 0;
                rfr.SetRaster(fileIns, fileOuts);
                rfr.SetArgumentProviderAOI(_argumentProvider.AOI);
                rfr.RegisterCalcModel(new RasterCalcHandlerFun <Int16, Int16>((rvInVistor, rvOutVistor, aoi) =>
                {
                    if (rvInVistor[0].RasterBandsData[0] != null && rvInVistor[1].RasterBandsData[0] != null)
                    {
                        int dataLength = rvInVistor[0].SizeY * rvInVistor[0].SizeX;
                        for (int i = 0; i < aoi.Length; i++)
                        {
                            int index = aoi[i];
                            if (rvInVistor[0].RasterBandsData[0][index] / niBandRoom > MinNear)
                            {
                                if (needcloud)
                                {
                                    if (!isexistcloud)
                                    {
                                        result.Put(totalindex + index);
                                        continue;
                                    }
                                    else if (rvInVistor[1].RasterBandsData[0][index] == 0)//非云
                                    {
                                        result.Put(totalindex + index);
                                    }
                                    else
                                    {
                                        //rvOutVistor[0].RasterBandsData[0][aoi[i]] = -9999;// 云 这里是否需要配置一下?
                                    }
                                }
                                else
                                {
                                    result.Put(totalindex + index);
                                    //rvOutVistor[0].RasterBandsData[0][aoi[i]] = 1;
                                }
                            }
                            else
                            {
                            }
                        }
                        totalindex = totalindex += dataLength;
                    }

                    return(false);
                }));
                rfr.Excute();
                return(result);
            }
            catch (Exception ex)
            {
                return(null);
            }
            finally
            {
                outRaster.Dispose();
            }
        }
示例#24
0
        private IPixelIndexMapper GenerateHistoryResultByAOI(IPixelIndexMapper pixelMapper, string historyFile, int[] drawedAOI)
        {
            if (!File.Exists(historyFile) || drawedAOI == null || drawedAOI.Length < 1)
            {
                return(null);
            }
            IRasterDataProvider historyPrd = null;
            IRasterDataProvider prd        = null;
            string outFileName             = null;

            try
            {
                historyPrd = GeoDataDriver.Open(historyFile) as IRasterDataProvider;
                prd        = GeoDataDriver.Open(_currentRasterFile) as IRasterDataProvider;
                IPixelIndexMapper result = PixelIndexMapperFactory.CreatePixelIndexMapper("FLD", prd.Width, prd.Height, prd.CoordEnvelope, prd.SpatialRef);
                if (pixelMapper != null && pixelMapper.Indexes.Count() > 0)
                {
                    foreach (int i in pixelMapper.Indexes)
                    {
                        result.Put(i);
                    }
                }
                List <RasterMaper> rms   = new List <RasterMaper>();
                RasterMaper        rm    = new RasterMaper(prd, new int[] { 1 });
                RasterMaper        oldRm = new RasterMaper(historyPrd, new int[] { 1 });
                rms.AddRange(new RasterMaper[] { rm, oldRm });
                using (IRasterDataProvider outRaster = GetTempOutRaster(historyFile, prd))
                {
                    //栅格数据映射
                    RasterMaper[] fileIns  = rms.ToArray();
                    RasterMaper[] fileOuts = new RasterMaper[] { new RasterMaper(outRaster, new int[] { 1 }) };
                    //创建处理模型
                    RasterProcessModel <short, short> rfr = null;
                    rfr = new RasterProcessModel <short, short>(null);
                    rfr.SetRaster(fileIns, fileOuts);
                    rfr.RegisterCalcModel(new RasterCalcHandler <short, short>((rvInVistor, rvOutVistor, aoi) =>
                    {
                        int y = rvInVistor[0].IndexY * rvInVistor[0].Raster.Width;
                        //修改aoi区域超出索引问题
                        int length = rvInVistor[1].RasterBandsData[0].Length;
                        foreach (int i in drawedAOI)
                        {
                            //修改aoi区域超出索引问题
                            if (i < y || i - y >= length)
                            {
                                continue;
                            }
                            if (rvInVistor[1].RasterBandsData[0][i - y] == 1)
                            {
                                rvOutVistor[0].RasterBandsData[0][i - y] = 1;
                                result.Put(i);
                            }
                        }
                    }));
                    rfr.Excute();
                }
                return(result);
            }
            finally
            {
                if (historyPrd != null)
                {
                    historyPrd.Dispose();
                }
                if (prd != null)
                {
                    prd.Dispose();
                }
                if (File.Exists(outFileName))
                {
                    File.Delete(outFileName);
                }
            }
        }
示例#25
0
        private IExtractResult FRAREAlgorithm(Action <int, string> progressTracker)
        {
            AngleParModel model    = _argumentProvider.GetArg("anglesettings") as AngleParModel;
            double        glintmax = double.Parse(_argumentProvider.GetArg("glint").ToString());
            //band
            int angleband = (int)_argumentProvider.GetArg("angle");
            //zoom
            float  anglezoom              = float.Parse(_argumentProvider.GetArg("angle_Zoom").ToString());
            string rasterfile             = _argumentProvider.DataProvider.fileName;
            IRasterDataProvider outRaster = null;
            List <RasterMaper>  rms       = new List <RasterMaper>();

            try
            {
                IRasterDataProvider sunzinRaster = RasterDataDriver.Open(model.FileAsunZ) as IRasterDataProvider;
                RasterMaper         brmsunz      = new RasterMaper(sunzinRaster, new int[] { angleband });
                rms.Add(brmsunz);
                IRasterDataProvider sunainRaster = RasterDataDriver.Open(model.FileAsunA) as IRasterDataProvider;
                RasterMaper         brmsuna      = new RasterMaper(sunainRaster, new int[] { angleband });
                rms.Add(brmsuna);
                IRasterDataProvider satzinRaster = RasterDataDriver.Open(model.FileAsatZ) as IRasterDataProvider;
                RasterMaper         brmsatz      = new RasterMaper(satzinRaster, new int[] { angleband });
                rms.Add(brmsatz);
                IRasterDataProvider satainRaster = RasterDataDriver.Open(model.FileAsatA) as IRasterDataProvider;
                RasterMaper         brmsata      = new RasterMaper(satainRaster, new int[] { angleband });
                rms.Add(brmsata);

                RasterIdentify ri = GetRasterIdentifyID(rasterfile);
                ri.SubProductIdentify = "FRAM";
                string                      outFileName = ri.ToWksFullFileName(".dat");
                IPixelIndexMapper           result      = null;
                IPixelFeatureMapper <Int16> resultTag   = null;
                int totalDatalength = 0;
                Dictionary <int, FireAngleFeature> listfeature = new Dictionary <int, FireAngleFeature>();
                outRaster = CreateOutRaster(outFileName, rms.ToArray());
                result    = PixelIndexMapperFactory.CreatePixelIndexMapper("FIR", outRaster.Width, outRaster.Height, outRaster.CoordEnvelope, outRaster.SpatialRef);
                //栅格数据映射
                RasterMaper[] fileIns  = rms.ToArray();
                RasterMaper[] fileOuts = new RasterMaper[] { new RasterMaper(outRaster, new int[] { 1 }) };
                //创建处理模型
                RasterProcessModel <Int16, UInt16> rfr = null;
                rfr = new RasterProcessModel <Int16, UInt16>(progressTracker);
                rfr.SetRaster(fileIns, fileOuts);
                rfr.RegisterCalcModel(new RasterCalcHandler <Int16, UInt16>((rvInVistor, rvOutVistor, aoi) =>
                {
                    int dataLength = rvOutVistor[0].SizeY * rvOutVistor[0].SizeX;

                    for (int index = 0; index < dataLength; index++)
                    {
                        double asunz      = rvInVistor[0].RasterBandsData[0][index] / anglezoom;
                        double asuna      = rvInVistor[1].RasterBandsData[0][index] / anglezoom;
                        double asatz      = rvInVistor[2].RasterBandsData[0][index] / anglezoom;
                        double asata      = rvInVistor[3].RasterBandsData[0][index] / anglezoom;
                        double glintangle = Math.Acos(Math.Sin(asunz) * Math.Sin(asatz) * Math.Cos(asuna - asata) + Math.Cos(asunz) * Math.Cos(asatz));
                        if (glintangle != 0)
                        {
                            if (glintangle * 180 / Math.PI < glintmax)
                            {
                                result.Put(totalDatalength + index);
                            }
                            //增加像元信息显示
                            FireAngleFeature feature = new FireAngleFeature();
                            feature.SunZ             = asunz;
                            feature.SunA             = asuna;
                            feature.SatZ             = asatz;
                            feature.SatA             = asata;
                            feature.Glint            = Math.Round(glintangle * 180 / Math.PI, 2);
                            listfeature.Add(totalDatalength + index, feature);
                        }
                        rvOutVistor[0].RasterBandsData[0][index] = Convert.ToUInt16(glintangle * 180 * anglezoom / Math.PI);
                    }
                    totalDatalength += dataLength;
                }));
                //执行
                rfr.Excute();
                result.Tag = new FireAngleCollection("耀斑角信息", listfeature);
                IExtractResultArray array = new ExtractResultArray("FIR");
                array.Add(result);
                FileExtractResult angleresult = new FileExtractResult(ri.SubProductIdentify, outFileName);
                angleresult.SetDispaly(false);
                array.Add(angleresult);

                return(array);
            }
            finally
            {
                foreach (RasterMaper rm in rms)
                {
                    rm.Raster.Dispose();
                }
                if (outRaster != null)
                {
                    outRaster.Dispose();
                }
            }
        }
示例#26
0
        public override IExtractResult Make(Action <int, string> progressTracker, IContextMessage contextMessage)
        {
            _contextMessage = contextMessage;
            if (_argumentProvider == null || _argumentProvider.DataProvider == null)
            {
                return(null);
            }
            string algname = _argumentProvider.GetArg("AlgorithmName").ToString();

            if (string.IsNullOrEmpty(algname))
            {
                PrintInfo("参数\"AlgorithmName\"为空。");
                return(null);
            }
            //光学数据积雪判识
            if (algname == "SNWExtract")
            {
                int    visiBandNo   = (int)_argumentProvider.GetArg("Visible");
                int    sIBandNo     = (int)_argumentProvider.GetArg("ShortInfrared");
                int    fIBandNo     = (int)_argumentProvider.GetArg("FarInfrared");
                double visiBandZoom = (double)_argumentProvider.GetArg("Visible_Zoom");
                double siBandZoom   = (double)_argumentProvider.GetArg("ShortInfrared_Zoom");
                double fiBandZoom   = (double)_argumentProvider.GetArg("FarInfrared_Zoom");
                if (visiBandNo <= 0 || sIBandNo <= 0 || fIBandNo <= 0 || visiBandZoom <= 0 || siBandZoom <= 0 || fiBandZoom <= 0)
                {
                    PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。");
                    return(null);
                }
                string express = string.Format(@"(band{1}/{4}f > var_ShortInfraredMin) && (band{1}/{4}f< var_ShortInfraredMax) && 
                                (band{2}/{5}f< var_FarInfraredMax) && (band{2}/{5}f > var_FarInfraredMin) && (band{0}/{3}f> var_VisibleMin) && 
                                ((float)(band{0}/{3}f-band{1}/{4}f)/(band{0}/{3}f+band{1}/{4}f)> var_NDSIMin) && 
                                ((float)(band{0}/{3}f-band{1}/{4}f)/(band{0}/{3}f+band{1}/{4}f)< var_NDSIMax)&&
                                (band{0}/{3}f< var_VisibleMax)", visiBandNo, sIBandNo, fIBandNo, visiBandZoom, siBandZoom, fiBandZoom);
                int[]  bandNos = new int[] { visiBandNo, sIBandNo, fIBandNo };
                IThresholdExtracter <UInt16> extracter = new SimpleThresholdExtracter <UInt16>();
                extracter.Reset(_argumentProvider, bandNos, express);
                int width  = _argumentProvider.DataProvider.Width;
                int height = _argumentProvider.DataProvider.Height;
                IPixelIndexMapper result = PixelIndexMapperFactory.CreatePixelIndexMapper("MWS", width, height, _argumentProvider.DataProvider.CoordEnvelope, _argumentProvider.DataProvider.SpatialRef);
                result.Tag = SnwDisplayInfo.GetDisplayInfo(_argumentProvider, visiBandNo, sIBandNo, fIBandNo);
                extracter.Extract(result);
                return(result);
            }
            else
            {
                float[] extrParas = (float[])_argumentProvider.GetArg("Arguments");
                string  filename  = _argumentProvider.DataProvider.fileName;
                //解析文件时间,确定波段顺序
                Match  m        = DataReg.Match(Path.GetFileName(filename));
                string filedate = "";
                if (m.Success)
                {
                    filedate = m.Value;
                }
                Int32 filedateDig = Convert.ToInt32(filedate);
                int   ch18vBandNo = 3; //默认为现在使用的波段顺序
                int   ch23vBandNo = 5;
                int   ch36vBandNo = 7;
                int   ch89vBandNo = 9;
                if (algname == "MSIdentify")
                {
                    if (filedateDig < 20110412)
                    {
                        ch18vBandNo = 7;
                        ch23vBandNo = 5;
                        ch36vBandNo = 3;
                        ch89vBandNo = 1;
                    }
                    if (ch18vBandNo <= 0 || ch23vBandNo <= 0 || ch36vBandNo <= 0 || ch89vBandNo <= 0)
                    {
                        PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。");
                        return(null);
                    }
                    //string express = string.Format(@"(((((band{1}-band{3})*0.01>=var_23V89Vmin)||((band{0}-band{2})*0.01>= var_18V36Vmin))&&((band{1}*0.01+327.68)<=var_23Vmax)&&((band{0}-band{2})*0.01>=var_18Vsec36Vmin)&&((band{1}-band{3}-band{0}+band{2})*0.01>=var_si1si2thickmin))||((((band{1}-band{3})*0.01>var_23V89Vmin)||((band{0}-band{2})*0.01> var_18V36Vmin))&&((band{1}*0.01)+327.68<=var_23Vmax)&&((band{0}-band{2})*0.01<var_18Vsec36Vmin)&&((band{1}-band{3}-band{0}+band{2})*0.01>=var_si1thinsi2min)))", ch18vBandNo, ch23vBandNo, ch36vBandNo, ch89vBandNo);
                    string express = string.Format(@"(((((band{1}-band{3})*0.01>={4})||((band{0}-band{2})*0.01>= {5}))&&((band{1}*0.01+327.68)<={6})&&((band{0}-band{2})*0.01>={7})&&((band{1}-band{3}-band{0}+band{2})*0.01>={8}))||((((band{1}-band{3})*0.01>{4})||((band{0}-band{2})*0.01> {5}))&&((band{1}*0.01)+327.68<={6})&&((band{0}-band{2})*0.01<{7})&&((band{1}-band{3}-band{0}+band{2})*0.01>={9})))", ch18vBandNo, ch23vBandNo, ch36vBandNo, ch89vBandNo, extrParas[0], extrParas[1], extrParas[2], extrParas[3], extrParas[4], extrParas[5]);
                    int[]  bandNos = new int[] { ch18vBandNo, ch23vBandNo, ch36vBandNo, ch89vBandNo };
                    IThresholdExtracter <Int16> extracter = new SimpleThresholdExtracter <Int16>();
                    extracter.Reset(_argumentProvider, bandNos, express);
                    int width  = _argumentProvider.DataProvider.Width;
                    int height = _argumentProvider.DataProvider.Height;
                    IPixelIndexMapper result = PixelIndexMapperFactory.CreatePixelIndexMapper("MWS", width, height, _argumentProvider.DataProvider.CoordEnvelope, _argumentProvider.DataProvider.SpatialRef);
                    //由于当数据过大(如全球范围数据时),分块缓存不足,因此注释掉。
                    //result.Tag = SnwDisplayInfo.GetDisplayInfoMS(_argumentProvider, ch18vBandNo, ch23vBandNo, ch36vBandNo, ch89vBandNo);
                    extracter.Extract(result);
                    return(result);
                }
                else
                {
                    return(null);
                }
            }
        }
示例#27
0
        private IExtractResult FIRFMack(Action <int, string> progressTracker)
        {
            IBandNameRaster bandNameRaster   = _argumentProvider.DataProvider as IBandNameRaster;
            int             NearInfrared     = TryGetBandNo(bandNameRaster, "NearInfrared");
            int             CoverageBand     = (int)_argumentProvider.GetArg("CoverageBand");
            double          NearInfraredZoom = (double)_argumentProvider.GetArg("NearInfrared_Zoom");
            double          CoverageZoom     = (double)_argumentProvider.GetArg("CoverageBand_Zoom");
            float           NearInfraredMax  = (float)_argumentProvider.GetArg("NearInfraredMax");
            float           CoverageMin      = (float)_argumentProvider.GetArg("CoverageMin");
            float           FIRLZoom         = (float)_argumentProvider.GetArg("FIRFZoom");

            if (NearInfrared == -1 || CoverageBand == -1)
            {
                PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误。");
                return(null);
            }

            string coverageFile = _argumentProvider.GetArg("coverageFile") == null ? null : _argumentProvider.GetArg("coverageFile").ToString();

            if (string.IsNullOrEmpty(coverageFile))
            {
                PrintInfo("请设置背景农田百分比数据!");
                return(null);
            }

            float maxAvgValue;
            float minAvgValue;

            string[] nearInfValues = _argumentProvider.GetArg("NearInfraredValues") as string[];
            if (nearInfValues == null || nearInfValues.Count() != 2)
            {
                return(null);
            }
            if (!float.TryParse(nearInfValues[0], out maxAvgValue) || !float.TryParse(nearInfValues[1], out minAvgValue))
            {
                return(null);
            }
            if (maxAvgValue == minAvgValue)
            {
                return(null);
            }
            float dltValue                  = maxAvgValue - minAvgValue;
            List <RasterMaper>  rms         = new List <RasterMaper>();
            IRasterDataProvider curPrd      = _argumentProvider.DataProvider;
            IRasterDataProvider coveragePrd = null;

            try
            {
                RasterMaper nearRm = new RasterMaper(curPrd, new int[] { NearInfrared });
                rms.Add(nearRm);

                coveragePrd = RasterDataDriver.Open(coverageFile) as IRasterDataProvider;
                if (coveragePrd.BandCount < CoverageBand)
                {
                    PrintInfo("请选择正确的农田百分比数据文件通道值!");
                    return(null);
                }
                RasterMaper coverageRm = new RasterMaper(coveragePrd, new int[] { CoverageBand });
                rms.Add(coverageRm);

                string                      outFileName = GetFileName(new string[] { curPrd.fileName }, _subProductDef.ProductDef.Identify, _identify, ".dat", null);
                IPixelIndexMapper           result      = null;
                IPixelFeatureMapper <Int16> resultTag   = null;
                int   totalDatalength = 0;
                float tempValue       = 0;
                using (IRasterDataProvider outRaster = CreateOutRaster(outFileName, rms.ToArray()))
                {
                    result = PixelIndexMapperFactory.CreatePixelIndexMapper("FIR", outRaster.Width, outRaster.Height, outRaster.CoordEnvelope, outRaster.SpatialRef);
                    if (this.Tag == null || (this.Tag as MemPixelFeatureMapper <Int16>) == null)
                    {
                        resultTag = new MemPixelFeatureMapper <Int16>("FIFLT", 1000, new Size(outRaster.Width, outRaster.Height), outRaster.CoordEnvelope, outRaster.SpatialRef);
                    }
                    else
                    {
                        resultTag = this.Tag as MemPixelFeatureMapper <Int16>;
                    }
                    RasterMaper[] fileIns  = rms.ToArray();
                    RasterMaper[] fileOuts = new RasterMaper[] { new RasterMaper(outRaster, new int[] { 1 }) };
                    //创建处理模型
                    RasterProcessModel <Int16, Int16> rfr = null;
                    rfr = new RasterProcessModel <Int16, Int16>(progressTracker);
                    rfr.SetRaster(fileIns, fileOuts);
                    rfr.SetFeatureAOI(_argumentProvider.AOIs);
                    rfr.RegisterCalcModel(new RasterCalcHandlerFun <short, short>((rvInVistor, rvOutVistor, aoi) =>
                    {
                        int dataLength = rvOutVistor[0].SizeY * rvOutVistor[0].SizeX;
                        if (rvInVistor[0].RasterBandsData == null || rvInVistor[1].RasterBandsData == null ||
                            rvInVistor[0].RasterBandsData[0] == null || rvInVistor[1].RasterBandsData[0] == null)
                        {
                            totalDatalength += dataLength;
                            return(false);
                        }
                        if (_argumentProvider.AOIs == null)
                        {
                            for (int index = 0; index < dataLength; index++)
                            {
                                if (IsFirA(rvInVistor, index, NearInfraredZoom, NearInfraredMax))
                                {
                                    result.Put(totalDatalength + index);

                                    tempValue = (maxAvgValue - rvInVistor[0].RasterBandsData[0][index]) / dltValue;
                                    if (tempValue < rvInVistor[1].RasterBandsData[0][index] / CoverageZoom)
                                    {
                                        resultTag.Put(totalDatalength + index, tempValue < 0 ? (Int16)0 : (tempValue > 1 ? (Int16)(FIRLZoom) : (Int16)(tempValue * FIRLZoom)));
                                    }
                                    else
                                    {
                                        resultTag.Put(totalDatalength + index, (Int16)(rvInVistor[1].RasterBandsData[0][index] / CoverageZoom * FIRLZoom));
                                    }
                                }
                            }
                        }
                        else if (_argumentProvider.AOIs != null && aoi != null && aoi.Length != 0)
                        {
                            int indexFromAOI = 0;
                            for (int i = 0; i < aoi.Length; i++)
                            {
                                indexFromAOI = aoi[i];
                                if (IsFirA(rvInVistor, indexFromAOI, NearInfraredZoom, NearInfraredMax))
                                {
                                    result.Put(totalDatalength + indexFromAOI);

                                    tempValue = (maxAvgValue - rvInVistor[0].RasterBandsData[0][aoi[i]]) / dltValue;
                                    if (tempValue < rvInVistor[1].RasterBandsData[0][aoi[i]] / CoverageZoom)
                                    {
                                        resultTag.Put(totalDatalength + indexFromAOI, tempValue < 0 ? (Int16)0 : (tempValue > 1 ? (Int16)(FIRLZoom) : (Int16)(tempValue * FIRLZoom)));
                                    }
                                    else
                                    {
                                        resultTag.Put(totalDatalength + indexFromAOI, (Int16)(rvInVistor[1].RasterBandsData[0][aoi[i]] / CoverageZoom * FIRLZoom));
                                    }
                                }
                            }
                        }
                        totalDatalength += dataLength;
                        return(false);
                    }));
                    //执行
                    rfr.Excute();
                    this.Tag = resultTag;
                    return(result);
                }
            }
            finally
            {
                if (coveragePrd != null)
                {
                    coveragePrd.Dispose();
                }
            }
        }