Пример #1
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();
                }
            }
        }
Пример #2
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);
        }
Пример #3
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);
        }
Пример #4
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);
        }
Пример #5
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();
                }
            }
        }
Пример #6
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);
        }
Пример #7
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);
        }
Пример #8
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);
        }
Пример #9
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);
        }
Пример #10
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);
        }
Пример #11
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);
        }
Пример #12
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);
        }
Пример #13
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);
        }
Пример #14
0
 public void ProcessVectorToRaster(string shpFileName, enumDataType dataType, double resolution, string rasterFileName)
 {
     if (string.IsNullOrEmpty(rasterFileName))
     {
         return;
     }
     using (IVectorFeatureDataReader dr = VectorDataReaderFactory.GetUniversalDataReader(shpFileName)
                                          as IVectorFeatureDataReader)
     {
         if (dr == null)
         {
             return;
         }
         CoordEnvelope       envelope = new CoordEnvelope(-180, 180, -90, 90);
         int                 height   = (int)Math.Ceiling((envelope.MaxY - envelope.MinY) / resolution);
         int                 width    = (int)Math.Ceiling((envelope.MaxX - envelope.MinX) / resolution);
         IRasterDataProvider dataPrd  = null;
         try
         {
             if (Path.GetExtension(rasterFileName).ToUpper() == ".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);
             }
             else
             {
                 return;
             }
             Feature[] features = dr.FetchFeatures();
             if (features == null || features.Length < 1)
             {
                 return;
             }
             ProcessVectorToRaster(features, dataPrd);
         }
         finally
         {
             if (dataPrd != null)
             {
                 dataPrd.Dispose();
             }
         }
     }
 }
Пример #15
0
        private object[] GetOptions(IRasterDataProvider dataProvider, CutArgument args, BlockItem item, out string extName, CoordEnvelope evp)
        {
            extName = null;
            List <object> options = new List <object>();

            if (args.Driver == "LDF")
            {
                extName = ".ldf";
                if (dataProvider.SpatialRef != null)
                {
                    string spRef = "SPATIALREF=" + dataProvider.SpatialRef.ToProj4String();
                    options.Add(spRef);
                }
                string mapInf = evp.ToMapInfoString(new Size(item.Width, item.Height));
                options.Add(mapInf);
            }
            return(options.Count > 0 ? options.ToArray() : null);
        }
Пример #16
0
        private unsafe void ReadAndWriteOneBandRaw(IRasterDataProvider dataPrd, string outfName)
        {
            int         bandNO = 4;
            IRasterBand bands  = dataPrd.GetRasterBand(bandNO);

            if (bands != null)
            {
                int                 height     = dataPrd.Height;
                int                 width      = dataPrd.Width;
                CoordEnvelope       envelope   = dataPrd.CoordEnvelope;
                IRasterDataProvider outdataPrd = null;
                try
                {
                    IRasterDataDriver driver  = GeoDataDriver.GetDriverByName("MEM") as IRasterDataDriver;
                    string            mapInfo = envelope.ToMapInfoString(new Size(width, height));
                    outdataPrd = driver.Create(outfName, width, height, 1, dataPrd.DataType, mapInfo);
                    float[] buffer = new float[dataPrd.Width * dataPrd.Height];
                    fixed(float *ptr = buffer)
                    {
                        IntPtr bufferPtr = new IntPtr(ptr);

                        bands.Read(0, 0, dataPrd.Width, dataPrd.Height, bufferPtr, dataPrd.DataType, dataPrd.Width, dataPrd.Height);
                        outdataPrd.GetRasterBand(1).Write(0, 0, width, height, bufferPtr, dataPrd.DataType, width, height);
                    }
                    string hdrFile = Path.ChangeExtension(outfName, ".hdr");
                    SaveHdrFile(hdrFile, width, height, dataPrd.DataType);
                }
                catch (System.Exception ex)
                {
                }
                finally
                {
                    if (dataPrd != null)
                    {
                        dataPrd.Dispose();
                    }
                    if (outdataPrd != null)
                    {
                        outdataPrd.Dispose();
                    }
                }
            }
        }
Пример #17
0
 private object[] GetOptions(CoordEnvelope outputEnvelope, int width, int height)
 {
     List<string> ops = new List<string>();
     if (_coordEnvelope != null)
         ops.Add(outputEnvelope.ToMapInfoString(new Size(width, height)));
     if (_spatialRef != null)
     {
         try
         {
             string spref = _spatialRef.ToProj4String();
             ops.Add("SPATIALREF=" + spref);
         }
         catch (Exception ex)
         {
             Console.Write(ex.Message);
         }
     }
     return ops.Count > 0 ? ops.ToArray() : null;
 }
Пример #18
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);
        }
Пример #19
0
        //public string MaskChina(string file)
        //{
        //    List<RasterMaper> rms = null;
        //    IRasterDataProvider outRaster = null;
        //    RasterProcessModel<float, float> rfr = null;
        //    string outfile = "";
        //    //中国区掩膜文件
        //    string chinarasterFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SystemData\\ProductArgs\\MWS\\SnowArgFile\\china_raster.dat");
        //    if (string.IsNullOrEmpty(chinarasterFile) || !File.Exists(chinarasterFile))
        //    {
        //        return null;
        //    }
        //    try
        //    {
        //        rms = new List<RasterMaper>();
        //        IRasterDataProvider inRaster = GeoDataDriver.Open(file) as IRasterDataProvider;
        //        RasterMaper fileIn = new RasterMaper(inRaster, new int[] { 1 });
        //        rms.Add(fileIn);
        //        IRasterDataProvider inRaster3 = GeoDataDriver.Open(chinarasterFile) as IRasterDataProvider;
        //        RasterMaper fileIn3 = new RasterMaper(inRaster3, new int[] { 1 });
        //        outfile = Path.GetDirectoryName(file)+ Path.GetFileNameWithoutExtension(file) + "_maskChina." + Path.GetExtension(file);
        //        rms.Add(fileIn3);
        //        outRaster = CreateOutRaster(outfile, enumDataType.Float, rms.ToArray(), inRaster.ResolutionX);
        //        RasterMaper fileOut = new RasterMaper(outRaster, new int[] { 1 });
        //        RasterMaper[] fileIns = rms.ToArray();
        //        RasterMaper[] fileOuts = new RasterMaper[] { fileOut };
        //        rfr = new RasterProcessModel<float, float>();
        //        rfr.SetRaster(fileIns, fileOuts);
        //        rfr.RegisterCalcModel(new RasterCalcHandler<float, float>((rvInVistor, rvOutVistor, aoi) =>
        //        {
        //            if (rvInVistor[0].RasterBandsData[0] != null && rvInVistor[1].RasterBandsData[0] != null)
        //            {
        //                int dataLength = rvOutVistor[0].SizeX * rvOutVistor[0].SizeY;
        //                for (int i = 0; i < dataLength; i++)
        //                {
        //                    //if (Convert.ToSingle(rvInVistor[1].RasterBandsData[0][i]) == 9.38169E-41) //陆地
        //                        rvOutVistor[0].RasterBandsData[0][i] = rvInVistor[0].RasterBandsData[0][i];
        //                    //else
        //                    //    rvOutVistor[0].RasterBandsData[0][i] = 2000f;
        //                }
        //            }
        //        }));
        //        rfr.Excute();
        //    }
        //    finally
        //    {
        //        if (outRaster != null)
        //            outRaster.Dispose();
        //        if (rms != null && rms.Count > 0)
        //        {
        //            foreach (RasterMaper rm in rms)
        //            {
        //                if (rm.Raster != null)
        //                    rm.Raster.Dispose();
        //            }
        //        }
        //    }
        //    return outfile;
        //}


        //创建输出删格文件
        protected IRasterDataProvider CreateOutRaster(string outFileName, enumDataType dataType, RasterMaper[] inrasterMaper, float resolution)
        {
            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));
            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);
        }
Пример #20
0
        public void CreateRasterDataPrd(string rasterFileName, int[,] dataValue)
        {
            CoordEnvelope       envelope = new CoordEnvelope(-180, 180, -90, 90);
            IRasterDataProvider dataPrd  = null;

            try
            {
                IRasterDataDriver driver = GeoDataDriver.GetDriverByName("MEM") as IRasterDataDriver;
                int    height            = (int)Math.Ceiling((envelope.MaxY - envelope.MinY) / _resolution);
                int    width             = (int)Math.Ceiling((envelope.MaxX - envelope.MinX) / _resolution);
                string mapInfo           = envelope.ToMapInfoString(new Size(width, height));
                dataPrd = driver.Create(rasterFileName, width, height, 1, enumDataType.Int16, mapInfo);
                WriteValueToRaster(dataValue, dataPrd);
            }
            finally
            {
                if (dataPrd != null)
                {
                    dataPrd.Dispose();
                }
            }
        }
Пример #21
0
        private object[] GetOptions()
        {
            List <string> ops = new List <string>();

            if (_coordEnvelope != null)
            {
                ops.Add(_coordEnvelope.ToMapInfoString(new Size(vData.Width, vData.Height)));
            }
            if (_spatialRef != null)
            {
                try
                {
                    string spref = _spatialRef.ToProj4String();
                    ops.Add("SPATIALREF=" + spref);
                }
                catch (Exception ex)
                {
                    Console.Write(ex.Message);
                }
            }
            return(ops.Count > 0 ? ops.ToArray() : null);
        }
Пример #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
        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);
        }
Пример #24
0
        private object[] GetOptions()
        {
            List <string> ops = new List <string>();

            if (_coordEnvelope != null)
            {
                ops.Add(_coordEnvelope.ToMapInfoString(_size));
            }
            if (_spatialRef != null)
            {
                try
                {
                    string spref = _spatialRef.ToProj4String();
                    ops.Add("SPATIALREF=" + spref);
                }
                catch (Exception ex)
                {
                    Console.Write(ex.Message);
                }
            }
            ops.Add("ExtHeaderSize=" + _extHeaderSize.ToString());
            return(ops.Count > 0 ? ops.ToArray() : null);
        }
Пример #25
0
 private string GetMapInfoString(CoordEnvelope coordEnvelope, int width, int height)
 {
     return(coordEnvelope != null?coordEnvelope.ToMapInfoString(new Size(width, height)) : string.Empty);
 }