示例#1
0
        public static IRasterDataProvider CreateRaster(string outFileName, IRasterDataProvider referProvider, string fname)
        {
            int width  = referProvider.Width;
            int height = referProvider.Height;

            Project.ISpatialReference spatialRef = referProvider.SpatialRef;
            enumDataType  datatype = referProvider.DataType;
            List <string> options  = new List <string>();

            options.Add("INTERLEAVE=BSQ");
            options.Add("VERSION=LDF");
            options.Add("WITHHDR=TRUE");
            options.Add("SPATIALREF=" + spatialRef.ToProj4String());
            options.Add("MAPINFO={" + 1 + "," + 1 + "}:{" + referProvider.CoordEnvelope.MinX + "," + referProvider.CoordEnvelope.MaxY + "}:{" + referProvider.ResolutionX + "," + referProvider.ResolutionY + "}"); //=env.ToMapInfoString(new Size(width, height));
            string hdrfile = HdrFile.GetHdrFileName(Path.ChangeExtension(fname, ".hdr"));

            if (!string.IsNullOrWhiteSpace(hdrfile) && File.Exists(hdrfile))
            {
                HdrFile hdr = HdrFile.LoadFrom(hdrfile);
                if (hdr != null && hdr.BandNames != null)
                {
                    options.Add("BANDNAMES=" + string.Join(",", hdr.BandNames));
                }
            }
            if (!Directory.Exists(Path.GetDirectoryName(outFileName)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(outFileName));
            }
            IRasterDataDriver  raster    = RasterDataDriver.GetDriverByName("LDF") as IRasterDataDriver;
            RasterDataProvider outRaster = raster.Create(outFileName, width, height, 1, datatype, options.ToArray()) as RasterDataProvider;

            return(outRaster);
        }
示例#2
0
        //以下为一些辅助帮助类
        public static IRasterDataProvider CreateRaster(string outFileName, CoordEnvelope env, float resolutionX, float resolutionY, int bandCount,
                                                       IRasterDataProvider referProvider)
        {
            //int bandCount = referProvider.BandCount;
            //CoordEnvelope outEnv = referProvider.CoordEnvelope;
            //float resX = referProvider.ResolutionX;
            //float resY = referProvider.ResolutionY;
            int width  = (int)(Math.Round(env.Width / resolutionX));
            int height = (int)(Math.Round(env.Height / resolutionY));

            Project.ISpatialReference spatialRef = referProvider.SpatialRef;
            enumDataType  datatype = referProvider.DataType;
            List <string> options  = new List <string>();

            options.Add("INTERLEAVE=BSQ");
            options.Add("VERSION=LDF");
            options.Add("WITHHDR=TRUE");
            options.Add("SPATIALREF=" + spatialRef.ToProj4String());
            options.Add("MAPINFO={" + 1 + "," + 1 + "}:{" + env.MinX + "," + env.MaxY + "}:{" + resolutionX + "," + resolutionY + "}"); //=env.ToMapInfoString(new Size(width, height));
            string hdrfile = HdrFile.GetHdrFileName(referProvider.fileName);

            if (!string.IsNullOrWhiteSpace(hdrfile) && File.Exists(hdrfile))
            {
                HdrFile hdr = HdrFile.LoadFrom(hdrfile);
                if (hdr != null && hdr.BandNames != null)
                {
                    options.Add("BANDNAMES=" + string.Join(",", hdr.BandNames));
                }
            }
            CheckAndCreateDir(Path.GetDirectoryName(outFileName));
            IRasterDataDriver  raster    = RasterDataDriver.GetDriverByName("LDF") as IRasterDataDriver;
            RasterDataProvider outRaster = raster.Create(outFileName, width, height, bandCount, datatype, options.ToArray()) as RasterDataProvider;

            return(outRaster);
        }
示例#3
0
        private IRasterDataProvider CreateOutRaster(string outFileName, RasterMaper[] inrasterMaper, int extHeaderLength)
        {
            IRasterDataDriver raster = RasterDataDriver.GetDriverByName("MEM") as IRasterDataDriver;
            CoordEnvelope     outEnv = null;
            float             resX   = inrasterMaper[0].Raster.ResolutionX;
            float             resY   = inrasterMaper[0].Raster.ResolutionY;

            foreach (RasterMaper inRaster in inrasterMaper)
            {
                if (outEnv == null)
                {
                    outEnv = inRaster.Raster.CoordEnvelope;
                }
                else
                {
                    outEnv = outEnv.Union(inRaster.Raster.CoordEnvelope);
                }
                if (resX < inRaster.Raster.ResolutionX)
                {
                    resX = inRaster.Raster.ResolutionX;
                }
                if (resY < inRaster.Raster.ResolutionY)
                {
                    resY = inRaster.Raster.ResolutionY;
                }
            }
            int                width     = (int)(Math.Round(outEnv.Width / resX));
            int                height    = (int)(Math.Round(outEnv.Height / resY));
            string             mapInfo   = outEnv.ToMapInfoString(new Size(width, height));
            RasterDataProvider outRaster = raster.Create(outFileName, width, height, 1, enumDataType.UInt16, mapInfo, "EXTHEADERSIZE=" + extHeaderLength) as RasterDataProvider;

            return(outRaster);
        }
示例#4
0
        protected IRasterDataProvider CreateOutRaster(string outFileName, RasterMaper[] inrasterMaper)
        {
            IRasterDataDriver raster = RasterDataDriver.GetDriverByName("MEM") as IRasterDataDriver;
            CoordEnvelope     outEnv = null;

            foreach (RasterMaper inRaster in inrasterMaper)
            {
                if (outEnv == null)
                {
                    outEnv = inRaster.Raster.CoordEnvelope;
                }
                else
                {
                    outEnv.Union(inRaster.Raster.CoordEnvelope);
                }
            }
            float              resX      = inrasterMaper[0].Raster.ResolutionX;
            float              resY      = inrasterMaper[0].Raster.ResolutionY;
            int                width     = (int)(Math.Round(outEnv.Width / resX));
            int                height    = (int)(Math.Round(outEnv.Height / resY));
            string             mapInfo   = outEnv.ToMapInfoString(new Size(width, height));
            RasterDataProvider outRaster = raster.Create(outFileName, width, height, 1, enumDataType.Int16, mapInfo) as RasterDataProvider;

            return(outRaster);
        }
示例#5
0
        protected IRasterDataProvider CreateOutM_BandRaster(string outFileName, RasterMaper[] inrasterMaper, int bandcount)
        {
            IRasterDataDriver raster = RasterDataDriver.GetDriverByName("LDF") as IRasterDataDriver;


            CoordEnvelope outEnv = null;

            foreach (RasterMaper inRaster in inrasterMaper)
            {
                if (outEnv == null)
                {
                    outEnv = inRaster.Raster.CoordEnvelope;
                }
                else
                {
                    outEnv.Union(inRaster.Raster.CoordEnvelope);
                }
            }
            float  resX    = inrasterMaper[0].Raster.ResolutionX;
            float  resY    = inrasterMaper[0].Raster.ResolutionY;
            int    width   = (int)(Math.Round(outEnv.Width / resX));
            int    height  = (int)(Math.Round(outEnv.Height / resY));
            string mapInfo = outEnv.ToMapInfoString(new Size(width, height));

            string[] optionString = new string[] {
                "INTERLEAVE=BSQ",
                "VERSION=LDF",
                "WITHHDR=TRUE",
                "SPATIALREF=" + inrasterMaper[0].Raster.SpatialRef == null?"":("SPATIALREF=" + inrasterMaper[0].Raster.SpatialRef.ToProj4String()),
                "MAPINFO={" + 1 + "," + 1 + "}:{" + outEnv.MinX + "," + outEnv.MaxY + "}:{" + resX + "," + resY + "}"
            };
            RasterDataProvider outRaster = raster.Create(outFileName, width, height, bandcount, enumDataType.UInt16, optionString) as RasterDataProvider;

            return(outRaster);
        }
示例#6
0
        private void TryCreateLDFFile(string bandfname, int bandNO, int xSize, int ySize, float[] buffer, string[] options, enumDataType dataType)
        {
            string dstDir = Path.GetDirectoryName(bandfname);

            if (!Directory.Exists(dstDir))
            {
                Directory.CreateDirectory(dstDir);
            }
            if (File.Exists(bandfname))
            {
                File.Delete(bandfname);
            }
            IRasterDataDriver driver = RasterDataDriver.GetDriverByName("LDF") as IRasterDataDriver;

            using (IRasterDataProvider bandRaster = driver.Create(bandfname, xSize, ySize, 1, dataType, options) as IRasterDataProvider)
            {
                GCHandle handle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
                try
                {
                    bandRaster.GetRasterBand(1).Write(0, 0, xSize, ySize, handle.AddrOfPinnedObject(), enumDataType.Float, xSize, ySize);
                }
                finally
                {
                    handle.Free();
                }
            }
        }
示例#7
0
        private IRasterDataProvider CreateRaster(string outFileName, IRasterDataProvider inRaster)
        {
            IRasterDataDriver  raster    = RasterDataDriver.GetDriverByName("MEM") as IRasterDataDriver;
            CoordEnvelope      outEnv    = inRaster.CoordEnvelope.Clone();
            string             mapInfo   = outEnv.ToMapInfoString(new Size(inRaster.Width, inRaster.Height));
            RasterDataProvider outRaster = raster.Create(outFileName, inRaster.Width, inRaster.Height, 1, enumDataType.Int16, mapInfo) as RasterDataProvider;

            return(outRaster);
        }
示例#8
0
        protected IRasterDataProvider CreateOutRaster(string outFileName, RasterMaper[] inrasterMaper, float resolution)
        {
            string dir = Path.GetDirectoryName(outFileName);

            if (!string.IsNullOrEmpty(dir))
            {
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
            }
            IRasterDataDriver raster = RasterDataDriver.GetDriverByName("MEM") as IRasterDataDriver;
            CoordEnvelope     outEnv = null;

            foreach (RasterMaper inRaster in inrasterMaper)
            {
                if (outEnv == null)
                {
                    outEnv = inRaster.Raster.CoordEnvelope;
                }
                else
                {
                    outEnv = outEnv.Union(inRaster.Raster.CoordEnvelope);
                }
            }
            float resX, resY;

            if (resolution != 0f)
            {
                resX = resolution;
                resY = resolution;
            }
            else
            {
                resX = inrasterMaper[0].Raster.ResolutionX;
                resY = inrasterMaper[0].Raster.ResolutionY;
                for (int i = 1; i < inrasterMaper.Length; i++)
                {
                    if (resX > inrasterMaper[i].Raster.ResolutionX)
                    {
                        resX = inrasterMaper[i].Raster.ResolutionX;
                    }
                    if (resY > inrasterMaper[i].Raster.ResolutionY)
                    {
                        resY = inrasterMaper[i].Raster.ResolutionY;
                    }
                }
            }
            int                width     = (int)(Math.Round(outEnv.Width / resX));
            int                height    = (int)(Math.Round(outEnv.Height / resY));
            string             mapInfo   = outEnv.ToMapInfoString(new Size(width, height));
            RasterDataProvider outRaster = raster.Create(outFileName, width, height, 1, enumDataType.Int16, mapInfo) as RasterDataProvider;

            return(outRaster);
        }
示例#9
0
        private IRasterDataProvider CreateMosaicRaster(string filename, GeoInfo geoHeader, int bandCount, ISpatialReference spatialRef)
        {
            IRasterDataProvider outRaster = null;

            if (File.Exists(filename))
            {
                outRaster = GeoDataDriver.Open(filename, enumDataProviderAccess.Update, null) as IRasterDataProvider;
            }
            else
            {
                float resX   = 0.01f;
                float resY   = 0.01f;
                float ltX    = 65;
                float ltY    = 60;
                int   width  = 8000;
                int   height = 7000;
                if (geoHeader == null)
                {
                    return(null);
                }
                resX   = geoHeader.ResX;
                resY   = geoHeader.ResY;
                ltX    = geoHeader.LtX;
                ltY    = geoHeader.LtY;
                width  = geoHeader.Width;
                height = geoHeader.Height;
                if (spatialRef == null)
                {
                    spatialRef = SpatialReference.GetDefault();
                }
                string dir = Path.GetDirectoryName(filename);
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
                IRasterDataDriver raster    = RasterDataDriver.GetDriverByName("LDF") as IRasterDataDriver;
                string            bandNames = "";//CreateBandNames(bandcount);
                string[]          options   = new string[] {
                    "INTERLEAVE=BSQ",
                    "VERSION=LDF",
                    "WITHHDR=TRUE",
                    "SPATIALREF=" + spatialRef.ToProj4String(),
                    "MAPINFO={" + 1 + "," + 1 + "}:{" + ltX + "," + ltY + "}:{" + resX + "," + resY + "}",
                    "BANDNAMES=" + bandNames
                };
                outRaster = raster.Create(filename, width, height, bandCount, enumDataType.UInt16, options) as RasterDataProvider;
                string outSolarZenithFile = Path.ChangeExtension(filename, ".SolarZenith.ldf");
                using (RasterDataProvider outSolarZenithRaster = raster.Create(outSolarZenithFile, width, height, 1, enumDataType.UInt16, options) as RasterDataProvider)
                { }
            }
            return(outRaster);
        }
示例#10
0
        public bool CreateRaster(string outFileName, int bandCount, enumDataType datatype, IRasterDataProvider referProvider)
        {
            CoordEnvelope env    = referProvider.CoordEnvelope;
            float         resX   = referProvider.ResolutionX;
            float         resY   = referProvider.ResolutionY;
            int           width  = referProvider.Width;
            int           height = referProvider.Height;

            Project.ISpatialReference spatialRef = referProvider.SpatialRef;
            List <string>             options    = new List <string>();

            options.Add("INTERLEAVE=BSQ");
            options.Add("VERSION=LDF");
            options.Add("WITHHDR=TRUE");
            options.Add("SPATIALREF=" + spatialRef.ToProj4String());
            options.Add("MAPINFO={" + 1 + "," + 1 + "}:{" + env.MinX + "," + env.MaxY + "}:{" + resX + "," + resY + "}"); //=env.ToMapInfoString(new Size(width, height));
            options.Add("BANDNAMES= " + "red,nir,fir");
            if (!Directory.Exists(Path.GetDirectoryName(outFileName)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(outFileName));
            }
            using (IRasterDataDriver raster = RasterDataDriver.GetDriverByName("LDF") as IRasterDataDriver)
            {
                using (RasterDataProvider outRaster = raster.Create(outFileName, width, height, bandCount, datatype, options.ToArray()) as RasterDataProvider)
                {
                    unsafe
                    {
                        fixed(UInt16 *ptr = output[0])
                        {
                            IntPtr buffer = new IntPtr(ptr);

                            outRaster.GetRasterBand(1).Write(0, 0, width, height, buffer, enumDataType.UInt16, width, height);
                        }

                        fixed(UInt16 *ptr = output[1])
                        {
                            IntPtr buffer = new IntPtr(ptr);

                            outRaster.GetRasterBand(2).Write(0, 0, width, height, buffer, enumDataType.UInt16, width, height);
                        }

                        fixed(UInt16 *ptr = output[2])
                        {
                            IntPtr buffer = new IntPtr(ptr);

                            outRaster.GetRasterBand(3).Write(0, 0, width, height, buffer, enumDataType.UInt16, width, height);
                        }
                    }
                    return(true);
                }
            }
        }
示例#11
0
        private IRasterDataProvider CreateOutRaster(string outFileName, int bandCount)
        {
            IRasterDataDriver raster     = RasterDataDriver.GetDriverByName("LDF") as IRasterDataDriver;
            CoordEnvelope     outEnv     = _dataProvider.CoordEnvelope;
            float             resX       = _dataProvider.ResolutionX;
            float             resY       = _dataProvider.ResolutionY;
            int                width     = (int)(Math.Round(outEnv.Width / resX));
            int                height    = (int)(Math.Round(outEnv.Height / resY));
            string             mapInfo   = outEnv.ToMapInfoString(new Size(width, height));
            RasterDataProvider outRaster = raster.Create(outFileName, width, height, bandCount, _dataProvider.DataType, mapInfo) as RasterDataProvider;

            return(outRaster);
        }
示例#12
0
        private IRasterDataProvider CreateOutRaster(RasterMaper rm)
        {
            RasterIdentify ri = new RasterIdentify(rm.Raster.fileName);

            ri.ProductIdentify    = _subProductDef.ProductDef.Identify;
            ri.SubProductIdentify = _subProductDef.Identify;
            string             outFileName = ri.ToWksFullFileName(".dat");
            IRasterDataDriver  raster      = RasterDataDriver.GetDriverByName("MEM") as IRasterDataDriver;
            CoordEnvelope      outEnv      = rm.Raster.CoordEnvelope;
            string             mapInfo     = outEnv.ToMapInfoString(new Size(rm.Raster.Width, rm.Raster.Height));
            RasterDataProvider outRaster   = raster.Create(outFileName, rm.Raster.Width, rm.Raster.Height, 1, enumDataType.Int16, mapInfo) as RasterDataProvider;

            return(outRaster);
        }
示例#13
0
        private IRasterDataProvider CreatOutRaster(string dstFileName, IRasterDataProvider srcDataProvider)
        {
            if (srcDataProvider == null || srcDataProvider.BandCount < 1)
            {
                return(null);
            }
            int bandCount                = srcDataProvider.BandCount;
            IRasterDataDriver  driver    = RasterDataDriver.GetDriverByName("LDF") as IRasterDataDriver;
            CoordEnvelope      outEnv    = new CoordEnvelope(-179.75, 180, -89.75, 90);
            double             resX      = outEnv.Width / _width;
            double             resY      = outEnv.Height / _height;
            string             mapInfo   = outEnv.ToMapInfoString(new Size(_width, _height));
            RasterDataProvider outRaster = driver.Create(dstFileName, _width, _height, srcDataProvider.BandCount, srcDataProvider.DataType, mapInfo) as RasterDataProvider;

            return(outRaster);
        }
示例#14
0
        private IRasterDataProvider CreateOutRaster(RasterIdentify rasterIdentify, IRasterDataProvider rasterProvider, string subProductIdentify)
        {
            IRasterDataDriver raster = RasterDataDriver.GetDriverByName("MEM") as IRasterDataDriver;
            CoordEnvelope     outEnv = rasterProvider.CoordEnvelope;
            float             resX   = rasterProvider.ResolutionX;
            float             resY   = rasterProvider.ResolutionY;
            int    width             = (int)(Math.Round(outEnv.Width / resX));
            int    height            = (int)(Math.Round(outEnv.Height / resY));
            string mapInfo           = outEnv.ToMapInfoString(new Size(width, height));

            rasterIdentify.SubProductIdentify = subProductIdentify;
            string             outFileName = rasterIdentify.ToWksFullFileName(".dat");
            RasterDataProvider outRaster   = raster.Create(outFileName, width, height, 1, enumDataType.Float, mapInfo) as RasterDataProvider;

            return(outRaster);
        }
示例#15
0
        public static bool CreateRaster(string outFileName, int bandCount, enumDataType datatype, IRasterDataProvider referProvider)
        {
            CoordEnvelope env    = referProvider.CoordEnvelope;
            float         resX   = referProvider.ResolutionX;
            float         resY   = referProvider.ResolutionY;
            int           width  = referProvider.Width;
            int           height = referProvider.Height;

            Project.ISpatialReference spatialRef = referProvider.SpatialRef;
            List <string>             options    = new List <string>();

            options.Add("INTERLEAVE=BSQ");
            options.Add("VERSION=LDF");
            options.Add("WITHHDR=TRUE");
            options.Add("SPATIALREF=" + spatialRef.ToProj4String());
            options.Add("MAPINFO={" + 1 + "," + 1 + "}:{" + env.MinX + "," + env.MaxY + "}:{" + resX + "," + resY + "}"); //=env.ToMapInfoString(new Size(width, height));
            options.Add("BANDNAMES= " + "LAI");
            //string hdrfile = HdrFile.GetHdrFileName(referProvider.fileName);
            //if (!string.IsNullOrWhiteSpace(hdrfile) && File.Exists(hdrfile))
            //{
            //    HdrFile hdr = HdrFile.LoadFrom(hdrfile);
            //    if (hdr != null && hdr.BandNames != null)
            //        options.Add("BANDNAMES=" + string.Join(",", hdr.BandNames));
            //}
            //CheckAndCreateDir();
            if (!Directory.Exists(Path.GetDirectoryName(outFileName)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(outFileName));
            }
            using (IRasterDataDriver raster = RasterDataDriver.GetDriverByName("LDF") as IRasterDataDriver)
            {
                using (RasterDataProvider outRaster = raster.Create(outFileName, width, height, bandCount, datatype, options.ToArray()) as RasterDataProvider)
                {
                    unsafe
                    {
                        fixed(UInt16 *ptr = output[0])
                        {
                            IntPtr buffer = new IntPtr(ptr);

                            outRaster.GetRasterBand(1).Write(0, 0, width, height, buffer, enumDataType.UInt16, width, height);
                        }
                    }
                    return(true);
                }
            }
        }
示例#16
0
        private IRasterDataProvider CreateOutRaster(string outFileName, RasterMaper[] rasterMaper)
        {
            IRasterDataDriver raster     = RasterDataDriver.GetDriverByName("MEM") as IRasterDataDriver;
            float             lonMin     = float.Parse(_argumentProvider.GetArg("LonMin").ToString());
            float             lonMax     = float.Parse(_argumentProvider.GetArg("LonMax").ToString());
            float             latMin     = float.Parse(_argumentProvider.GetArg("LatMin").ToString());
            float             latMax     = float.Parse(_argumentProvider.GetArg("LatMax").ToString());
            CoordEnvelope     outEnv     = new CoordEnvelope(lonMin, lonMax, latMin, latMax);
            float             resX       = rasterMaper[0].Raster.ResolutionX;
            float             resY       = rasterMaper[0].Raster.ResolutionY;
            int                width     = (int)(Math.Round(outEnv.Width / resX));
            int                height    = (int)(Math.Round(outEnv.Height / resY));
            string             mapInfo   = outEnv.ToMapInfoString(new Size(width, height));
            RasterDataProvider outRaster = raster.Create(outFileName, width, height, 1, enumDataType.Int16, mapInfo) as RasterDataProvider;

            return(outRaster);
        }
示例#17
0
        private IRasterDataProvider GetTempOutRaster(IRasterDataProvider currentRasterPrd)
        {
            string outFileName = AppDomain.CurrentDomain.BaseDirectory + "TemporalFileDir//" + Path.GetFileNameWithoutExtension(currentRasterPrd.fileName) + "_temp.ldf";

            if (!Directory.Exists(Path.GetDirectoryName(outFileName)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(outFileName));
            }
            IRasterDataDriver raster     = RasterDataDriver.GetDriverByName("LDF") as IRasterDataDriver;
            CoordEnvelope     outEnv     = currentRasterPrd.CoordEnvelope.Clone();
            int                width     = currentRasterPrd.Width;
            int                height    = currentRasterPrd.Height;
            string             mapInfo   = outEnv.ToMapInfoString(new Size(width, height));
            RasterDataProvider outRaster = raster.Create(outFileName, width, height, 1, currentRasterPrd.DataType, mapInfo) as RasterDataProvider;

            return(outRaster);
        }
示例#18
0
        private IRasterDataProvider CreateOutRaster(string outFileName, enumDataType dataType, RasterMaper[] inrasterMaper, float resolution, Int16 zoom)
        {
            IRasterDataDriver raster = RasterDataDriver.GetDriverByName("MEM") as IRasterDataDriver;
            CoordEnvelope     outEnv = null;

            foreach (RasterMaper inRaster in inrasterMaper)
            {
                if (outEnv == null)
                {
                    outEnv = inRaster.Raster.CoordEnvelope;
                }
                else
                {
                    outEnv = outEnv.Intersect(inRaster.Raster.CoordEnvelope);
                }
            }
            float resX, resY;

            if (resolution != 0f)
            {
                resX = resolution;
                resY = resolution;
            }
            else
            {
                resX = inrasterMaper[0].Raster.ResolutionX;
                resY = inrasterMaper[0].Raster.ResolutionY;
            }
            int width  = (int)(Math.Round(outEnv.Width / resX));
            int height = (int)(Math.Round(outEnv.Height / resY));

            if (inrasterMaper.Length == 1 && zoom != 1)
            {
                outEnv = new CoordEnvelope(outEnv.MinX - resX * zoom / 2, outEnv.MaxX - resX * zoom / 2, outEnv.MinY + resX * zoom / 2, outEnv.MaxY + resX * zoom / 2);
            }
            string mapInfo = outEnv.ToMapInfoString(new Size(width, height));

            if (File.Exists(outFileName))
            {
                File.Delete(outFileName);
            }
            RasterDataProvider outRaster = raster.Create(outFileName, width, height, 1, dataType, mapInfo) as RasterDataProvider;

            return(outRaster);
        }
示例#19
0
        private IRasterDataProvider CreatOutputRaster(string outFileName, enumDataType dataType, int width, int height)
        {
            IRasterDataDriver raster = RasterDataDriver.GetDriverByName("MEM") as IRasterDataDriver;
            CoordEnvelope     outEnv = null;

            switch (width)
            {
            case 400: outEnv = new CoordEnvelope(119.6875, 120.6875, 30.7375, 31.7375);
                break;

            case 500: outEnv = new CoordEnvelope(119.776253, 121.026253, 30.67375, 31.92375);
                break;

            case 600: outEnv = new CoordEnvelope(119.651253, 121.151253, 30.54875, 32.04875);
                break;
            }
            string             mapInfo   = outEnv.ToMapInfoString(new Size(width, height));
            RasterDataProvider outRaster = raster.Create(outFileName, width, height, 1, dataType, mapInfo) as RasterDataProvider;

            return(outRaster);
        }
示例#20
0
        //创建输出删格文件
        protected IRasterDataProvider CreateOutRaster(string outFileName, enumDataType dataType, RasterMaper[] inrasterMaper, float resolution)
        {
            IRasterDataDriver raster = RasterDataDriver.GetDriverByName("MEM") as IRasterDataDriver;

            GeoDo.RSS.Core.DF.CoordEnvelope outEnv = null;
            foreach (RasterMaper inRaster in inrasterMaper)
            {
                if (outEnv == null)
                {
                    outEnv = inRaster.Raster.CoordEnvelope;
                }
                else
                {
                    outEnv = outEnv.Intersect(inRaster.Raster.CoordEnvelope);
                }
            }
            float resX, resY;

            if (resolution != 0f)
            {
                resX = resolution;
                resY = resolution;
            }
            else
            {
                resX = inrasterMaper[0].Raster.ResolutionX;
                resY = inrasterMaper[0].Raster.ResolutionY;
            }
            int    width   = (int)(Math.Round(outEnv.Width / resX));
            int    height  = (int)(Math.Round(outEnv.Height / resY));
            string mapInfo = outEnv.ToMapInfoString(new Size(width, height));

            if (File.Exists(outFileName))
            {
                File.Delete(outFileName);
            }
            RasterDataProvider outRaster = raster.Create(outFileName, width, height, 1, dataType, mapInfo) as RasterDataProvider;

            return(outRaster);
        }
示例#21
0
        private IRasterDataProvider CreateOutRaster(string fileName, RasterMaper[] rasterMaper)
        {
            string            extension = Path.GetExtension(fileName).ToUpper();
            IRasterDataDriver raster    = null;

            if (extension == ".LDF")
            {
                raster = RasterDataDriver.GetDriverByName("LDF") as IRasterDataDriver;
            }
            else if (extension == ".DAT")
            {
                raster = RasterDataDriver.GetDriverByName("MEM") as IRasterDataDriver;
            }
            int                width     = (int)(txtWidth.Value);
            int                height    = (int)(txtHeight.Value);
            double             minY      = txtMaxLat.Value - _resolution * height;
            double             maxX      = txtMinLon.Value + _resolution * width;
            CoordEnvelope      outEnv    = new CoordEnvelope(txtMinLon.Value, maxX, minY, txtMaxLat.Value);
            string             mapInfo   = outEnv.ToMapInfoString(new Size(width, height));
            RasterDataProvider outRaster = raster.Create(fileName, width, height, 1, rasterMaper[0].Raster.DataType, mapInfo) as RasterDataProvider;

            return(outRaster);
        }
示例#22
0
        private IRasterDataProvider CreateOutputFile(RasterMaper[] inputRasterMapers, string outFileName, float resolution)
        {
            IRasterDataDriver raster = RasterDataDriver.GetDriverByName("MEM") as IRasterDataDriver;
            CoordEnvelope     outEnv = null;

            foreach (RasterMaper maper in inputRasterMapers)
            {
                if (outEnv == null)
                {
                    outEnv = maper.Raster.CoordEnvelope;
                }
                else
                {
                    outEnv = outEnv.Union(maper.Raster.CoordEnvelope);
                }
            }
            int                width     = (int)(Math.Round(outEnv.Width / resolution));
            int                height    = (int)(Math.Round(outEnv.Height / resolution));
            string             mapInfo   = outEnv.ToMapInfoString(new Size(width, height));
            RasterDataProvider outRaster = raster.Create(outFileName, width, height, 1, inputRasterMapers[0].Raster.DataType, mapInfo) as RasterDataProvider;

            return(outRaster);
        }
示例#23
0
        public void Calc()
        {
            Stopwatch sw = new Stopwatch();

            sw.Start();
            Action <int, string> progres = new Action <int, string>(
                (progress, text) =>
            {
                //this.progressBar1.Value = progress;
                //this.Text = text;
                //Application.DoEvents();
                Console.WriteLine(progress);
            }
                );
            //举例计算NDVI
            RasterProcessModel <ushort, short> rfr = null;

            RasterMaper[] fileIns  = null;
            RasterMaper[] fileOuts = null;
            try
            {
                string fin = @"E:\Smart\MAS\ldf\FY3A_MERSI_GBAL_L1_20120517_0235_0250M_MS_GLL_DXX.ldf";
                //fin = @"E:\Smart\ldf\FY3A_MERSI_海南省_GLL_L1_20120911_D_0250M_MS.ldf";
                fin = @"E:\Smart\MAS\ldf\FY3B_MERSI_20120510_0640.LDF";
                RasterDataProvider or = RasterDataDriver.Open(fin) as RasterDataProvider;
                //初始化输出数据,这里输出为dat,可根据实际需求,自行决定输出文件格式
                IRasterDataDriver dd      = RasterDataDriver.GetDriverByName("MEM") as IRasterDataDriver;
                string            mapInfo = or.CoordEnvelope.ToMapInfoString(new Size(or.Width * 2, or.Height * 2));
                //"MAPINFO={X,Y}:{Col,Row}:{ResolutionX,ResolutionY}";
                //mapInfo = "MAPINFO={1,1}:{108.0904,20.1572}:{0.0025,0.0025}";
                //输出数据和输入数据的范围可以不一致
                RasterDataProvider tr = dd.Create(@"E:\Smart\ldf\FY3A_MERSI_海南省_GLL_L1_20120911_D_0250M_MS_NDVI.dat", or.Width, or.Height, 1, enumDataType.Int16, mapInfo) as RasterDataProvider;
                tr.GetRasterBand(1).Fill(-999);

                RasterMaper fileIn  = new RasterMaper(or, new int[] { 3, 4 });
                RasterMaper fileOut = new RasterMaper(tr, new int[] { 1 });
                fileIns  = new RasterMaper[] { fileIn };
                fileOuts = new RasterMaper[] { fileOut };
                //创建处理器
                rfr = new RasterProcessModel <ushort, short>(progres);
                rfr.SetRaster(fileIns, fileOuts);
                rfr.SetTemplateAOI("vector:海陆模版");
                rfr.RegisterCalcModel(new RasterCalcHandler <ushort, short>((rvInVistor, rvOutVistor, aoiIndex) =>
                {
                    if (rvInVistor[0].RasterBandsData != null)
                    {
                        if (rvInVistor == null)
                        {
                            return;
                        }
                        ushort[] inBand0 = rvInVistor[0].RasterBandsData[0]; //第1个输入文件的第1个波段的各像素值
                        ushort[] inBand1 = rvInVistor[0].RasterBandsData[1]; //第1个输入文件的第2个波段的各像素值
                        short[] ndvi     = new short[inBand0.Length];
                        if (aoiIndex != null)
                        {
                            int index;
                            for (int i = 0; i < aoiIndex.Length; i++)
                            {
                                index = aoiIndex[i];
                                rvOutVistor[0].RasterBandsData[0][index] = (short)((inBand1[index] - inBand0[index]) * 1000f / (inBand1[index] + inBand0[index]));
                            }
                        }
                        //else
                        //{
                        //    for (int i = 0; i < inBand0.Length; i++)
                        //    {
                        //        //第1个输出文件的第1个波段存储NDVI值
                        //        rvOutVistor[0].RasterBandsData[0][i] = (short)((inBand1[i] - inBand0[i]) * 1000f / (inBand1[i] + inBand0[i]));
                        //        //通道1和通道2的差值
                        //        //fileOutVistor[0].RasterBandsData[1][p] = (short)(inBand0[p] - inBand1[p]);
                        //    }
                        //}
                    }
                }));
                rfr.Excute();
            }
            finally
            {
                if (fileIns != null)
                {
                    for (int i = 0; i < fileIns.Length; i++)
                    {
                        fileIns[i].Raster.Dispose();
                    }
                }
                if (fileOuts != null)
                {
                    for (int i = 0; i < fileOuts.Length; i++)
                    {
                        fileOuts[i].Raster.Dispose();
                    }
                }
            }
            sw.Stop();
            Console.WriteLine((sw.ElapsedMilliseconds / 1000f).ToString() + "秒");
        }
示例#24
0
        private IExtractResult CalcEVIAlgorithm1(string inputFile, int[] bandNos, float zoom, double[] bandZoom, float[] cloudyArgs, Int16 defCloudy, bool isFitterCloud, string aoiTemplate, Action <int, string> progressTracker)
        {
            string cloudFileName = FindCloudExtractResult(inputFile);
            float  g, c1, c2, l;

            try
            {
                g  = (float)_argumentProvider.GetArg("G");
                c1 = (float)_argumentProvider.GetArg("C1");
                c2 = (float)_argumentProvider.GetArg("C2");
                l  = (float)_argumentProvider.GetArg("L");
            }
            catch (Exception)
            {
                PrintInfo("计算参数获取失败,请重新设置!");
                return(null);
            }
            bool isAppCloud;

            if (!bool.TryParse(_argumentProvider.GetArg("isAppCloud").ToString(), out isAppCloud))
            {
                PrintInfo("合并交互云参数设置不正确!");
                return(null);
            }
            IRasterDataProvider clmPrd            = null;
            RasterProcessModel <short, short> rfr = null;
            List <RasterMaper> fileIns            = new List <RasterMaper>();

            RasterMaper[] fileOuts = null;
            try
            {
                //输入数据(LDF)
                IRasterDataProvider inRaster = RasterDataDriver.Open(inputFile) as IRasterDataProvider;
                if (inRaster == null)
                {
                    PrintInfo("读取栅格文件失败:" + inRaster);
                    return(null);
                }
                //输出数据(EVI)
                string            outFileName = GetFileName(new string[] { inRaster.fileName }, _subProductDef.ProductDef.Identify, _identify, ".dat", null);
                IRasterDataDriver dd          = RasterDataDriver.GetDriverByName("MEM") as IRasterDataDriver;
                string            mapInfo     = inRaster.CoordEnvelope.ToMapInfoString(new Size(inRaster.Width, inRaster.Height));
                string[]          opts        = new string[] {
                    "INTERLEAVE=BSQ",
                    "VERSION=MEM",
                    "WITHHDR=TRUE",
                    "SPATIALREF=" + inRaster.SpatialRef.ToProj4String(),
                    mapInfo
                };
                RasterDataProvider outRaster = dd.Create(outFileName, inRaster.Width, inRaster.Height, 1, enumDataType.Int16, opts) as RasterDataProvider;
                string             clmFile   = GetClmFile(inputFile);
                int cloudCH = GetCloudCHNO();
                //栅格数据映射
                fileIns.Add(new RasterMaper(inRaster, bandNos));
                if (isAppCloud)
                {
                    if (!string.IsNullOrEmpty(clmFile) && File.Exists(clmFile))
                    {
                        clmPrd = GeoDataDriver.Open(clmFile) as IRasterDataProvider;
                        if (clmPrd.BandCount < cloudCH)
                        {
                            PrintInfo("请选择正确的云数据通道进行计算.");
                            isAppCloud = false;
                        }
                        else
                        {
                            fileIns.Add(new RasterMaper(clmPrd, new int[] { cloudCH }));
                        }
                    }
                    else
                    {
                        isAppCloud = false;
                    }
                }

                RasterMaper fileOut = new RasterMaper(outRaster, new int[] { 1 });
                fileOuts = new RasterMaper[] { fileOut };
                //创建处理模型
                rfr = new RasterProcessModel <short, short>(progressTracker);
                rfr.SetRaster(fileIns.ToArray(), fileOuts);
                rfr.SetTemplateAOI(aoiTemplate);
                rfr.RegisterCalcModel(new RasterCalcHandler <short, short>((rvInVistor, rvOutVistor, aoi) =>
                {
                    if (rvInVistor[0].RasterBandsData != null)
                    {
                        if (rvInVistor == null)
                        {
                            return;
                        }
                        short[] inBand0 = rvInVistor[0].RasterBandsData[0];                     //第1个输入文件的第1个波段的各像素值
                        short[] inBand1 = rvInVistor[0].RasterBandsData[1];                     //第1个输入文件的第2个波段的各像素值
                        short[] inBand2 = rvInVistor[0].RasterBandsData[2];                     //第1个输入文件的第3个波段的各像素值
                        short[] inBand3 = rvInVistor[0].RasterBandsData[3];                     //第1个输入文件的第4个波段的各像素值
                        short[] inBand4 = rvInVistor[0].RasterBandsData[4];                     //第1个输入文件的第5个波段的各像素值
                        short[] inBand5 = isAppCloud ? rvInVistor[1].RasterBandsData[0] : null; //第2个输入文件的第1个波段的各像素值
                        short[] ndvi    = new short[inBand0.Length];
                        if (string.IsNullOrWhiteSpace(aoiTemplate))
                        {
                            for (int index = 0; index < inBand0.Length; index++)
                            {
                                if ((isAppCloud && inBand5[index] == 1) || (isFitterCloud && inBand1[index] / bandZoom[1] > cloudyArgs[0] && inBand4[index] / bandZoom[4] < cloudyArgs[1] && Math.Abs(inBand3[index] / bandZoom[3] - inBand4[index] / bandZoom[4]) > cloudyArgs[2]))
                                {
                                    rvOutVistor[0].RasterBandsData[0][index] = defCloudy;
                                    continue;
                                }
                                //第1个输出文件的第1个波段存储EVI值
                                rvOutVistor[0].RasterBandsData[0][index] = (short)(g * (float)(inBand1[index] / bandZoom[1] - inBand0[index] / bandZoom[0]) / (inBand1[index] / bandZoom[1] + c1
                                                                                                                                                               * inBand0[index] / bandZoom[0] - c2 * inBand2[index] / bandZoom[2] + l) * zoom);
                            }
                        }
                        else if (aoi != null && aoi.Length != 0)
                        {
                            int index;
                            for (int i = 0; i < aoi.Length; i++)
                            {
                                index = aoi[i];
                                if ((isAppCloud && inBand5[index] == 1) || (isFitterCloud && inBand1[index] / bandZoom[1] > cloudyArgs[0] && inBand4[index] / bandZoom[4] < cloudyArgs[1] && Math.Abs(inBand3[index] / bandZoom[3] - inBand4[index] / bandZoom[4]) > cloudyArgs[2]))
                                {
                                    rvOutVistor[0].RasterBandsData[0][index] = defCloudy;
                                    continue;
                                }
                                //第1个输出文件的第1个波段存储EVI值
                                rvOutVistor[0].RasterBandsData[0][index] = (short)(g * (float)(inBand1[index] / bandZoom[1] - inBand0[index] / bandZoom[0]) / (inBand1[index] / bandZoom[1] + c1
                                                                                                                                                               * inBand0[index] / bandZoom[0] - c2 * inBand2[index] / bandZoom[2] + l) * zoom);
                            }
                        }
                    }
                }));
                //执行
                rfr.Excute();
                FileExtractResult res = new FileExtractResult(_subProductDef.Identify, outFileName, true);
                res.SetDispaly(false);
                return(res);
            }
            finally
            {
                if (fileIns != null)
                {
                    for (int i = 0; i < fileIns.Count; i++)
                    {
                        fileIns[i].Raster.Dispose();
                    }
                }
                if (fileOuts != null)
                {
                    for (int i = 0; i < fileOuts.Length; i++)
                    {
                        fileOuts[i].Raster.Dispose();
                    }
                }
                if (clmPrd != null)
                {
                    clmPrd.Dispose();
                }
            }
        }
示例#25
0
        private IExtractResult IceConverageAlgorithmWithAOI(Action <int, string> progressTracker)
        {
            enumDataType dataType;
            int          xSize, ySize, length;

            short[]  nicDataBuffer = null;
            string[] options       = null;
            using (IRasterDataProvider selectRaster = GeoDataDriver.Open(_fileName, _fileOpenArgs) as IRasterDataProvider)
            {
                dataType      = selectRaster.DataType;
                xSize         = selectRaster.Width;
                ySize         = selectRaster.Height;
                length        = xSize * ySize;
                nicDataBuffer = new short[xSize * ySize];
                using (IRasterDataProvider aoiRaster = GeoDataDriver.Open(_aoiFileName) as IRasterDataProvider)
                {
                    if (aoiRaster.Width != selectRaster.Width || aoiRaster.Height != selectRaster.Height)
                    {
                        return(null);
                    }
                    byte[]   aoi        = new byte[xSize * ySize];
                    GCHandle aoiHandle  = GCHandle.Alloc(aoi, GCHandleType.Pinned);
                    GCHandle dataHandle = GCHandle.Alloc(nicDataBuffer, GCHandleType.Pinned);
                    try
                    {
                        aoiRaster.GetRasterBand(1).Read(0, 0, xSize, ySize, aoiHandle.AddrOfPinnedObject(), enumDataType.Byte, xSize, ySize);
                        selectRaster.GetRasterBand(1).Read(0, 0, xSize, ySize, dataHandle.AddrOfPinnedObject(), enumDataType.Int16, xSize, ySize);
                        for (int i = 0; i < length; i++)
                        {
                            if (aoi[i] == 0 && nicDataBuffer[i] > 0 && nicDataBuffer[i] <= 100) //移除感兴趣区域外的海冰
                            {
                                nicDataBuffer[i] = 0;                                           //陆地是120,海洋0,目前是将误判的海冰设置为海洋
                            }
                            else if (aoi[i] == 1 && nicDataBuffer[i] == 110)
                            {
                                nicDataBuffer[i] = 100;//感兴趣区域内的无效区域填充为冰
                            }
                        }
                    }
                    finally
                    {
                        aoiHandle.Free();
                        dataHandle.Free();
                    }
                }
                //生成新的海冰覆盖度文件。
                options = CreateLDFOptions(selectRaster);
            }
            string            newfile = MifEnvironment.GetFullFileName(Path.GetFileNameWithoutExtension(_fileName) + Guid.NewGuid().ToString() + ".ldf");//系统配置的Temp目录
            IRasterDataDriver driver  = RasterDataDriver.GetDriverByName("LDF") as IRasterDataDriver;

            using (IRasterDataProvider newRaster = driver.Create(newfile, xSize, ySize, 1, dataType, options) as IRasterDataProvider)
            {
                GCHandle handle = GCHandle.Alloc(nicDataBuffer, GCHandleType.Pinned);
                try
                {
                    newRaster.GetRasterBand(1).Write(0, 0, xSize, ySize, handle.AddrOfPinnedObject(), dataType, xSize, ySize);
                }
                finally
                {
                    handle.Free();
                }
                _fileName     = newfile;
                _fileOpenArgs = "";
            }
            return(IceConverageAlgorithm(progressTracker));
        }
示例#26
0
        /// <summary>
        /// 根据当前绘制的AOI生成新的南极或北极海冰AOI文件。
        /// 如果当前绘制AOI的文件和当前要出专题图的文件区域一致时候(都是北极或都是南极),才生成新的AOI文件
        /// </summary>
        private void TryCreateNewAoiFile()
        {
            //获取当前视窗AOI以及Raster
            _session = _argumentProvider.GetArg("SmartSession") as ISmartSession;
            ICanvasViewer cv = _session.SmartWindowManager.ActiveCanvasViewer;

            if (cv == null)
            {
                return;
            }
            IRasterDrawing drawing = cv.ActiveObject as IRasterDrawing;

            if (drawing == null || drawing.DataProvider == null)
            {
                return;
            }
            IRasterDataProvider canvasRaster = drawing.DataProvider;

            int[] drawedAOI = cv.AOIProvider.GetIndexes();
            if (drawedAOI == null || drawedAOI.Length == 0)
            {
                return;
            }
            //如果当前算法面板设置的海冰覆盖度 和 当前打开的不匹配,则不生成或更新AOI文件
            using (IRasterDataProvider selectedRaster = GeoDataDriver.Open(_fileName, _fileOpenArgs) as IRasterDataProvider)
            {
                if (selectedRaster == null)
                {
                    return;
                }
                if (selectedRaster.Width != canvasRaster.Width || selectedRaster.Height != canvasRaster.Height)
                {
                    return;
                }
            }
            if (File.Exists(_aoiFileName))//这里存疑,不能简单的这么删除,应当待后面的新文件生成后再删除该文件
            {
                File.Delete(_aoiFileName);
            }
            int xSize = canvasRaster.Width;
            int ySize = canvasRaster.Height;
            ISpatialReference spatialReference = canvasRaster.SpatialRef;
            CoordEnvelope     env = canvasRaster.CoordEnvelope;
            //创建Aoi文件
            IRasterDataDriver driver = RasterDataDriver.GetDriverByName("LDF") as IRasterDataDriver;

            string[] options = CreateLDFOptions(canvasRaster);
            using (IRasterDataProvider aoiRaster = driver.Create(_aoiFileName, xSize, ySize, 1, enumDataType.Byte, options) as IRasterDataProvider)
            {
                byte[] buffer = new byte[xSize * ySize];
                foreach (int i in drawedAOI)
                {
                    buffer[i] = 1;
                }
                GCHandle handle = GCHandle.Alloc(buffer, GCHandleType.Pinned);
                try
                {
                    aoiRaster.GetRasterBand(1).Write(0, 0, xSize, ySize, handle.AddrOfPinnedObject(), enumDataType.Byte, xSize, ySize);
                }
                finally
                {
                    handle.Free();
                }
            }
        }
        /// <summary>
        /// 单文件计算其NDVI
        /// </summary>
        /// <param name="inputFile"></param>
        /// <param name="bandNos"></param>
        /// <param name="zoom"></param>
        /// <param name="aoiTemplate"></param>
        /// <param name="progressTracker"></param>
        /// <returns></returns>
        private IExtractResult CalcNDVI(string inputFile, int[] bandNos, float zoom, string aoiTemplate, Action <int, string> progressTracker)
        {
            RasterProcessModel <ushort, short> rfr = null;

            RasterMaper[] fileIns  = null;
            RasterMaper[] fileOuts = null;
            try
            {
                //输入数据(LDF)
                IRasterDataProvider inRaster = RasterDataDriver.Open(inputFile) as IRasterDataProvider;
                if (inRaster == null)
                {
                    PrintInfo("读取栅格文件失败:" + inRaster);
                    return(null);
                }
                //输出数据(NDVI)
                string             outFileName = GetFileName(new string[] { inRaster.fileName }, _subProductDef.ProductDef.Identify, _identify, ".ldf", null);
                IRasterDataDriver  dd          = RasterDataDriver.GetDriverByName("LDF") as IRasterDataDriver;
                string             mapInfo     = inRaster.CoordEnvelope.ToMapInfoString(new Size(inRaster.Width, inRaster.Height));
                RasterDataProvider outRaster   = dd.Create(outFileName, inRaster.Width, inRaster.Height, 1, enumDataType.Int16, mapInfo) as RasterDataProvider;
                //栅格数据映射
                RasterMaper fileIn  = new RasterMaper(inRaster, bandNos);
                RasterMaper fileOut = new RasterMaper(outRaster, new int[] { 1 });
                fileIns  = new RasterMaper[] { fileIn };
                fileOuts = new RasterMaper[] { fileOut };
                //创建处理模型
                rfr = new RasterProcessModel <ushort, short>(progressTracker);
                rfr.SetRaster(fileIns, fileOuts);
                rfr.SetTemplateAOI(aoiTemplate);
                rfr.RegisterCalcModel(new RasterCalcHandler <ushort, short>((rvInVistor, rvOutVistor, aoi) =>
                {
                    if (rvInVistor[0].RasterBandsData != null)
                    {
                        if (rvInVistor == null)
                        {
                            return;
                        }
                        ushort[] inBand0 = rvInVistor[0].RasterBandsData[0]; //第1个输入文件的第1个波段的各像素值
                        ushort[] inBand1 = rvInVistor[0].RasterBandsData[1]; //第1个输入文件的第2个波段的各像素值
                        short[] ndvi     = new short[inBand0.Length];
                        if (string.IsNullOrWhiteSpace(aoiTemplate))
                        {
                            for (int index = 0; index < inBand0.Length; index++)
                            {
                                //第1个输出文件的第1个波段存储NDVI值
                                rvOutVistor[0].RasterBandsData[0][index] = (short)((inBand1[index] - inBand0[index]) * zoom / (inBand1[index] + inBand0[index]));
                            }
                        }
                        else if (aoi != null && aoi.Length != 0)
                        {
                            int index;
                            for (int i = 0; i < aoi.Length; i++)
                            {
                                index = aoi[i];
                                //第1个输出文件的第1个波段存储NDVI值
                                rvOutVistor[0].RasterBandsData[0][index] = (short)((inBand1[index] - inBand0[index]) * zoom / (inBand1[index] + inBand0[index]));
                            }
                        }
                    }
                }));
                //执行
                rfr.Excute();
                FileExtractResult res = new FileExtractResult(_subProductDef.Identify, outFileName, true);
                res.SetDispaly(false);
                return(res);
            }
            finally
            {
                if (fileIns != null)
                {
                    for (int i = 0; i < fileIns.Length; i++)
                    {
                        fileIns[i].Raster.Dispose();
                    }
                }
                if (fileOuts != null)
                {
                    for (int i = 0; i < fileOuts.Length; i++)
                    {
                        fileOuts[i].Raster.Dispose();
                    }
                }
            }
        }
示例#28
0
        /// <summary>
        /// 单文件计算其NDVI
        /// </summary>
        /// <param name="inputFile"></param>
        /// <param name="bandNos"></param>
        /// <param name="zoom"></param>
        /// <param name="aoiTemplate"></param>
        /// <param name="progressTracker"></param>
        /// <returns></returns>
        private IExtractResult CalcNDVI(string inputFile, int[] bandNos, float zoom, double[] CloudyZoom, float[] cloudyArgs, Int16 defCloudy, bool isFitterCloud, bool isAppCloud, string aoiTemplate, Action <int, string> progressTracker)
        {
            //查找输入文件对应的云判识结果文件
            RasterProcessModel <ushort, short> rfr = null;
            List <RasterMaper> fileIns             = new List <RasterMaper>();

            RasterMaper[]       fileOuts = null;
            IRasterDataProvider clmPrd   = null;

            try
            {
                //输入数据(LDF)
                IRasterDataProvider inRaster = RasterDataDriver.Open(inputFile) as IRasterDataProvider;
                if (inRaster == null)
                {
                    PrintInfo("读取栅格文件失败:" + inRaster);
                    return(null);
                }
                //输出数据(NDVI)
                string            outFileName = GetFileName(new string[] { inRaster.fileName }, _subProductDef.ProductDef.Identify, _identify, ".dat", null);
                IRasterDataDriver dd          = RasterDataDriver.GetDriverByName("MEM") as IRasterDataDriver;
                string            mapInfo     = inRaster.CoordEnvelope.ToMapInfoString(new Size(inRaster.Width, inRaster.Height));
                string[]          opts        = new string[] {
                    "INTERLEAVE=BSQ",
                    "VERSION=MEM",
                    "WITHHDR=TRUE",
                    "SPATIALREF=" + inRaster.SpatialRef.ToProj4String(),
                    mapInfo
                };

                RasterDataProvider outRaster = dd.Create(outFileName, inRaster.Width, inRaster.Height, 1, enumDataType.Int16, opts) as RasterDataProvider;
                outRaster.GetRasterBand(1).Fill(Int16.MinValue);
                string clmFile = GetClmFile(inputFile);
                int    cloudCH = GetCloudCHNO();
                //栅格数据映射
                fileIns.Add(new RasterMaper(inRaster, bandNos));
                if (isAppCloud)
                {
                    if (!string.IsNullOrEmpty(clmFile) && File.Exists(clmFile))
                    {
                        clmPrd = GeoDataDriver.Open(clmFile) as IRasterDataProvider;
                        if (clmPrd.BandCount < cloudCH)
                        {
                            PrintInfo("请选择正确的云数据通道进行计算.");
                            isAppCloud = false;
                        }
                        else
                        {
                            fileIns.Add(new RasterMaper(clmPrd, new int[] { cloudCH }));
                        }
                    }
                    else
                    {
                        isAppCloud = false;
                    }
                }
                RasterMaper fileOut = new RasterMaper(outRaster, new int[] { 1 });
                //创建处理模型
                fileOuts = new RasterMaper[] { fileOut };
                rfr      = new RasterProcessModel <ushort, short>(progressTracker);
                rfr.SetRaster(fileIns.ToArray(), fileOuts);
                rfr.SetTemplateAOI(aoiTemplate);
                rfr.RegisterCalcModel(new RasterCalcHandler <ushort, short>((rvInVistor, rvOutVistor, aoi) =>
                {
                    if (rvInVistor[0].RasterBandsData != null)
                    {
                        if (rvInVistor == null)
                        {
                            return;
                        }
                        ushort[] inBand0  = rvInVistor[0].RasterBandsData[0];                     //第1个输入文件的第1个波段的各像素值
                        ushort[] inBand1  = rvInVistor[0].RasterBandsData[1];                     //第1个输入文件的第2个波段的各像素值
                        ushort[] inBand2  = rvInVistor[0].RasterBandsData[2];                     //第1个输入文件的第3个波段的各像素值
                        ushort[] inBand3  = rvInVistor[0].RasterBandsData[3];                     //第1个输入文件的第4个波段的各像素值
                        ushort[] inBand12 = isAppCloud ? rvInVistor[1].RasterBandsData[0] : null; //第2个输入文件的第1个波段的各像素值
                        short[] ndvi      = new short[inBand0.Length];
                        if (aoi == null || aoi.Length == 0)
                        {
                            for (int index = 0; index < inBand0.Length; index++)
                            {
                                if ((inBand12 != null && inBand12[index] != 0) || (isFitterCloud && inBand1[index] / CloudyZoom[0] > cloudyArgs[0] && inBand3[index] / CloudyZoom[2] < cloudyArgs[1] && Math.Abs(inBand2[index] / CloudyZoom[1] - inBand3[index] / CloudyZoom[2]) > cloudyArgs[2]))
                                {
                                    rvOutVistor[0].RasterBandsData[0][index] = defCloudy;
                                    continue;
                                }
                                //第1个输出文件的第1个波段存储NDVI值
                                rvOutVistor[0].RasterBandsData[0][index] = (short)((inBand1[index] - inBand0[index]) * zoom / (inBand1[index] + inBand0[index]));
                            }
                        }
                        else if (aoi != null && aoi.Length != 0)
                        {
                            int index;
                            for (int i = 0; i < aoi.Length; i++)
                            {
                                index = aoi[i];
                                if ((inBand12 != null && inBand12[index] != 0) || (isFitterCloud && inBand1[index] / CloudyZoom[0] > cloudyArgs[0] && inBand3[index] / CloudyZoom[2] < cloudyArgs[1] && Math.Abs(inBand2[index] / CloudyZoom[1] - inBand3[index] / CloudyZoom[2]) > cloudyArgs[2]))
                                {
                                    rvOutVistor[0].RasterBandsData[0][index] = defCloudy;
                                    continue;
                                }
                                //第1个输出文件的第1个波段存储NDVI值
                                rvOutVistor[0].RasterBandsData[0][index] = (short)((inBand1[index] - inBand0[index]) * zoom / (inBand1[index] + inBand0[index]));
                            }
                        }
                    }
                }));
                //执行
                rfr.Excute();
                FileExtractResult res = new FileExtractResult(_subProductDef.Identify, outFileName, true);
                res.SetDispaly(false);
                return(res);
            }
            finally
            {
                if (fileIns != null)
                {
                    for (int i = 0; i < fileIns.Count; i++)
                    {
                        fileIns[i].Raster.Dispose();
                    }
                }
                if (fileOuts != null)
                {
                    for (int i = 0; i < fileOuts.Length; i++)
                    {
                        fileOuts[i].Raster.Dispose();
                    }
                }
                if (clmPrd != null)
                {
                    clmPrd.Dispose();
                }
            }
        }
示例#29
0
        private IExtractResult BaseOrbitAlgorithm(Action <int, string> progressTracker)
        {
            int    CSRVisibleCH      = (int)_argumentProvider.GetArg("VisibleCH");
            int    maxNDVICH         = (int)_argumentProvider.GetArg("NDVICH");
            double VisibleZoom       = (double)_argumentProvider.GetArg("Visible_Zoom");
            double ShortInfraredZoom = (double)_argumentProvider.GetArg("ShortInfrared_Zoom");
            double VisibleCHZoom     = (double)_argumentProvider.GetArg("VisibleCH_Zoom");
            double NDVICHZoom        = (double)_argumentProvider.GetArg("NDVICH_Zoom");
            double ndviZoom          = (float)_argumentProvider.GetArg("NDVIZoom");

            if (_argumentProvider.GetArg("HistroySRCFile") == null || _argumentProvider.GetArg("CurrentRasterFile") == null)
            {
                return(null);
            }
            Dictionary <string, string> csrStr = GetFilemap("HistroyCSRFile");
            string CurrentRasterFile           = _argumentProvider.GetArg("CurrentRasterFile").ToString();
            int    visibleCH     = (int)_argumentProvider.GetArg("Visible");
            int    shortInfrared = (int)_argumentProvider.GetArg("ShortInfrared");

            if (CSRVisibleCH == -1 || maxNDVICH == -1 || csrStr == null || csrStr.Count < 2 || !File.Exists(CurrentRasterFile))
            {
                PrintInfo("晴空反射率生产所用文件或通道未设置完全,请检查!");
                return(null);
            }

            if (visibleCH == -1 || shortInfrared == -1)
            {
                using (IRasterDataProvider rasterProvider = RasterDataDriver.Open(CurrentRasterFile) as IRasterDataProvider)
                {
                    if (rasterProvider != null)
                    {
                        IBandNameRaster bandNameRaster = rasterProvider as IBandNameRaster;
                        visibleCH     = TryGetBandNo(bandNameRaster, "Visible");
                        shortInfrared = TryGetBandNo(bandNameRaster, "ShortInfrared");
                    }
                }
                if (visibleCH == -1 || shortInfrared == -1)
                {
                    PrintInfo("晴空反射率生产所用文件或通道未设置完全,请检查!");
                    return(null);
                }
            }

            //是否为自动生成时生成该产品,若是,需要查找"0CSR"与"MAXN"文件
            if (!ResetCsrString(csrStr))
            {
                PrintInfo("晴空反射率生产所用文件不齐备,请检查!");
                return(null);
            }

            //查找输入文件对应的云判识结果文件
            RasterProcessModel <short, UInt16> rfr = null;
            List <RasterMaper> fileIns             = new List <RasterMaper>();

            RasterMaper[]       fileOuts   = null;
            IRasterDataProvider skyPrd     = null;
            IRasterDataProvider maxNdviPrd = null;

            try
            {
                //输入数据(LDF)
                IRasterDataProvider inRaster = _argumentProvider.DataProvider;
                //输出数据(0CSR)
                string            outFileName = GetFileName(new string[] { inRaster.fileName }, _subProductDef.ProductDef.Identify, _identify, ".dat", null);
                IRasterDataDriver dd          = RasterDataDriver.GetDriverByName("MEM") as IRasterDataDriver;
                string            mapInfo     = inRaster.CoordEnvelope.ToMapInfoString(new Size(inRaster.Width, inRaster.Height));
                string[]          opts        = new string[] {
                    "INTERLEAVE=BSQ",
                    "VERSION=MEM",
                    "WITHHDR=TRUE",
                    "SPATIALREF=" + inRaster.SpatialRef.ToProj4String(),
                    mapInfo
                };
                RasterDataProvider outRaster = dd.Create(outFileName, inRaster.Width, inRaster.Height, 1, enumDataType.UInt16, opts) as RasterDataProvider;
                outRaster.GetRasterBand(1).Fill(Int16.MinValue);
                //栅格数据映射
                fileIns.Add(new RasterMaper(inRaster, new int[] { visibleCH, shortInfrared }));
                skyPrd = GeoDataDriver.Open(csrStr["0CSR"]) as IRasterDataProvider;
                if (skyPrd.BandCount < CSRVisibleCH)
                {
                    PrintInfo("请选择正确的云数据通道进行计算.");
                    return(null);
                }
                fileIns.Add(new RasterMaper(skyPrd, new int[] { CSRVisibleCH }));
                maxNdviPrd = GeoDataDriver.Open(csrStr["MAXN"]) as IRasterDataProvider;
                if (maxNdviPrd.BandCount < maxNDVICH)
                {
                    PrintInfo("请选择正确的云数据通道进行计算.");
                    return(null);
                }
                fileIns.Add(new RasterMaper(maxNdviPrd, new int[] { maxNDVICH }));

                RasterMaper fileOut = new RasterMaper(outRaster, new int[] { 1 });
                //创建处理模型
                fileOuts = new RasterMaper[] { fileOut };
                rfr      = new RasterProcessModel <short, UInt16>(progressTracker);
                rfr.SetRaster(fileIns.ToArray(), fileOuts);
                float curNDVI = 0f;
                rfr.RegisterCalcModel(new RasterCalcHandler <short, UInt16>((rvInVistor, rvOutVistor, aoi) =>
                {
                    if (rvInVistor[0].RasterBandsData != null)
                    {
                        if (rvInVistor == null)
                        {
                            return;
                        }
                        short[] inBand0  = rvInVistor[0].RasterBandsData[0]; //第1个输入文件的第1个波段的各像素值
                        short[] inBand1  = rvInVistor[0].RasterBandsData[1]; //第1个输入文件的第2个波段的各像素值
                        short[] inBand21 = rvInVistor[1].RasterBandsData[0]; //第2个输入文件的第1个波段的各像素值
                        short[] inBand31 = rvInVistor[2].RasterBandsData[0]; //第3个输入文件的第1个波段的各像素值
                        for (int index = 0; index < inBand0.Length; index++)
                        {
                            curNDVI = GetNDVI(inBand0[index], inBand1[index]);
                            if (curNDVI * NDVICHZoom > inBand31[index])
                            {
                                rvOutVistor[0].RasterBandsData[0][index] = (UInt16)inBand1[index];
                            }
                            else
                            {
                                rvOutVistor[0].RasterBandsData[0][index] = (UInt16)inBand21[index];
                            }
                        }
                    }
                }));
                //执行
                rfr.Excute();
                FileExtractResult res = new FileExtractResult(_subProductDef.Identify, outFileName, true);
                res.SetDispaly(false);
                return(res);
            }
            finally
            {
                if (fileOuts != null)
                {
                    for (int i = 0; i < fileOuts.Length; i++)
                    {
                        fileOuts[i].Raster.Dispose();
                    }
                }
                if (skyPrd != null)
                {
                    skyPrd.Dispose();
                }
                if (maxNdviPrd != null)
                {
                    maxNdviPrd.Dispose();
                }
            }
            //

            //Dictionary<string, FilePrdMap> filePrdMap = new Dictionary<string, FilePrdMap>();
            //filePrdMap.Add("CurrentRasterFile", new FilePrdMap(CurrentRasterFile, VisibleZoom, new VaildPra(UInt16.MinValue, UInt16.MaxValue), new int[] { visibleCH, shortInfrared }));
            //filePrdMap.Add("csrFile", new FilePrdMap(csrStr["0CSR"], VisibleCHZoom, new VaildPra(UInt16.MinValue, UInt16.MaxValue), new int[] { CSRVisibleCH }));
            //filePrdMap.Add("maxNDVIFile", new FilePrdMap(csrStr["MAXN"], NDVICHZoom, new VaildPra(Int16.MinValue, Int16.MaxValue), new int[] { maxNDVICH }));
            //ITryCreateVirtualPrd tryVPrd = new TryCreateVirtualPrdByMultiFile();
            //IVirtualRasterDataProvider vrd = tryVPrd.CreateVirtualRasterPRD(ref filePrdMap);
            //if (vrd == null)
            //{
            //    PrintInfo("当前数据与历史晴空数据不在同一区域内,请重新设置!");
            //    foreach (FilePrdMap value in filePrdMap.Values)
            //    {
            //        if (value.Prd != null)
            //            value.Prd.Dispose();
            //    }
            //    return null;
            //}
            //try
            //{
            //    float curNDVI = 0f;
            //    ArgumentProvider ap = new ArgumentProvider(vrd, null);
            //    RasterPixelsVisitor<float> rpVisitor = new RasterPixelsVisitor<float>(ap);
            //    IPixelFeatureMapper<UInt16> _curCSR = new MemPixelFeatureMapper<UInt16>("0CSR", 1000, new Size(vrd.Width, vrd.Height), vrd.CoordEnvelope, vrd.SpatialRef);
            //    IPixelFeatureMapper<Int16> _maxNDVI = new MemPixelFeatureMapper<Int16>("MAXN", 1000, new Size(vrd.Width, vrd.Height), vrd.CoordEnvelope, vrd.SpatialRef);
            //    rpVisitor.VisitPixel(new int[] { filePrdMap["CurrentRasterFile"].StartBand,
            //                                     filePrdMap["CurrentRasterFile"].StartBand+1,
            //                                     filePrdMap["csrFile"].StartBand,
            //                                     filePrdMap["maxNDVIFile"].StartBand},
            //        (index, values) =>
            //        {
            //            curNDVI = GetNDVI(values, 1, 0);
            //            if (curNDVI > values[3])
            //            {
            //                _curCSR.Put(index, (UInt16)(values[0] * VisibleZoom));
            //                _maxNDVI.Put(index, (Int16)(curNDVI * ndviZoom));
            //            }
            //            else
            //            {
            //                _curCSR.Put(index, (UInt16)(values[2] * VisibleZoom));
            //                _maxNDVI.Put(index, (Int16)(values[3] * ndviZoom));
            //            }
            //        });
            //    IExtractResultArray extractArray = new ExtractResultArray("0CRS");
            //    extractArray.Add(_curCSR);
            //    extractArray.Add(_maxNDVI);
            //    return extractArray;
            //}
            //finally
            //{
            //    vrd.Dispose();
            //    if (filePrdMap != null && filePrdMap.Count() > 0)
            //    {
            //        foreach (FilePrdMap value in filePrdMap.Values)
            //        {
            //            if (value.Prd != null)
            //                value.Prd.Dispose();
            //        }
            //    }
            //}
        }