Ejemplo n.º 1
0
        public void MvgToLdfFile()
        {
            _fname = @"E:\气象局项目\MAS二期\mvg文件\FOG_DBLV_FY3A_VIRR_1000M_DXX_P001_200911131354.mvg";
            IGeoDataDriver      drv = GeoDataDriver.GetDriverByName("MVG");
            IRasterDataProvider prd = drv.Open(_fname, enumDataProviderAccess.ReadOnly) as IRasterDataProvider;

            Assert.NotNull(prd);

            IMvgDataProvider mvgPrd    = prd as IMvgDataProvider;
            MvgHeader        mvgHeader = mvgPrd.Header;

            Assert.NotNull(mvgHeader);
            Console.WriteLine("mvgHeader.HeaderSize = " + mvgHeader.HeaderSize);
            Console.WriteLine("mvgHeader.Width = " + mvgHeader.Width);
            Console.WriteLine("mvgHeader.Height = " + mvgHeader.Height);

            mvgPrd.ToLdfFile();
            mvgPrd.Dispose();
            prd.Dispose();
            drv.Dispose();
        }
Ejemplo n.º 2
0
        private RgbStretcherProvider GetRgbStretcherProvider(string fname)
        {
            IRasterDataProvider prd = null;

            try
            {
                prd = GeoDataDriver.Open(fname) as IRasterDataProvider;
                if (prd != null && prd.BandCount == 1)
                {
                    return(new RgbStretcherProvider());
                }
            }
            finally
            {
                if (prd != null)
                {
                    prd.Dispose();
                }
            }
            return(null);
        }
Ejemplo n.º 3
0
 private StatResultItem[] AreaStatCustom(string fname, string title, Dictionary <string, int[]> aoi)
 {
     if (string.IsNullOrEmpty(title))
     {
         title = "积雪程度指数统计";
     }
     if (string.IsNullOrEmpty(fname))
     {
         return(null);
     }
     StatResultItem[] items = null;
     using (IRasterDataProvider prd = GeoDataDriver.Open(fname) as IRasterDataProvider)
     {
         if (aoi == null || aoi.Count == 0)
         {
             return(null);
         }
         items = StatAreaCustom(prd, aoi);
         return(items);
     }
 }
Ejemplo n.º 4
0
 public override void ComputeDstEnvelope(IRasterDataProvider geoRaster, ISpatialReference dstSpatialRef, out PrjEnvelope maxPrjEnvelope, Action <int, string> progressCallback)
 {
     if (geoRaster != null)
     {
         double[]    xs = null;
         double[]    ys = null;
         Size        geoSize;
         Size        maxGeoSize    = new Size(1024, 1024);//采样读取后的最大Size
         IRasterBand longitudeBand = null;
         IRasterBand latitudeBand  = null;
         ReadLocations(geoRaster, out longitudeBand, out latitudeBand);//GetGeoBand
         ReadLocations(longitudeBand, latitudeBand, maxGeoSize, out xs, out ys, out geoSize);
         Size geoRasterSize = new Size(longitudeBand.Width, longitudeBand.Height);
         TryResetLonlatForLeftRightInvalid(xs, ys, geoSize, geoRasterSize);
         _rasterProjector.ComputeDstEnvelope(_srcSpatialRef, xs, ys, geoSize, dstSpatialRef, out maxPrjEnvelope, progressCallback);
     }
     else
     {
         maxPrjEnvelope = PrjEnvelope.Empty;
     }
 }
Ejemplo n.º 5
0
 //准备[辐射定标]参数
 private void ReadyRadiationArgs(IRasterDataProvider srcRaster)
 {
     if (srcRaster == null)
     {
         throw new ArgumentNullException("srcRaster", "获取亮温转换参数失败");
     }
     try
     {
         IBandProvider srcbandpro = srcRaster.BandProvider as IBandProvider;
         _refSB_Cal_Coefficients           = ReadFileAttributeToFloat(srcbandpro, RefSB_Cal_Coefficients, 14);
         _prelaunch_Nonlinear_Coefficients = ReadFileAttributeToFloat(srcbandpro, Prelaunch_Nonlinear_Coefficients, 9);
         Size srcSize = new System.Drawing.Size(srcRaster.Width, srcRaster.Height);
         _solarZenithData           = ReadDataSetToInt16(srcbandpro, srcSize, SolarZenith, 0);
         _emissive_Radiance_Scales  = ReadDataSetToSingle(srcbandpro, new Size(3, srcSize.Height), Emissive_Radiance_Scales, 0);
         _emissive_Radiance_Offsets = ReadDataSetToSingle(srcbandpro, new Size(3, srcSize.Height), Emissive_Radiance_Offsets, 0);
     }
     catch (Exception ex)
     {
         throw new Exception("获取亮温转换参数失败", ex.InnerException);
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// 准备定位信息,计算投影后的值,并计算范围
        /// </summary>
        private void ReadyLocations(IRasterDataProvider srcRaster, ISpatialReference dstSpatialRef, Size srcSize,
                                    out double[] xs, out double[] ys, out PrjEnvelope maxPrjEnvelope, Action <int, string> progressCallback)
        {
            if (progressCallback != null)
            {
                progressCallback(1, "读取并插值经度数据集");
            }
            Size locationSize;

            ReadLocations(srcRaster, out xs, out ys, out locationSize);
            TryResetLonlatForLeftRightInvalid(xs, ys, locationSize);
            if (xs == null || xs == null)
            {
                throw new Exception("读取经纬度数据失败");
            }
            if (progressCallback != null)
            {
                progressCallback(3, "预处理经纬度数据集");
            }
            _rasterProjector.ComputeDstEnvelope(_srcSpatialRef, xs, ys, srcSize, dstSpatialRef, out maxPrjEnvelope, progressCallback);
        }
Ejemplo n.º 7
0
        private void NOAA18海洋_Click(object sender, EventArgs e)
        {
            InitExIdentify();
            _exAlg.CustomIdentify = "海洋";
            _exAlg.Satellite      = "NOAA18";
            _exAlg.Sensor         = "AVHRR";

            AlgorithmDef        alg = _sub.GetAlgorithmDefByIdentify("NOAA18Sea");
            IArgumentProvider   arg = MonitoringThemeFactory.GetArgumentProvider(_exPro, _exAlg);
            IRasterDataProvider prd = GetRasterDataProviderNOAA18();

            arg.DataProvider = prd;
            arg.AOI          = GetAOI(prd, false);
            arg.SetArg("NOAA18Sea", alg);
            SubProductBinaryDst bin = new SubProductBinaryDst(_sub);

            IPixelIndexMapper result   = bin.Make(null) as IPixelIndexMapper;
            string            saveName = @"E:\data\dst\output\3sandNoaa18Sea.png";

            CreatBitmap(prd, result.Indexes.ToArray(), saveName);
        }
Ejemplo n.º 8
0
        private void MODIS陆地_Click(object sender, EventArgs e)
        {
            InitExIdentify();
            _exAlg.CustomIdentify = "陆地";
            _exAlg.Satellite      = "EOST";
            _exAlg.Sensor         = "MODIS";

            AlgorithmDef        alg = _sub.GetAlgorithmDefByIdentify("EOSLand");
            IArgumentProvider   arg = MonitoringThemeFactory.GetArgumentProvider(_exPro, _exAlg);
            IRasterDataProvider prd = GetRasterDataProviderMODIS();

            arg.DataProvider = prd;
            arg.AOI          = GetAOI(prd, true);
            arg.SetArg("EOSLand", alg);
            SubProductBinaryDst bin = new SubProductBinaryDst(_sub);

            IPixelIndexMapper result   = bin.Make(null) as IPixelIndexMapper;
            string            saveName = @"E:\data\dst\output\2sandEOSland.png";

            CreatBitmap(prd, result.Indexes.ToArray(), saveName);
        }
Ejemplo n.º 9
0
 public TileBitmapProvider(IRasterDrawing drawing, ICanvas canvas,
                           IRasterDataProvider dataProvider,
                           TileSetting tileSetting, int[] selectedBandNos,
                           GeoDo.RSS.Core.DrawEngine.CoordEnvelope originalEnvelope,
                           float originalResolutionX, float originalResolutionY,
                           IRgbStretcherProvider stretcherProvider, string colortablename)
 {
     _drawing               = drawing;
     _canvas                = canvas;
     _dataProvider          = dataProvider;
     _tileSetting           = tileSetting;
     _selectedBandNos       = selectedBandNos;
     _loadingName           = _dataProvider.fileName;
     _colorTableName        = colortablename;
     _tilesLocator          = new NearestTilesLocator(_dataProvider, originalEnvelope, originalResolutionX, originalResolutionY);
     _tileCacheManager      = new TileBitmapCacheManager();
     _canvasEnvelopeChanged = new EventHandler(CanvasEnvelopeChanged);
     _stretcherProvider     = stretcherProvider;
     CreateDataProviderReader();
     CreateTileLoadWorker();
 }
Ejemplo n.º 10
0
        public string Do()
        {
            if (_monitoringSession == null)
            {
                return("未定义待导入哪个产品!");
            }
            IRasterDataProvider dataProvider = GetRasterDataProvider();

            if (dataProvider == null)
            {
                return("未选择待导入影像数据!");
            }
            GetDefaultInfo();
            if (_monitoringSession.ActiveMonitoringSubProduct == null)
            {
                if (!string.IsNullOrEmpty(_defaultSubPro))
                {
                    ChangedSubPro();
                }
                else
                {
                    return("未定义待导入哪个子产品!");
                }
            }
            ImportFilesObj[] objs = GetImportFileObjByForm(dataProvider);
            if (objs == null)
            {
                if (_defaultManual)
                {
                    ExecuteCommd(6634, _argsFile);
                    return(string.Empty);
                }
                else
                {
                    return("无可导入数据!");
                }
            }
            ApplayExtractResult(dataProvider, objs);
            return(string.Empty);
        }
Ejemplo n.º 11
0
 private IExtractResultBase ComputeSingleFile(string fname, IRasterExtracter <ushort, short> extracter, int[] bandNos, string express)
 {
     using (IRasterDataProvider prd = GeoDataDriver.Open(fname) as IRasterDataProvider)
     {
         if (prd == null)
         {
             return(null);
         }
         int bandCount = prd.BandCount;
         foreach (int band in bandNos)
         {
             if (bandCount == 0 || bandCount == 1)
             {
                 PrintInfo("请选择正确的局地文件进行计算。");
                 return(null);
             }
             if (bandCount < band)
             {
                 PrintInfo("获取波段序号失败,可能是波段映射表配置错误或判识算法波段参数配置错误!");
                 return(null);
             }
         }
         IArgumentProvider aPrd = new ArgumentProvider(prd, null);
         extracter.Reset(aPrd, bandNos, express);
         string filename = string.Empty;
         using (IPixelFeatureMapper <Int16> resultNDVI = new MemPixelFeatureMapper <Int16>(_identify, prd.Width * prd.Height, new System.Drawing.Size(prd.Width, prd.Height), prd.CoordEnvelope, prd.SpatialRef))
         {
             extracter.Extract(resultNDVI);
             RasterIdentify rid = GetRasterIdentify(fname);
             using (InterestedRaster <Int16> iir = new InterestedRaster <Int16>(rid, new System.Drawing.Size(prd.Width, prd.Height), prd.CoordEnvelope))
             {
                 iir.Put(resultNDVI);
                 filename = iir.FileName;
             }
             IFileExtractResult ndviResult = new FileExtractResult(_identify, filename);
             ndviResult.SetDispaly(false);
             return(ndviResult);
         }
     }
 }
Ejemplo n.º 12
0
        public static int[] GetAOIByVectorTemplate(IRasterDataProvider dataProvider, string shpTemplateName, string primaryFieldName)
        {
            string shpFullname = VectorAOITemplate.FindVectorFullname(shpTemplateName);

            if (String.IsNullOrEmpty(shpFullname))
            {
                return(null);
            }
            //step2:读取矢量
            Feature[] features = GetFeatures(shpFullname);
            if (features == null || features.Length == 0)
            {
                return(null);
            }
            //step3:矢量栅格化
            Dictionary <string, Color> nameColors = new Dictionary <string, Color>();

            using (Bitmap bitmap = VectorsToBitmap(dataProvider, features, primaryFieldName, out nameColors))
            {
                int[]      aoi;
                Color      color;
                string     name;
                List <int> items = new List <int>();
                foreach (Feature fea in features)
                {
                    name = fea.GetFieldValue(primaryFieldName);
                    if (String.IsNullOrEmpty(name))
                    {
                        continue;
                    }
                    color = nameColors[name];
                    aoi   = GetAOIByFeature(bitmap, color);
                    if (aoi != null)
                    {
                        items.AddRange(aoi);
                    }
                }
                return(items != null?items.ToArray() : null);
            }
        }
Ejemplo n.º 13
0
        unsafe private IRasterDataProvider GetSubPrd <T>(IRasterDataProvider dstPrd, IRasterDataProvider rst, RasterIdentify rasterIdentify, int offsetX, int offsetY)
        {
            string ExtInfos = rasterIdentify.ExtInfos;

            rasterIdentify.ExtInfos = DateTime.Now.ToString("HHmmss");
            IInterestedRaster <T> dst = new InterestedRaster <T>(rasterIdentify, new Size(rst.Width, rst.Height), rst.CoordEnvelope, rst.SpatialRef);

            switch (dstPrd.DataType)
            {
            case enumDataType.Int16:
                Int16[] dataBlock = new Int16[rst.Width * rst.Height];
                fixed(Int16 *buffer = dataBlock)
                {
                    IntPtr ptr = new IntPtr(buffer);

                    dstPrd.Read(offsetX, offsetY, rst.Width, rst.Height, ptr, dstPrd.DataType, rst.Width, rst.Height, 1, new int[] { 1 }, enumInterleave.BSQ);
                    IRasterBand bp = dst.HostDataProvider.GetRasterBand(1);

                    bp.Write(0, 0, rst.Width, rst.Height, ptr, enumDataType.Int16, rst.Width, rst.Height);
                }

                break;

            case enumDataType.UInt16:
                UInt16[] dataBlockUint = new UInt16[rst.Width * rst.Height];
                fixed(UInt16 *buffer = dataBlockUint)
                {
                    IntPtr ptr = new IntPtr(buffer);

                    dstPrd.Read(offsetX, offsetY, rst.Width, rst.Height, ptr, dstPrd.DataType, rst.Width, rst.Height, 1, new int[] { 1 }, enumInterleave.BSQ);
                    IRasterBand bp = dst.HostDataProvider.GetRasterBand(1);

                    bp.Write(0, 0, rst.Width, rst.Height, ptr, enumDataType.UInt16, rst.Width, rst.Height);
                }

                break;
            }
            rasterIdentify.ExtInfos = ExtInfos;
            return(dst.HostDataProvider);
        }
Ejemplo n.º 14
0
        public Dictionary <string, double> Area(IRasterDataProvider dataProvider, int[] aoi, Dictionary <string, Func <T, bool> > filterDic)
        {
            if (dataProvider.CoordEnvelope == null)
            {
                return(null);
            }
            IArgumentProvider argPrd = new ArgumentProvider(dataProvider, null);

            argPrd.AOI = aoi;
            IRasterPixelsVisitor <T> visitor = new RasterPixelsVisitor <T>(argPrd);
            int    row    = 0;
            int    width  = dataProvider.Width;
            double maxLat = dataProvider.CoordEnvelope.MaxY;
            double res    = dataProvider.ResolutionX;
            Dictionary <string, double> areas = new Dictionary <string, double>();
            int length = filterDic.Count;

            string[]         keys      = filterDic.Keys.ToArray();
            Func <T, bool>[] filters   = filterDic.Values.ToArray();
            double[]         statAreas = new double[length];
            visitor.VisitPixel(new int[] { 1 },
                               (idx, values) =>
            {
                for (int i = 0; i < length; i++)
                {
                    if (filters[i](values[0]))
                    {
                        row           = idx / width;
                        statAreas[i] += ComputePixelArea(row, maxLat, res);
                        break;
                    }
                }
            }
                               );
            for (int i = 0; i < length; i++)
            {
                areas.Add(keys[i], statAreas[i]);
            }
            return(areas);
        }
Ejemplo n.º 15
0
        private static int[] GetBands(IRasterDataProvider prd, Dictionary <string, string> argDic)
        {
            List <int> bands    = new List <int>();
            bool       argIsOK  = true;
            int        tempBand = 0;

            if (argDic.ContainsKey("Bands"))
            {
                if (argDic["Bands"].ToUpper() != "ALL")
                {
                    string[] split = argDic["Bands"].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    if (split != null && split.Length != 0)
                    {
                        for (int i = 0; i < split.Length; i++)
                        {
                            tempBand = int.Parse(split[i]);
                            if (tempBand >= prd.BandCount)
                            {
                                argIsOK = false;
                                break;
                            }
                            bands.Add(tempBand);
                        }
                    }
                }
                else
                {
                    argIsOK = false;
                }
            }
            if (!argIsOK)
            {
                bands.Clear();
                for (int i = 0; i < prd.BandCount; i++)
                {
                    bands.Add(i + 1);
                }
            }
            return(bands.ToArray());
        }
Ejemplo n.º 16
0
        /// <summary>
        /// 通用MODIS 正弦数据产品投影转换
        /// </summary>
        /// <param name="file">文件名</param>
        /// <param name="env">范围</param>
        /// <param name="res">分辨率</param>
        /// <returns></returns>
        public string PrjMODSIN(string file, string outdir, PrjEnvelope env, float res, string regionNam, Action <int, string> progressTracker)
        {
            //根据文件名解析tile号nh,nv
            UInt16 nh = 0; UInt16 nv = 0;
            string fnam = Path.GetFileNameWithoutExtension(file).ToLower();

            string[] parts = fnam.Split(new char[] { '.' });
            foreach (string part in parts)
            {
                if (part.Contains("h") & part.Contains("v"))
                {
                    nh = Convert.ToUInt16(part.Substring(1, 2));
                    nv = Convert.ToUInt16(part.Substring(4, 2));
                }
            }
            //计算图像四角坐标;
            double minX = -20015109.354 + nh * 1111950.5196666666;
            double maxX = -20015109.354 + (nh + 1) * 1111950.5196666666;
            double maxY = -10007554.677 + (18 - nv) * 1111950.5196666666;
            double minY = -10007554.677 + (18 - nv - 1) * 1111950.5196666666;

            string[] args = new string[3];
            args[0] = "datasets = 0";
            args[1] = "geoinfo=" + Convert.ToString(minX) + "," + Convert.ToString(maxX) + "," + Convert.ToString(minY) + "," + Convert.ToString(maxY) + ",1000.000,1000.000";
            args[2] = "proj4 = +proj=sinu +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs";
            ISpatialReference dstSpatialRef = SpatialReference.GetDefault();
            FilePrjSettings   prjSetting    = new FilePrjSettings();

            using (IRasterDataProvider prd = GeoDataDriver.Open(file, args) as IRasterDataProvider)
            {
                prjSetting.OutEnvelope        = env;
                prjSetting.OutResolutionX     = res;
                prjSetting.OutResolutionY     = res;
                prjSetting.OutFormat          = "LDF";
                prjSetting.OutPathAndFileName = outdir + "\\" + Path.GetFileNameWithoutExtension(file) + "_" + regionNam + "_LST.ldf";
                ProjectedFileTransform proj = new ProjectedFileTransform();
                proj.Project(prd, prjSetting, dstSpatialRef, progressTracker);
            }
            return(prjSetting.OutPathAndFileName);
        }
Ejemplo n.º 17
0
        public void TestReadHDF()//持续运行多次后,自动退出
        {
            IRasterDataProvider srcPrd = GetReader();

            MessageBox.Show("创建provider成功");
            try
            {
                for (int i = 0; i < 10; i++)
                {
                    IBandProvider srcbandpro = srcPrd.BandProvider as IBandProvider;
                    {
                        IRasterBand[] latBands = srcbandpro.GetBands("EV_1KM_RefSB");
                        IRasterBand   latBand  = latBands[0];
                        {
                            Size     srSize = new Size(latBand.Width / 2, latBand.Height / 2);
                            UInt16[] lats   = new UInt16[srSize.Width * srSize.Height];
                            unsafe
                            {
                                fixed(UInt16 *ptrLat = lats)
                                {
                                    IntPtr bufferPtrLat = new IntPtr(ptrLat);

                                    latBand.Read(0, 0, srSize.Width, srSize.Height, bufferPtrLat, enumDataType.UInt16, srSize.Width, srSize.Height);
                                }
                            }
                        }
                    }
                    MessageBox.Show("读取通道数据成功");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                srcPrd.Dispose();
                GC.SuppressFinalize(false);
            }
        }
Ejemplo n.º 18
0
        private unsafe static T[] GetDataValue <T>(IRasterDataProvider dataPrd, int bandNum)
        {
            int          width    = dataPrd.Width;
            int          height   = dataPrd.Height;
            int          length   = width * height;
            enumDataType dataType = dataPrd.DataType;
            IRasterBand  band;

            switch (dataType)
            {
            case enumDataType.Float:
            {
                float[] buffer = new float[width * height];
                band = dataPrd.GetRasterBand(bandNum);
                fixed(float *ptr = buffer)
                {
                    IntPtr bufferPtr = new IntPtr(ptr);

                    band.Read(0, 0, dataPrd.Width, dataPrd.Height, bufferPtr, enumDataType.Float, dataPrd.Width, dataPrd.Height);
                }

                return(buffer as T[]);
            }

            case enumDataType.Int16:
            {
                short[] buffer = new short[width * height];
                band = dataPrd.GetRasterBand(bandNum);
                fixed(short *ptr = buffer)
                {
                    IntPtr bufferPtr = new IntPtr(ptr);

                    band.Read(0, 0, dataPrd.Width, dataPrd.Height, bufferPtr, enumDataType.Int16, dataPrd.Width, dataPrd.Height);
                }

                return(buffer as T[]);
            }
            }
            return(null);
        }
Ejemplo n.º 19
0
 public void Dispose()
 {
     if (_readPixelHelper != null)
     {
         _readPixelHelper.Dispose();
         _readPixelHelper = null;
     }
     if (_tileBitmapProvider != null)
     {
         _tileBitmapProvider.Dispose();
         _tileBitmapProvider = null;
     }
     if (_bitmap != null)
     {
         _bitmap.Dispose();
         _bitmap = null;
     }
     if (_dataProviderCopy != null)
     {
         IUpdateCoordEnvelope u = _dataProviderCopy as IUpdateCoordEnvelope;
         if (u != null)
         {
             u.IsStoreHeaderChanged = false;
         }
         _dataProviderCopy.Dispose();
         _dataProviderCopy = null;
     }
     if (_dataProvider != null)
     {
         _dataProvider.Dispose();
         _dataProvider = null;
     }
     if (_firstBitmap != null)
     {
         _firstBitmap.Dispose();
         _firstBitmap = null;
     }
     _envelope = null;
     _canvas   = null;
 }
Ejemplo n.º 20
0
 private void ReadDnIS(IRasterDataProvider srcImgRaster, string dsName)
 {
     if (srcImgRaster == null)
     {
         throw new ArgumentNullException("srcRaster", "获取亮温转换参数失败:参数srcRaster为空");
     }
     if (dsName == null)
     {
         throw new ArgumentNullException("dataSetName", "获取亮温转换参数失败:参数srcRaster为空");
     }
     try
     {
         IBandProvider srcbandpro = srcImgRaster.BandProvider as IBandProvider;
         int           count      = srcbandpro.GetBands(dsName).Length;
         _dsIntercept = ReadDataSetAttrToFloat(srcbandpro, dsName, "Intercept", count);
         _dsSlope     = ReadDataSetAttrToFloat(srcbandpro, dsName, "Slope", count);
     }
     catch (Exception ex)
     {
         throw new Exception("获取亮温转换参数失败:" + ex.Message, ex.InnerException);
     }
 }
Ejemplo n.º 21
0
        public void CreateRasterDataPrd(string rasterFileName, int[,] dataValue)
        {
            CoordEnvelope       envelope = new CoordEnvelope(-180, 180, -90, 90);
            IRasterDataProvider dataPrd  = null;

            try
            {
                IRasterDataDriver driver = GeoDataDriver.GetDriverByName("MEM") as IRasterDataDriver;
                int    height            = (int)Math.Ceiling((envelope.MaxY - envelope.MinY) / _resolution);
                int    width             = (int)Math.Ceiling((envelope.MaxX - envelope.MinX) / _resolution);
                string mapInfo           = envelope.ToMapInfoString(new Size(width, height));
                dataPrd = driver.Create(rasterFileName, width, height, 1, enumDataType.Int16, mapInfo);
                WriteValueToRaster(dataValue, dataPrd);
            }
            finally
            {
                if (dataPrd != null)
                {
                    dataPrd.Dispose();
                }
            }
        }
Ejemplo n.º 22
0
        private string TryGetInfoFromActiveView(out BlockDef[] envelopes)
        {
            envelopes = null;
            ICanvasViewer canViewer = _smartSession.SmartWindowManager.ActiveCanvasViewer;

            if (canViewer == null)
            {
                throw new Exception("未获得激活的数据窗口");
            }
            IAOIProvider aoiProvider = canViewer.AOIProvider;

            if (aoiProvider == null)
            {
                throw new Exception("未从激活的数据窗口中获取感兴趣区域");
            }
            IRasterDrawing      drawing = canViewer.Canvas.PrimaryDrawObject as IRasterDrawing;
            IRasterDataProvider rdp     = drawing.DataProvider;

            if (rdp == null)
            {
                throw new Exception("未从激活的数据窗口中获取数据提供者");
            }
            if (rdp.DataIdentify != null && rdp.DataIdentify.IsOrbit)
            {
                throw new NotSupportedException("暂未支持轨道数据的裁切");
            }
            List <BlockDef> enves = new List <BlockDef>();

            AOIItem[] aoiitems = aoiProvider.GetAOIItems();
            if (aoiitems != null && aoiitems.Length != 0)
            {
                for (int i = 0; i < aoiitems.Length; i++)
                {
                    enves.Add(new BlockDef(aoiitems[i].Name, aoiitems[i].GeoEnvelope.MinX, aoiitems[i].GeoEnvelope.MinY, aoiitems[i].GeoEnvelope.MaxX, aoiitems[i].GeoEnvelope.MaxY));
                }
            }
            envelopes = enves.ToArray();
            return(rdp.fileName);
        }
Ejemplo n.º 23
0
        /// <summary>
        /// 计算云覆盖度
        /// </summary>
        /// <param name="dataProvider">云监测生成的判识结果文件</param>
        /// <param name="pixelCount">指定区域像素点个数(例如:太湖区域像素点总数)</param>
        /// <returns></returns>
        public float CalcCloudConvertDegree(IRasterDataProvider dataProvider, int[] aoi)
        {
            if (dataProvider == null || aoi.Count() == 0)
            {
                return(0);
            }
            long nCloud = 0;
            IRasterOperator <UInt16> rasterOper = new RasterOperator <UInt16>();

            nCloud = rasterOper.Count(dataProvider, aoi, (value) =>
            {
                if (value == 1)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            });
            return((float)nCloud / (float)aoi.Count());
        }
Ejemplo n.º 24
0
 private bool IsBigEndian(IRasterDataProvider rasterDataProvider)
 {
     using (FileStream fs = new FileStream(rasterDataProvider.fileName, FileMode.Open, FileAccess.Read))
     {
         using (BinaryReader br = new BinaryReader(fs))
         {
             byte[] buffer = new byte[2];
             fs.Seek(10, SeekOrigin.Begin);
             buffer = br.ReadBytes(2);
             br.Close();
             fs.Close();
             if (ToLocalEndian_Core.ToInt16FromBig(buffer) == 22016)
             {
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
     }
 }
Ejemplo n.º 25
0
        private void Project(IRasterDataProvider srcRaster, NOAA_PrjSettings prjSettings, ISpatialReference dstSpatialRef, Action <int, string> progressCallback)
        {
            PrjEnvelope envelops = prjSettings.OutEnvelope;

            if (envelops.IntersectsWith(_maxPrjEnvelope))
            {
                switch (prjSettings.OutFormat)
                {
                case "LDF":
                    ProjectToLDF(srcRaster, prjSettings, dstSpatialRef, progressCallback);
                    break;

                case "MEMORY":
                default:
                    throw new NotSupportedException(string.Format("暂不支持的输出格式", prjSettings.OutFormat));
                }
            }
            else
            {
                throw new Exception("数据不在目标区间内");
            }
        }
Ejemplo n.º 26
0
        public string CreateThematicGraphic(string dataFileName, string outIdentify, string extInfos, params object[] options)
        {
            if (_isNeedFitToTemplateWidth)
            {
                using (IRasterDataProvider prd = GeoDataDriver.Open(dataFileName) as IRasterDataProvider)
                {
                    if (prd != null)
                    {
                        FitTemplateWidth(_template.Layout, prd.Width, prd.Height);
                    }
                }
            }
            string       _fname = GetOutputGxdFileName(dataFileName, outIdentify, extInfos);
            IGxdDocument _doc   = GetDocument(dataFileName, _aoi, _template, options != null && options.Length > 0 ? options[0] : null);

            if (_doc == null)
            {
                return(null);
            }
            if (options.Length > 1)
            {
                PrjEnvelope envelope = options[1] as PrjEnvelope;
                if (envelope != null)
                {
                    ILayout              layout = _doc.GxdTemplateHost.LayoutTemplate.Layout;
                    IElement[]           dfs    = layout.QueryElements((e) => { return(e is IDataFrame); });
                    List <IGxdDataFrame> list   = _doc.DataFrames;
                    if (dfs != null && list != null && dfs.Length > 0 && list.Count > 0)
                    {
                        for (int i = 0; i < dfs.Length; i++)
                        {
                            ApplyAttributesOfDataFrame(list[i], dfs[i] as IDataFrame, layout, envelope);
                        }
                    }
                }
            }
            _doc.SaveAs(_fname);
            return(_fname);
        }
Ejemplo n.º 27
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);
            }
        }
Ejemplo n.º 28
0
        private static Dictionary <int, int> GetCalcBands(IRasterDataProvider prd, Dictionary <string, string> argDic)
        {
            Dictionary <int, int> CalcBands = new Dictionary <int, int>();
            bool argIsOK  = true;
            int  tempBand = 0;

            if (argDic.ContainsKey("CalcBands"))
            {
                string[] split = argDic["CalcBands"].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                string[] temp  = null;
                if (split != null && split.Length != 0)
                {
                    for (int i = 0; i < split.Length; i++)
                    {
                        if (string.IsNullOrEmpty(split[i]) || !split[i].Contains("="))
                        {
                            continue;
                        }
                        temp     = split[i].Split(new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
                        tempBand = int.Parse(temp[1]);
                        if (tempBand > prd.BandCount)
                        {
                            argIsOK = false;
                            break;
                        }
                        if (!CalcBands.ContainsKey(int.Parse(temp[0].Replace("band", ""))))
                        {
                            CalcBands.Add(int.Parse(temp[0].Replace("band", "")), tempBand);
                        }
                    }
                }
            }
            if (!argIsOK || CalcBands.Count == 0)
            {
                return(null);
            }
            CalcBands.OrderBy(curr => curr.Key);
            return(CalcBands);
        }
Ejemplo n.º 29
0
 public void Apply(IRasterDataProvider dataProvider, int[] aoi)
 {
     if (dataProvider == null)
     {
         return;
     }
     _aoi = aoi;
     if (aoi == null || aoi.Length == 0)
     {
         rdAOI.Enabled       = false;
         rdFullImage.Checked = true;
     }
     else
     {
         rdAOI.Checked = true;
     }
     _dataProvider      = dataProvider;
     _isNewDataProvider = false;
     txtFileName.Text   = _dataProvider.fileName;
     FillBands(dataProvider, tvXBands);
     FillBands(dataProvider, tvYBands);
 }
Ejemplo n.º 30
0
 private void btnSelectXFile_Click(object sender, EventArgs e)
 {
     if (_isNewXDataProvider && _XdataProvider != null)
     {
         txtXFileName.Text = string.Empty;
         _XdataProvider.Dispose();
         _XdataProvider = null;
     }
     using (OpenFileDialog dlg = new OpenFileDialog())
     {
         dlg.Filter = "All Smart Supported Files(*.*)|*.*";
         if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
         {
             _XdataProvider = TryCreateDataProvider(dlg.FileName);
             if (_XdataProvider != null)
             {
                 Apply(_XdataProvider, null, true);
                 _isNewXDataProvider = true;
             }
         }
     }
 }