示例#1
0
        public IRasterSet OpenRaster(string fileName)
        {
            IRasterSet dataSet = null;

            if (Drivers != null)
            {
                foreach (var driver in RasterDrivers)
                {
                    try
                    {
                        dataSet = driver.Open(fileName, true);
                    }
                    catch (Exception e)
                    {
                        Debug.WriteLine(e);
                        try
                        {
                            dataSet = driver.Open(fileName, false);
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine(ex);
                        }
                    }
                    if (dataSet != null)
                    {
                        break;
                    }
                }
            }
            return(dataSet);
        }
示例#2
0
        private IRasterSet GetRasterSet(string fileName, OSGeo.GDAL.Dataset dataset)
        {
            IRasterSet rasterSet = null;

            if (dataset != null && dataset.RasterCount > 0)
            {
                using var band = dataset.GetRasterBand(1);
                if (band == null)
                {
                    return(null);
                }
                switch (band.DataType)
                {
                case OSGeo.GDAL.DataType.GDT_Byte:
                    rasterSet = new GdalRasterSet <byte>(fileName, dataset);
                    break;

                case OSGeo.GDAL.DataType.GDT_Int16:
                    rasterSet = new GdalRasterSet <short>(fileName, dataset);
                    break;

                case OSGeo.GDAL.DataType.GDT_UInt16:
                    rasterSet = new GdalRasterSet <ushort>(fileName, dataset);
                    break;

                case OSGeo.GDAL.DataType.GDT_Int32:
                    rasterSet = new GdalRasterSet <int>(fileName, dataset);
                    break;

                case OSGeo.GDAL.DataType.GDT_UInt32:
                    rasterSet = new GdalRasterSet <uint>(fileName, dataset);
                    break;

                case OSGeo.GDAL.DataType.GDT_CFloat32:
                    rasterSet = new GdalRasterSet <float>(fileName, dataset);
                    break;

                case OSGeo.GDAL.DataType.GDT_CFloat64:
                    rasterSet = new GdalRasterSet <double>(fileName, dataset);
                    break;

                default:
                    throw new NotImplementedException();
                }
            }
            return(rasterSet);
        }
示例#3
0
        IRasterSet IRasterDriver.Open(string fileName, bool update)
        {
            OSGeo.GDAL.Dataset dataset = null;
            var access = update ? OSGeo.GDAL.Access.GA_Update : OSGeo.GDAL.Access.GA_ReadOnly;

            try
            {
                dataset = OSGeo.GDAL.Gdal.Open(fileName, access);
            }
            catch (Exception e)
            {
                Debug.WriteLine($"打开“{fileName}”失败,错误信息:{e}");
            }
            IRasterSet rasterSet = GetRasterSet(fileName, dataset);

            return(rasterSet);
        }
示例#4
0
        public IRasterSet Create(string fileName, int xsize, int ysize, int bands, RasterType eType)
        {
            IRasterSet rasterSet   = null;
            var        driverCount = OSGeo.GDAL.Gdal.GetDriverCount();

            for (int i = 0; i < driverCount; i++)
            {
                using (var driver = OSGeo.GDAL.Gdal.GetDriver(i))
                {
                    var dataset = driver.Create(fileName, xsize, ysize, bands, eType.ToRasterType(), null);
                    if (dataset != null)
                    {
                        rasterSet = GetRasterSet(fileName, dataset);
                    }
                }
            }
            return(rasterSet);
        }