Exemplo n.º 1
0
        private IRasterBand WriteCacheFile(double[] data, string fileName, int width, int height, out IRasterDataProvider cacheWriter)
        {
            string[] options = new string[]
            {
                "INTERLEAVE=BSQ",
                "VERSION=LDF",
                "WITHHDR=TRUE",
            };
            if (_outLdfDriver == null)
            {
                _outLdfDriver = GeoDataDriver.GetDriverByName("LDF") as IRasterDataDriver;
            }
            cacheWriter = _outLdfDriver.Create(fileName, width, height, 1, enumDataType.Double, options) as IRasterDataProvider;
            IRasterBand band = cacheWriter.GetRasterBand(1);

            {
                unsafe
                {
                    fixed(double *ptr = data)
                    {
                        IntPtr bufferPtr = new IntPtr(ptr);

                        band.Write(0, 0, width, height, bufferPtr, enumDataType.Double, width, height);
                    }
                }
            }
            return(band);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        private void BuildInternalBuffer(string fileName)
        {
            IRasterDataDriver drv = GeoDataDriver.GetDriverByName("MEM") as IRasterDataDriver;

            _dataProvider = drv.Create(fileName, vData.Width, vData.Height, 1, vData.DataType, GetOptions());
            _rasterBand   = _dataProvider.GetRasterBand(1);
        }
Exemplo n.º 4
0
        public static IRasterDataProvider CreateVirtureData(VirtualRasterHeader vHeader, string filename, enumDataType enumDataType)
        {
            IRasterDataDriver dr = GeoDataDriver.GetDriverByName("LDF") as IRasterDataDriver;

            return(dr.Create(filename, vHeader.Width, vHeader.Height, 1, enumDataType,
                             vHeader.CoordEnvelope.ToMapInfoString(new Size(vHeader.Width, vHeader.Height))));
        }
Exemplo n.º 5
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);
        }
Exemplo n.º 6
0
        /// <summary>
        /// 创建目标tif文件读取驱动
        /// </summary>
        /// <returns></returns>
        private IRasterDataProvider GetOutFileProvider(IRasterDataProvider srcRaster, Size outimg, string outfilename)
        {
            string[] options   = null;
            string   driver    = string.Empty;
            string   dstwktstr = string.Empty;

            dstwktstr = "GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137,298.257223563]],PRIMEM['Greenwich',0],UNIT['Degree',0.0174532925199433]]";
            dstwktstr = dstwktstr.Replace('\'', '"');
            double minx        = srcRaster.CoordEnvelope.MinX;
            double maxy        = srcRaster.CoordEnvelope.MaxY;
            double resolutionX = srcRaster.ResolutionX;
            double resolutionY = srcRaster.ResolutionY;

            driver  = "GDAL";
            options = new string[] {
                "DRIVERNAME=GTiff",
                "TFW=NO",
                "WKT=" + dstwktstr,
                "GEOTRANSFORM=" + string.Format("{0},{1},{2},{3},{4},{5}", minx, resolutionX, 0, maxy, 0, -resolutionY)
            };
            int    bandCount = srcRaster.BandCount == 1 ? 1 : 3;
            string outdir    = Path.GetDirectoryName(outfilename);

            if (!Directory.Exists(outdir))
            {
                Directory.CreateDirectory(outdir);
            }
            IRasterDataDriver outdrv = GeoDataDriver.GetDriverByName(driver) as IRasterDataDriver;

            return(outdrv.Create(outfilename, outimg.Width, outimg.Height, bandCount, enumDataType.Byte, options) as IRasterDataProvider);
        }
Exemplo n.º 7
0
        private IRasterDataProvider CreatOutputRaster(string outputFName, IRasterDataProvider inRaster, int bandCount, Action <int, string> progressCallback)
        {
            if (inRaster == null)
            {
                return(null);
            }
            if (progressCallback != null)
            {
                progressCallback(1, "开始创建目标文件...");
            }
            IRasterDataDriver driver  = GeoDataDriver.GetDriverByName("GDAL") as IRasterDataDriver;
            List <string>     options = new List <string>();

            options.AddRange(new string[] { "DRIVERNAME=GTiff",
                                            "TFW=YES",
                                            "TILED=YES" });
            if (inRaster.SpatialRef != null)
            {
                options.Add("WKT=" + inRaster.SpatialRef.ToWKTString());
            }
            if (inRaster.CoordEnvelope != null)
            {
                options.Add("GEOTRANSFORM=" + string.Format("{0},{1},{2},{3},{4},{5}", 0, inRaster.ResolutionX, 0, inRaster.CoordEnvelope.MaxY, 0, -inRaster.ResolutionY));
            }
            IRasterDataProvider prdWrite = driver.Create(outputFName, inRaster.Width, inRaster.Height, bandCount, enumDataType.Byte, options.ToArray()) as IRasterDataProvider;

            if (progressCallback != null)
            {
                progressCallback(20, "目标文件创建完成.");
            }
            return(prdWrite);
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
0
        private void BuildCalcBuffer(string fileName)
        {
            IRasterDataDriver drv = GeoDataDriver.GetDriverByName("MEM") as IRasterDataDriver;

            _outputCalcDataProvider = drv.Create(fileName, vData.Width, vData.Height, 1, CalcType, GetOptions());
            _outputCalcRasterBand   = _outputCalcDataProvider.GetRasterBand(1);
        }
Exemplo n.º 10
0
        public void ProcessArrayToRaster(string dstFileName, int[,] arrayValue)
        {
            CoordEnvelope       envelope = new CoordEnvelope(-180, 180, -90, 90);
            IRasterDataProvider dataPrd  = null;
            enumDataType        dataType = enumDataType.Int16;

            try
            {
                if (Path.GetExtension(dstFileName).ToUpper() == ".DAT")
                {
                    IRasterDataDriver driver  = GeoDataDriver.GetDriverByName("MEM") as IRasterDataDriver;
                    string            mapInfo = envelope.ToMapInfoString(new Size(_datwidth, _datheight));
                    dataPrd = driver.Create(dstFileName, _datwidth, _datheight, 1, dataType, mapInfo);
                }
                else
                {
                    return;
                }
                if (arrayValue == null)
                {
                    return;
                }
                ProcessArrayToRaster(arrayValue, dataPrd);
            }
            finally
            {
                if (dataPrd != null)
                {
                    dataPrd.Dispose();
                }
            }
        }
Exemplo n.º 11
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);
        }
Exemplo n.º 12
0
        private IRasterDataProvider CreateOutRaster(string outdir, IRasterDataProvider raster, ISpatialReference dstSpatial, PrjEnvelope envelope, double resolutionX, double resolutionY, string bandNames)
        {
            IRasterDataProvider outRaster = null;

            if (raster.Driver.Name == "MEM")    //smart 产品数据,输出也用MEM驱动,目前数据纠正这里不存在。
            {
                string[] options = new string[]
                {
                    "INTERLEAVE=BSQ",
                    "VERSION=MEM",
                    "SPATIALREF=" + dstSpatial.ToProj4String(),
                    "MAPINFO={" + 1 + "," + 1 + "}:{" + envelope.MinX + "," + envelope.MaxY + "}:{" + resolutionX + "," + resolutionY + "}",
                    string.IsNullOrWhiteSpace(bandNames)?"": "BANDNAMES=" + bandNames
                };
                string outfilename = Path.Combine(outdir, Path.GetFileNameWithoutExtension(raster.fileName) + ".DAT");
                outRaster = (raster.Driver as IRasterDataDriver).Create(outfilename, raster.Width, raster.Height, 1, enumDataType.Int16, options);
            }
            else//ldf
            {
                string[] options = new string[]
                {
                    "INTERLEAVE=BSQ",
                    "VERSION=LDF",
                    "SPATIALREF=" + dstSpatial.ToProj4String(),
                    "MAPINFO={" + 1 + "," + 1 + "}:{" + envelope.MinX + "," + envelope.MaxY + "}:{" + resolutionX + "," + resolutionY + "}",
                    "DATETIME=" + raster.DataIdentify.OrbitDateTime,
                    string.IsNullOrWhiteSpace(bandNames)?"": "BANDNAMES=" + bandNames
                };
                string            outfilename = Path.Combine(outdir, Path.GetFileNameWithoutExtension(raster.fileName) + ".LDF");
                IRasterDataDriver driver      = GeoDataDriver.GetDriverByName("LDF") as IRasterDataDriver;
                outRaster = driver.Create(outfilename, raster.Width, raster.Height, 1, enumDataType.Int16, options);
            }
            return(outRaster);
        }
Exemplo n.º 13
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);
        }
Exemplo n.º 14
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);
        }
Exemplo n.º 15
0
        internal IRasterDataProvider CreateOutFile(string driver, string outfilename, int dstBandCount, Size outSize, enumDataType dataType, string[] options)
        {
            CheckAndCreateDir(Path.GetDirectoryName(outfilename));
            IRasterDataDriver outdrv = GeoDataDriver.GetDriverByName(driver) as IRasterDataDriver;

            return(outdrv.Create(outfilename, outSize.Width, outSize.Height, dstBandCount, dataType, options) as IRasterDataProvider);
        }
Exemplo n.º 16
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();
                }
            }
        }
Exemplo n.º 17
0
        private void BuildInternalBuffer(string _fileName)
        {
            IRasterDataDriver drv = GeoDataDriver.GetDriverByName("MEM") as IRasterDataDriver;

            _dataProvider = drv.Create(_fileName, _size.Width, _size.Height, 1, GetDataType(), GetOptions());
            _rasterValues = _dataProvider.GetRasterBand(1);
        }
Exemplo n.º 18
0
        private IRasterDataProvider CreateDstDataProvider(IRasterDataDriver driver, string outFile, IRasterDataProvider dataProvider)
        {
            ISpatialReference spatialRef = dataProvider.SpatialRef ?? new SpatialReference(new GeographicCoordSystem());
            string            spRef      = "SPATIALREF=" + spatialRef.ToProj4String();
            string            mapInf     = dataProvider.CoordEnvelope.ToMapInfoString(new Size(dataProvider.Width, dataProvider.Height));

            return(driver.Create(outFile, dataProvider.Width, dataProvider.Height, 1, enumDataType.Float, spRef, mapInf, "WITHHDR=TRUE"));
        }
Exemplo n.º 19
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);
        }
Exemplo n.º 20
0
        /// <summary>
        /// 0、先生成目标文件,以防止目标空间不足。
        /// 1、计算查找表
        /// 2、对所有波段执行投影
        /// </summary>
        private void ProjectToLDF(IRasterDataProvider srcRaster, FY3_VIRR_PrjSettings prjSettings, ISpatialReference dstSpatialRef, Action <int, string> progressCallback)
        {
            string         outFormat    = prjSettings.OutFormat;
            string         outfilename  = prjSettings.OutPathAndFileName;
            string         dstProj4     = dstSpatialRef.ToProj4String();
            List <BandMap> bandMaps     = prjSettings.BandMapTable;
            int            dstBandCount = bandMaps.Count;
            Size           srcSize      = new Size(srcRaster.Width, srcRaster.Height);
            Size           dstSize      = prjSettings.OutSize;

            using (IRasterDataDriver drv = GeoDataDriver.GetDriverByName("LDF") as IRasterDataDriver)
            {
                PrjEnvelope dstEnvelope = prjSettings.OutEnvelope;
                string      mapInfo     = "MAPINFO={" + 1 + "," + 1 + "}:{" + dstEnvelope.MinX + "," + dstEnvelope.MaxY + "}:{" + prjSettings.OutResolutionX + "," + prjSettings.OutResolutionY + "}";
                using (IRasterDataProvider prdWriter = drv.Create(outfilename, dstSize.Width, dstSize.Height, dstBandCount,
                                                                  enumDataType.UInt16, "INTERLEAVE=BSQ", "VERSION=LDF", "SPATIALREF=" + dstProj4, mapInfo, "WITHHDR=TRUE") as IRasterDataProvider)
                {
                    //计算查找表
                    //ISpatialReference srcSpatialRef = srcRaster.SpatialRef;
                    UInt16[] dstRowLookUpTable = new UInt16[dstSize.Width * dstSize.Height];
                    UInt16[] dstColLookUpTable = new UInt16[dstSize.Width * dstSize.Height];
                    _rasterProjector.ComputeIndexMapTable(_xs, _ys, srcSize, dstSize, dstEnvelope, _maxPrjEnvelope,
                                                          out dstRowLookUpTable, out dstColLookUpTable, progressCallback);
                    //执行投影
                    UInt16[] srcBandData = new UInt16[srcSize.Width * srcSize.Height];
                    UInt16[] dstBandData = new UInt16[dstSize.Width * dstSize.Height];
                    int      progress    = 0;
                    for (int i = 0; i < dstBandCount; i++)      //读取原始通道值,投影到目标区域
                    {
                        if (progressCallback != null)
                        {
                            progress = (int)((i + 1) * 100 / dstBandCount);
                            progressCallback(progress, string.Format("投影第{0}共{1}通道", i + 1, dstBandCount));
                        }
                        BandMap bandMap = bandMaps[i];
                        ReadBandData(srcBandData, bandMap.File, bandMap.DatasetName, bandMap.BandIndex, srcSize);
                        if (prjSettings.IsRadiation)
                        {
                            DoRadiation(srcBandData, srcSize, bandMap.DatasetName, bandMap.BandIndex, prjSettings.IsSolarZenith);
                        }
                        _rasterProjector.Project <UInt16>(srcBandData, srcSize, dstRowLookUpTable, dstColLookUpTable, dstSize, dstBandData, 0, progressCallback);
                        using (IRasterBand band = prdWriter.GetRasterBand(i + 1))
                        {
                            unsafe
                            {
                                fixed(UInt16 *ptr = dstBandData)
                                {
                                    IntPtr bufferPtr = new IntPtr(ptr);

                                    band.Write(0, 0, band.Width, band.Height, bufferPtr, enumDataType.UInt16, band.Width, band.Height);
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 21
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);
        }
Exemplo n.º 22
0
 private bool InitOutFile(IRasterDataProvider rasterIn, string[] inFiles, string outDir, int defaultValue, out IRasterDataProvider[] rasterOuts)
 {
     rasterOuts = null;
     try
     {
         string            fileExt      = "";
         IRasterDataDriver driver       = null;
         string[]          optionString = null;
         if (rasterIn.Driver.Name == "MEM")//判识结果
         {
             optionString = new string[] {
                 "SPATIALREF=" + rasterIn.SpatialRef == null?"":("SPATIALREF=" + rasterIn.SpatialRef.ToProj4String()),
                 "MAPINFO={" + 1 + "," + 1 + "}:{" + rasterIn.CoordEnvelope.MinX + "," + rasterIn.CoordEnvelope.MaxY + "}:{" + rasterIn.ResolutionX + "," + rasterIn.ResolutionY + "}"
             };
             driver  = GeoDataDriver.GetDriverByName("MEM") as IRasterDataDriver;
             fileExt = ".DAT";
         }
         else
         {
             optionString = new string[] {
                 "INTERLEAVE=BSQ",
                 "VERSION=LDF",
                 "WITHHDR=TRUE",
                 "SPATIALREF=" + rasterIn.SpatialRef == null?"":("SPATIALREF=" + rasterIn.SpatialRef.ToProj4String()),
                 "MAPINFO={" + 1 + "," + 1 + "}:{" + rasterIn.CoordEnvelope.MinX + "," + rasterIn.CoordEnvelope.MaxY + "}:{" + rasterIn.ResolutionX + "," + rasterIn.ResolutionY + "}"
             };
             driver  = GeoDataDriver.GetDriverByName("LDF") as IRasterDataDriver;
             fileExt = ".LDF";
         }
         string[] fileOuts = new string[inFiles.Length];
         for (int i = 0; i < inFiles.Length; i++)
         {
             fileOuts[i] = Path.Combine(Path.GetDirectoryName(inFiles[0]) + "/out", Path.ChangeExtension(Path.GetFileName(inFiles[i]), fileExt));
         }
         rasterOuts = new IRasterDataProvider[inFiles.Length];
         for (int i = 0; i < inFiles.Length; i++)
         {
             IRasterDataProvider rasterOut = driver.Create(fileOuts[i], rasterIn.Width, rasterIn.Height, 1, rasterIn.DataType, optionString);
             if (rasterOut == null)
             {
                 return(false);
             }
             rasterOuts[i] = rasterOut;
             double nodata = 0d;
             double.TryParse(defaultValue.ToString(), out nodata);
             rasterOut.GetRasterBand(1).Fill(nodata);
         }
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Exemplo n.º 23
0
        private void BuildInternalBuffer(string fileName)
        {
            IRasterDataDriver drv = GeoDataDriver.GetDriverByName("LDF") as IRasterDataDriver;

            _outputDataProvider = drv.Create(fileName, vData.Width, vData.Height, vData.BandCount, vData.DataType, GetOptions());
            _outputRasterBands  = new IRasterBand[vData.BandCount];
            for (int i = 0; i < vData.BandCount; i++)
            {
                _outputRasterBands[i] = _outputDataProvider.GetRasterBand(i + 1);
            }
        }
Exemplo n.º 24
0
        public void ProcessVectorToRaster(Feature[] features, string shpPrimaryField, enumDataType dataType, double resolution, CoordEnvelope envelope, string rasterFileName)
        {
            //创建目标文件
            if (string.IsNullOrEmpty(rasterFileName))
            {
                return;
            }
            if (envelope == null)
            {
                return;
            }
            int height = (int)Math.Ceiling((envelope.MaxY - envelope.MinY) / resolution);
            int width  = (int)Math.Ceiling((envelope.MaxX - envelope.MinX) / resolution);
            IRasterDataProvider dataPrd = null;

            try
            {
                string extension = Path.GetExtension(rasterFileName).ToUpper();
                switch (extension)
                {
                case ".LDF":
                {
                    IRasterDataDriver driver  = GeoDataDriver.GetDriverByName("LDF") as IRasterDataDriver;
                    string            mapInfo = envelope.ToMapInfoString(new Size(width, height));
                    dataPrd = driver.Create(rasterFileName, width, height, 1, dataType, mapInfo);
                    break;
                }

                case ".DAT":
                {
                    IRasterDataDriver driver  = GeoDataDriver.GetDriverByName("MEM") as IRasterDataDriver;
                    string            mapInfo = envelope.ToMapInfoString(new Size(width, height));
                    dataPrd = driver.Create(rasterFileName, width, height, 1, dataType, mapInfo);
                    break;
                }

                default:
                    return;
                }
                if (features == null || features.Length < 1)
                {
                    return;
                }
                ProcessVectorToRaster(features, shpPrimaryField, dataPrd);
            }
            finally
            {
                if (dataPrd != null)
                {
                    dataPrd.Dispose();
                }
            }
        }
Exemplo n.º 25
0
        private IRasterDataProvider CreateDstDataProvider(IRasterDataProvider srcDataProvider, RasterCut.CutArgument args, RasterCut.BlockItem item)
        {
            string        extName;
            CoordEnvelope evp = GetDstEnvelope(srcDataProvider, item);

            object[]          options = GetOptions(srcDataProvider, args, item, out extName, evp);
            IRasterDataDriver drv     = GeoDataDriver.GetDriverByName(args.Driver, args.DriverOptions) as IRasterDataDriver;
            string            fname   = GetOutFileName(args.OutFileName, item, extName);

            return(drv.Create(fname, item.Width, item.Height, args.BandNos.Length, srcDataProvider.DataType,
                              options));
        }
Exemplo n.º 26
0
        internal IRasterDataProvider CreateOutFile(string outfilename, int dstBandCount, Size outSize, enumDataType dataType, string[] options)
        {
            string dir = Path.GetDirectoryName(outfilename);

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            IRasterDataDriver outdrv = GeoDataDriver.GetDriverByName("LDF") as IRasterDataDriver;

            return(outdrv.Create(outfilename, outSize.Width, outSize.Height, dstBandCount, dataType, options) as IRasterDataProvider);
        }
Exemplo n.º 27
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);
                }
            }
        }
Exemplo n.º 28
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);
        }
Exemplo n.º 29
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);
        }
Exemplo n.º 30
0
        public static void SaveToDBLVDat(string hdffname, string rasterFileName, Feature[] features, double resolution, Action <int, string> processPolback)
        {
            CoordEnvelope envelope;

            HDF5Filter.GetDataCoordEnvelope(hdffname, out envelope);
            int height = (int)Math.Ceiling((envelope.MaxY - envelope.MinY) / resolution);
            int width  = (int)Math.Ceiling((envelope.MaxX - envelope.MinX) / resolution);

            Int16[] dblv = new Int16[height * width];
            if (processPolback != null)
            {
                processPolback(15, "开始计算火点判识结果...");
            }
            ProcessFeaturesDBLV(features, resolution, width, envelope.MaxY, envelope.MinX, ref dblv);
            if (processPolback != null)
            {
                processPolback(50, "开始输出火点判识结果...");
            }
            IRasterDataProvider dataPrd = null;

            try
            {
                IRasterDataDriver driver  = GeoDataDriver.GetDriverByName("MEM") as IRasterDataDriver;
                string            mapInfo = envelope.ToMapInfoString(new Size(width, height));
                //string mapInfo = new CoordEnvelope(envelope.MinX - 0.01, envelope.MaxX - 0.01, envelope.MinY - 0.1, envelope.MaxY - 0.1).ToMapInfoString(new Size(width, height));
                dataPrd = driver.Create(rasterFileName, width, height, 1, enumDataType.Int16, mapInfo);
                unsafe
                {
                    fixed(Int16 *ptr = dblv)
                    {
                        IntPtr bufferPtr = new IntPtr(ptr);

                        dataPrd.GetRasterBand(1).Write(0, 0, width, height, bufferPtr, enumDataType.Int16, width, height);
                    }
                }
                if (processPolback != null)
                {
                    processPolback(100, "输出火点判识结果完成!");
                }
            }
            finally
            {
                if (dataPrd != null)
                {
                    dataPrd.Dispose();
                }
            }
        }