Exemplo n.º 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 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);
        }
Exemplo n.º 2
0
        public ImportFilesObj[] AutoFindFilesByDirver(string productIdentify, string subProIdentify, IRasterDataProvider dataProvider, string dir)
        {
            if (string.IsNullOrEmpty(dir))
            {
                return(null);
            }
            if (_transDef == null)
            {
                _transDef = (new DATXMLParser()).GetTransDef();
            }
            if (_transDef == null)
            {
                return(null);
            }
            RasterIdentify rs        = new RasterIdentify(dataProvider.fileName);
            string         searchStr = "*";

            if (rs == null)
            {
                return(null);
            }
            ProductDef proDef = _transDef.GetProductBySmartProductIdentify(productIdentify);

            if (proDef != null && !string.IsNullOrEmpty(proDef.FileIdentify))
            {
                searchStr += proDef.FileIdentify + "*";
            }
            SubProductDef subProDef = proDef.GetSubProductBySmartIdentfy(subProIdentify);

            if (subProDef != null && !string.IsNullOrEmpty(subProDef.FileIdentify))
            {
                searchStr += subProDef.FileIdentify + "*";
            }
            if (!string.IsNullOrEmpty(rs.Satellite))
            {
                searchStr += rs.Satellite + "*";
            }
            if (!string.IsNullOrEmpty(rs.Sensor))
            {
                searchStr += rs.Sensor + "*";
            }
            if (rs.OrbitDateTime != DateTime.MinValue)
            {
                searchStr += rs.OrbitDateTime.ToString("yyyyMMddHHmmss") + "*";
            }
            string[] files = Directory.GetFiles(dir, searchStr + ".dat", SearchOption.AllDirectories);
            if (files == null || files.Length == 0)
            {
                return(null);
            }
            string datRegion = null;

            if (!string.IsNullOrEmpty(rs.RegionIdentify) && files.Length > 1)
            {
                for (int i = 0; i < files.Length; i++)
                {
                    datRegion = GetRegionName(files[i]);
                    if (string.IsNullOrEmpty(datRegion) || rs.RegionIdentify.IndexOf(datRegion) == -1)
                    {
                        files[i] = string.Empty;
                    }
                }
            }
            List <ImportFilesObj> importFiles = new List <ImportFilesObj>();
            ImportFilesObj        obj         = null;

            foreach (string file in files)
            {
                if (string.IsNullOrEmpty(file))
                {
                    continue;
                }
                obj = new ImportFilesObj(productIdentify, subProIdentify, Path.GetFileName(file), Path.GetDirectoryName(file));
                importFiles.Add(obj);
            }
            return(importFiles.Count == 0 ? null : importFiles.ToArray());
        }