Example #1
0
    public static void Main(string[] args)
    {
        if (args.Length != 3)
        {
            usage();
        }

        Gdal.AllRegister();

        GDALWarpAppOptions options = new GDALWarpAppOptions(args[1].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries));

        string[] dstNames = args[2].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

        Dataset[] ds = new Dataset[dstNames.Length];

        for (int i = 0; i < dstNames.Length; i++)
        {
            ds[i] = Gdal.Open(dstNames[i], Access.GA_ReadOnly);
        }

        Dataset dso = Gdal.Warp(args[0], ds, options, new Gdal.GDALProgressFuncDelegate(ProgressFunc), "Sample Data");

        if (dso == null)
        {
            Console.WriteLine("Can't create dest dataset " + args[1]);
            System.Environment.Exit(-1);
        }
    }
Example #2
0
        /// <summary>
        /// Creates a new image given the specified file format
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="inRam">if set to <c>true</c> should load entire file in ram.</param>
        /// <param name="progHandler">The prog handler.</param>
        /// <param name="bandType">Type of the band.</param>
        /// <returns></returns>
        public IImageData Create(string fileName, int width, int height, bool inRam, IProgressHandler progHandler, ImageBandType bandType)
        {
            Gdal.AllRegister();
            Driver d = GetDriverByExtension(fileName);

            if (d == null)
            {
                return(null);
            }
            Dataset ds;

            if (bandType == ImageBandType.ARGB)
            {
                ds = d.Create(fileName, width, height, 4, DataType.GDT_Byte, new string[] { });
            }
            else if (bandType == ImageBandType.RGB)
            {
                ds = d.Create(fileName, width, height, 3, DataType.GDT_Byte, new string[] { });
            }
            else if (bandType == ImageBandType.PalletCoded)
            {
                ds = d.Create(fileName, width, height, 1, DataType.GDT_Byte, new string[] { });
            }
            else
            {
                ds = d.Create(fileName, width, height, 1, DataType.GDT_Byte, new string[] { });
            }

            return(new GdalImage(fileName, ds, bandType));
        }
Example #3
0
        //
        // GDL of Code
        //
        void imginfo(string open, out int bit, out int channels, out string format)
        {
            bit      = -1;
            channels = 0;
            format   = "";
            Gdal.AllRegister();

            Dataset data_igdal = Gdal.Open(open, Access.GA_ReadOnly);

            Band[] bants_gdal = new Band[data_igdal.RasterCount];
            channels = data_igdal.RasterCount;
            format   = data_igdal.GetDriver().ShortName;

            bants_gdal[0] = data_igdal.GetRasterBand(1);
            if (bants_gdal[0].DataType == DataType.GDT_Byte)
            {
                bit = 8;
            }
            if (bants_gdal[0].DataType == DataType.GDT_UInt16)
            {
                bit = 16;
            }
            if (bants_gdal[0].DataType == DataType.GDT_Int16)
            {
                bit = 16;
            }
            data_igdal.Dispose();
            bants_gdal[0].Dispose();
        }
        private void openPan1_Click(object sender, EventArgs e)
        {
            Gdal.AllRegister();
            OpenFileDialog ofd = new OpenFileDialog();

            //允许打开的文件格式
            ofd.Filter =
                "Erdas Imagine (*.img)|*.img|" +
                "GeoTiff (*.tif *.tiff)|*.tif;*.tiff|" +
                "HDF (*.hdf *.h5 *he5)|*.hdf;*.h5;*he5|" +
                "位图文件 (*.bmp)|*.bmp|" +
                "Graphics Interchange Format (*.gif)|*.gif|" +
                "JPEG (*.jpg *.jpeg)|*.jpg;*.jpeg|" +
                "Portable Network Graphics (*.png)|*.png|" +
                "所有文件|*.*";
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                file2 = ofd.FileName;
                ds2   = Gdal.Open(file2, Access.GA_ReadOnly);
            }
            Rectangle pictureRect = new Rectangle();

            pictureRect.X      = 0;
            pictureRect.Y      = 0;
            pictureRect.Width  = 600;
            pictureRect.Height = 450;
            Foudation fd   = new Foudation();
            Band      band = ds2.GetRasterBand(1);

            img2 = fd.GetImage(ds2, pictureRect, band);
        }
Example #5
0
        public void centreTest()
        {
            Gdal.AllRegister();
            Gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "YES");
            Gdal.SetConfigOption("SHAPE_ENCODING", "");
            Ogr.RegisterAll();

            String   a    = "";
            Geometry line = new Geometry(wkbGeometryType.wkbLineString);

            line.AddPoint(0, 0, 0);
            line.AddPoint(1, 1, 0);
            line.AddPoint(2, 0, 0);
            line.ExportToWkt(out a);
            // Console.WriteLine(a);


            Geometry g = line.Centroid();

            g.ExportToWkt(out a);
            //  Console.WriteLine(a);


            double d = line.GetX(line.GetPointCount() - 1);

            double e = line.GetY(line.GetPointCount() - 1);

            Console.WriteLine(d);
            Console.WriteLine(e);
        }
Example #6
0
        public void geometryTest()
        {
            Gdal.AllRegister();
            Gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "YES");
            Gdal.SetConfigOption("SHAPE_ENCODING", "");
            Ogr.RegisterAll();


            Geometry line = new Geometry(wkbGeometryType.wkbLinearRing);

            line.AddPoint(0, 0, 0);
            line.AddPoint(0, 1, 0);
            line.AddPoint(1, 1, 0);
            line.AddPoint(1, 0, 0);
            line.AddPoint(0, 0, 0);



            String a = "";

            line.ExportToWkt(out a);
            Console.WriteLine(a);

            Console.WriteLine(line.GetGeometryCount());


            for (int i = 0; i < line.GetGeometryCount(); i++)
            {
                line.GetGeometryRef(i).ExportToWkt(out a);

                Console.WriteLine(a);
            }
        }
        private void openMsi1_Click(object sender, EventArgs e)
        {
            Gdal.AllRegister();
            OpenFileDialog ofd = new OpenFileDialog();

            //允许打开的文件格式
            ofd.Filter =
                "Erdas Imagine (*.img)|*.img|" +
                "GeoTiff (*.tif *.tiff)|*.tif;*.tiff|" +
                "HDF (*.hdf *.h5 *he5)|*.hdf;*.h5;*he5|" +
                "位图文件 (*.bmp)|*.bmp|" +
                "Graphics Interchange Format (*.gif)|*.gif|" +
                "JPEG (*.jpg *.jpeg)|*.jpg;*.jpeg|" +
                "Portable Network Graphics (*.png)|*.png|" +
                "所有文件|*.*";
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                file1 = ofd.FileName;
                ds1   = Gdal.Open(file1, Access.GA_ReadOnly);
                if (ds1.RasterCount < 3)
                {
                    MessageBox.Show("不是多波段影像!\n请重新选择", "Error");
                    file1 = null;
                }
            }
        }
Example #8
0
        private async void GetOlines00(string inDataPath, string _outDSpath, string OutShpPath, double ImprotLevel = 80)
        {
            Gdal.AllRegister();


            Dataset _inDataset  = Gdal.Open(inDataPath, Access.GA_ReadOnly);
            Dataset _outDataset = Gdal.Open(_outDSpath, Access.GA_ReadOnly);


            int iCount = 0, Maxcnt = GetCutNumberOfImg(inDataPath);

            for (int i = 0; i < Maxcnt; i++)
            {
                CutData data = new CutData(inDataPath, _outDSpath, OutShpPath, i, ImprotLevel);
                await Task.Run(() =>
                {
                    TKData(data);
                    iCount++;
                    if (iCount == Maxcnt)
                    {
                        asyRE.Set();
                    }
                });
            }
        }
Example #9
0
        public void GetOlines(string inDataPath, string _outDSpath, string OutShpPath, double ImprotLevel = 80)
        {
            Gdal.AllRegister();

            qthread = new QThread(OutShpPath);
            Dataset _inDataset  = Gdal.Open(inDataPath, Access.GA_ReadOnly);
            Dataset _outDataset = Gdal.Open(_outDSpath, Access.GA_ReadOnly);

            AutoResetEvent autoRE = new AutoResetEvent(false);
            int            iCount = 0, Maxcnt = GetCutNumberOfImg(inDataPath);

            for (int i = 0; i < Maxcnt; i++)
            {
                CutData data = new CutData(inDataPath, _outDSpath, OutShpPath, i, ImprotLevel);
                Thread  th   = new Thread((tt) =>
                {
                    TKData(tt);
                    iCount++;
                    if (iCount == Maxcnt)
                    {
                        autoRE.Set();
                    }
                });
                th.Name = "thNM_" + i.ToString();
                th.Start(data);
            }
            autoRE.WaitOne();
            qthread.Close();
        }
Example #10
0
        /// <summary>
        /// 从影像拿到帖图
        /// </summary>
        /// <param name="inMapPath"></param>
        /// <param name="saveMapPath"></param>
        void getDom(string inMapPath, string saveMapPath)
        {
            Gdal.AllRegister();
            Dataset ds = Gdal.Open(inMapPath, Access.GA_ReadOnly);

            double[] geoTran = new double[6];
            ds.GetGeoTransform(geoTran);

            Envelope enve = new Envelope();

            geom.GetEnvelope(enve);
            int xoff, yoff, xend, yend, xSize, ySize;

            Tools.geoToImageSpace(geoTran, enve.MinX, enve.MaxY, out xoff, out yoff);
            Tools.geoToImageSpace(geoTran, enve.MaxX, enve.MinY, out xend, out yend);
            xSize = xend - xoff;
            ySize = yend - yoff;
            if (File.Exists(saveMapPath))
            {
                File.Delete(saveMapPath);
            }
            OSGeo.GDAL.Driver dr    = Gdal.GetDriverByName("GTiff");
            Dataset           outDs = dr.Create(saveMapPath, xSize, ySize, 3, DataType.GDT_UInt16, null);

            for (int i = 1; i <= ds.RasterCount; i++)
            {
                double[] values = new double[xSize * ySize];
                ds.GetRasterBand(i).ReadRaster(xoff, yoff, xSize, ySize, values, xSize, ySize, 0, 0);
                outDs.GetRasterBand(i).WriteRaster(0, 0, xSize, ySize, values, xSize, ySize, 0, 0);
            }
            ds.Dispose();
            outDs.Dispose();
        }
Example #11
0
        static void Main()
        {
            m_ctrlLogger.Info("START APPLICATION.");
            try {
                //============================================================
                // GDAL initialize
                //============================================================
                Gdal.AllRegister();

                //============================================================
                // GeoTIFF file copy
                //============================================================
                for (int i = 0; i < FILE_LANDSAT_OUT_IMG.Length; i++)
                {
                    if (File.Exists(FILE_LANDSAT_OUT_IMG[i]) == false)
                    {
                        new Bitmap(FILE_LANDSAT_IN_IMG[i]).Save(FILE_LANDSAT_OUT_IMG[i]);
                    }
                }

                //============================================================
                // Application setup
                //============================================================
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new MainForm());
            } catch (Exception ex) {
                m_ctrlLogger.Fatal(ex);
            } finally {
                m_ctrlLogger.Info("END APPLICATION.");
            }
        }
Example #12
0
 public ImportController(IConfiguration config, gisContext context)
 {
     _context           = context;
     _temp_storage_path = config.GetValue <string>("TempStoragePath");
     Gdal.AllRegister();
     Ogr.RegisterAll();
 }
Example #13
0
        async static void multi(string dsm, string oriShp, int i)
        {
            await Task.Run(() =>
            {
                Ogr.RegisterAll();
                Gdal.AllRegister();

                Dataset rastDs   = Gdal.Open(dsm, Access.GA_ReadOnly);
                var geoTransform = new double[6];
                rastDs.GetGeoTransform(geoTransform);

                OSGeo.OGR.Driver dr = OSGeo.OGR.Ogr.GetDriverByName("ESRI shapefile");
                DataSource featDs   = dr.Open(oriShp, 1);
                Layer oriLayer      = featDs.GetLayerByIndex(0);
                Feature oriFeat     = oriLayer.GetFeature(i);

                Feature bufFeat = new Feature(new FeatureDefn(""));
                bufFeat.SetGeometry(oriFeat.GetGeometryRef().Buffer(1, 0));

                int[] subRasterOff_Size = subRasterInfo(geoTransform, rastDs.RasterXSize, rastDs.RasterYSize, bufFeat);

                getMaxMinValue(rastDs, oriFeat, bufFeat, subRasterOff_Size);

                oriLayer.SetFeature(oriFeat);

                bufFeat.Dispose();
                rastDs.Dispose();
                featDs.Dispose();
                tickTime++;
            });
        }
Example #14
0
        public TileGenerator(string mapfile, string savePath, string tileListId)
        {
            try
            {
                id = tileListId;

                string version = mapscript.msGetVersion();

                if (Directory.Exists(Environment.CurrentDirectory + "\\gdalplugins"))
                {
                    Gdal.SetConfigOption("GDAL_DRIVER_PATH", Environment.CurrentDirectory + "\\gdalplugins");
                }

                Gdal.AllRegister();
                Ogr.RegisterAll();
                mapscript.SetEnvironmentVariable("CURL_CA_BUNDLE=" + Environment.CurrentDirectory + "\\curl-ca-bundle.crt");

                MapUtils.SetPROJ_LIB(Environment.CurrentDirectory + "\\ProjLib");

                Gdal.SetConfigOption("GDAL_DATA", Environment.CurrentDirectory);

                map = new mapObj(mapfile);

                ProcessTileList(savePath, tileListId);
            }
            catch (Exception ex)
            {
                ExceptionDump(ex);
            }
        }
        public double[] GetImageInfo(string inPut)
        {
            double[] rtn = new double[6];

            FileInfo inPutFile = new FileInfo(inPut);

            //입력 파일이 없다면 종료
            if (!inPutFile.Exists)
            {
                return(null);
            }
            else
            {
                //입력 파일이 img 파일이 아니라면 종료
                if (inPutFile.Extension != ".img")
                {
                    return(null);
                }
            }

            Gdal.AllRegister();
            Dataset dataset = Gdal.Open(inPut, Access.GA_ReadOnly);

            dataset.GetGeoTransform(rtn);

            return(rtn);
        }
Example #16
0
        /// <summary>
        /// Configures Gdal.
        /// </summary>
        /// <remarks>Make sure to call this method before using Gdal.</remarks>
        internal static void ConfigureGdal()
        {
            if (!Usable)
            {
                throw new Exception(string.Format(Strings.UnableToConfigure, "GDAL"));
            }
            if (IsGdalConfigured)
            {
                return;
            }

            // Register drivers
            try
            {
                Gdal.AllRegister();
            }
            catch (Exception exception)
            {
                throw new Exception(string.Format(Strings.UnableToConfigure, "GDAL"), exception);
            }

            IsGdalConfigured = true;

            #if DEBUG
            PrintDriversGdal();
            #endif
        }
 /// <summary>
 /// Static constructor.
 /// </summary>
 static DefaultTerrainElevationFactory()
 {
     try {
         Gdal.AllRegister();
     } catch {
     }
 }
Example #18
0
 static void Main()
 {
     Application.EnableVisualStyles();
     Application.SetCompatibleTextRenderingDefault(false);
     //Application.Run(new Form1());
     Gdal.AllRegister();
     FornixModeling.GenModel();
 }
Example #19
0
        public Form1()
        {
            InitializeComponent();

            // init gdal -- very importance
            GdalConfiguration.ConfigureGdal();
            Gdal.AllRegister();
        }
Example #20
0
        public void testStaticPartition()
        {
            Gdal.AllRegister();
            Gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "YES");
            Gdal.SetConfigOption("SHAPE_ENCODING", "");
            Ogr.RegisterAll();

            //读取文件
            DataSource ds     = Ogr.Open(fromPath, 0);
            Layer      oLayer = ds.GetLayerByIndex(0);

            // 写入文件

            OSGeo.OGR.Driver oDriver = Ogr.GetDriverByName("ESRI Shapefile");

            // 创建数据源

            DataSource oDS;

            if (Ogr.Open(toPath, 0) != null)
            {
                oDS = Ogr.Open(toPath, 1);
                oDS.DeleteLayer(0);
            }
            else
            {
                oDS = oDriver.CreateDataSource(toPath, null);
            }


            Layer       toLayer  = oDS.CreateLayer("POINT", oLayer.GetSpatialRef(), wkbGeometryType.wkbPoint, null);
            Random      ran      = new Random();
            Feature     oFeature = null;
            Geometry    lines    = null;
            FeatureDefn oDefn    = oLayer.GetLayerDefn();

            FieldDefn oFieldID = new FieldDefn("HEIGHT_G", FieldType.OFTReal);

            toLayer.CreateField(oFieldID, 1);

            FieldDefn oFieldName = new FieldDefn("PWLs", FieldType.OFTReal);

            toLayer.CreateField(oFieldName, 1);

            while ((oFeature = oLayer.GetNextFeature()) != null)
            {
                //read current feature

                lines = oFeature.GetGeometryRef();
                Feature feature = new Feature(oDefn);
                feature.SetGeometry(Line.getPoint(lines, lines.Centroid()));
                feature.SetField(0, 4.0);
                feature.SetField(1, ran.Next(40, 120));
                toLayer.CreateFeature(feature);
            }

            oDS.SyncToDisk();
        }
        public Spectrum(string filepath, int X, int Y, PictureBox pictureBox)
        {
            InitializeComponent();
            filepath1.Text = filepath;
            Gdal.AllRegister();
            Dataset ds = Gdal.Open(filepath, Access.GA_ReadOnly);

            imgX.Text = X.ToString();
            imgY.Text = Y.ToString();
            int[] r, g, b;
            int   xSize = ds.RasterXSize;
            int   ySize = ds.RasterYSize;

            double[] tran = new double[6];
            ds.GetGeoTransform(tran);
            float pre_x = X * 1.0f / pictureBox.Width * xSize;
            float pre_y = Y * 1.0f / pictureBox.Height * ySize;

            // 坐标转换
            double x = tran[0] + pre_x * tran[1] + pre_y * tran[2];
            double y = tran[3] + pre_x * tran[4] + pre_y * tran[5];

            trueX.Text = x.ToString();
            trueY.Text = y.ToString();
            if (ds.RasterCount == 1)
            {
                r = new int[xSize * ySize];
                ds.GetRasterBand(1).ReadRaster(0, 0, xSize, ySize, r, xSize, ySize, 0, 0);
                G.Visible = false;
                B.Visible = false;
                R.Text    = "R:" + r[(int)(pre_x + pre_y * xSize)].ToString();
            }
            else if (ds.RasterCount == 2)
            {
                r = new int[xSize * ySize];
                g = new int[xSize * ySize];
                ds.GetRasterBand(1).ReadRaster(0, 0, xSize, ySize, r, xSize, ySize, 0, 0);
                ds.GetRasterBand(2).ReadRaster(0, 0, xSize, ySize, g, xSize, ySize, 0, 0);
                G.Visible = true;
                B.Visible = false;
                R.Text    = "R:" + r[(int)(pre_x + pre_y * xSize)].ToString();
                G.Text    = "G:" + g[(int)(pre_x + pre_y * xSize)].ToString();
            }
            else
            {
                r = new int[xSize * ySize];
                g = new int[xSize * ySize];
                b = new int[xSize * ySize];
                ds.GetRasterBand(1).ReadRaster(0, 0, xSize, ySize, r, xSize, ySize, 0, 0);
                ds.GetRasterBand(2).ReadRaster(0, 0, xSize, ySize, g, xSize, ySize, 0, 0);
                ds.GetRasterBand(3).ReadRaster(0, 0, xSize, ySize, b, xSize, ySize, 0, 0);
                G.Visible = true;
                B.Visible = true;
                R.Text    = "R:" + r[(int)(pre_x + pre_y * xSize)].ToString();
                G.Text    = "G:" + g[(int)(pre_x + pre_y * xSize)].ToString();
                B.Text    = "B:" + b[(int)(pre_x + pre_y * xSize)].ToString();
            }
        }
Example #22
0
        /// <summary>
        /// 从影像拿到帖图
        /// </summary>
        /// <param name="inMapPath"></param>
        /// <param name="saveMapPath"></param>
        void getDom(string inMapPath, string saveMapPath)
        {
            Gdal.AllRegister();
            OSGeo.GDAL.Gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "YES");
            //打开DOM
            Dataset ds = Gdal.Open(inMapPath, Access.GA_ReadOnly);

            double[] geoTran = new double[6];
            ds.GetGeoTransform(geoTran);
            //拿边界
            Envelope enve = new Envelope();

            geom.GetEnvelope(enve);
            int xoff, yoff, xend, yend, xSize, ySize;

            Tools.geoToImageSpace(geoTran, enve.MinX, enve.MaxY, out xoff, out yoff);
            Tools.geoToImageSpace(geoTran, enve.MaxX, enve.MinY, out xend, out yend);
            xSize = xend - xoff;
            ySize = yend - yoff;

            //创建新文件
            if (File.Exists(saveMapPath))
            {
                File.Delete(saveMapPath);
            }

            OSGeo.GDAL.Driver dr    = Gdal.GetDriverByName("GTIFF");
            Dataset           outDs = dr.Create(saveMapPath, xSize, ySize, 3, DataType.GDT_Byte, null);// --------------------for test

            geoTran[0] = enve.MinX;
            geoTran[3] = enve.MaxY;
            outDs.SetGeoTransform(geoTran);

            for (int i = 1; i <= ds.RasterCount; i++)
            {
                int[] values = new int[xSize * ySize];
                ds.GetRasterBand(i).ReadRaster(xoff, yoff, xSize, ySize, values, xSize, ySize, 0, 0);

                Band band = outDs.GetRasterBand(i);
                band.WriteRaster(0, 0, xSize, ySize, values, xSize, ySize, 0, 0);
                band.FlushCache();
                outDs.FlushCache();
            }
            for (int b = 1; b < 4; b++)
            {
                double min, max, mean, std;
                Band   oriBand = ds.GetRasterBand(b);
                Band   band    = outDs.GetRasterBand(b);

                //P1 是否接受小误差         --------------------for test
                oriBand.ComputeStatistics(true, out min, out max, out mean, out std, null, "");
                band.SetStatistics(min, max, mean, std);

                band.FlushCache();
            }
            outDs.Dispose();
            ds.Dispose();
        }
Example #23
0
 static GdalWmtsService()
 {
     Gdal.AllRegister();
     // 为了支持中文路径,请添加下面这句代码
     Gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "NO");
     // 为了使属性表字段支持中文,请添加下面这句
     Gdal.SetConfigOption("SHAPE_ENCODING", "");
     Ogr.RegisterAll();
 }
Example #24
0
        public static int GetXSize(String fileName)
        {
            Gdal.AllRegister();

            Dataset dataset = Gdal.Open(fileName, Access.GA_ReadOnly);
            Band    band    = dataset.GetRasterBand(1);

            return(band.XSize);
        }
Example #25
0
        public GdalFunctionStore()
        {
            state          = GdalState.Closed;
            TypeConverters = new List <ITypeConverter>();
            Functions      = new EventedList <IFunction>();

            //register gdal drivers
            Gdal.AllRegister();
        }
Example #26
0
        static GDAL()
        {
            // seed the assembly load
            //new MissionPlanner.Drawing.Common.Common();

            log.InfoFormat("GDAL static ctor");
            //GdalConfiguration.ConfigureGdal();
            Gdal.AllRegister();
        }
        public void IsGeoTiff_Test()
        {
            // Opens a GeoTiff with elevation data. IsGeoTiff should return true. Then opens Tiff with color RGB values. IsGeoTiff should return false
            string goodTiffName = testingFolder + "Findlay Topo.tif";
            string badTiffName  = testingFolder + "DEM JM.tif";

            TopoInfo    topo  = new TopoInfo();
            Check_class check = new Check_class();

            GdalConfiguration.ConfigureGdal();
            Gdal.AllRegister();
            Dataset GDAL_obj;

            // Test function with GeoTiff file
            try
            {
                GDAL_obj = Gdal.Open(goodTiffName, Access.GA_ReadOnly);
            }
            catch
            {
                return;
            }

            int width  = GDAL_obj.RasterXSize;
            int height = GDAL_obj.RasterYSize;

            Band GD_Raster = GDAL_obj.GetRasterBand(1);

            double[] buff = new double[width * height];
            GD_Raster.ReadRaster(0, 0, width, height, buff, width, height, 0, 0);

            bool isGeoTiff = check.IsGeoTIFF(buff);

            Assert.AreSame(true, isGeoTiff);

            // Test function with a TIF (color RGB) file
            try
            {
                GDAL_obj = Gdal.Open(goodTiffName, Access.GA_ReadOnly);
            }
            catch
            {
                return;
            }

            width  = GDAL_obj.RasterXSize;
            height = GDAL_obj.RasterYSize;

            GD_Raster = GDAL_obj.GetRasterBand(1);

            buff = new double[width * height];
            GD_Raster.ReadRaster(0, 0, width, height, buff, width, height, 0, 0);

            isGeoTiff = check.IsGeoTIFF(buff);
            Assert.AreSame(false, isGeoTiff);
        }
Example #28
0
    public static void Main(string[] args)
    {
        if (args.Length < 2)
        {
            usage();
        }

        // Using early initialization of System.Console
        Console.WriteLine("");

        try
        {
            /* -------------------------------------------------------------------- */
            /*      Register driver(s).                                             */
            /* -------------------------------------------------------------------- */
            Gdal.AllRegister();

            /* -------------------------------------------------------------------- */
            /*      Open dataset.                                                   */
            /* -------------------------------------------------------------------- */
            Dataset ds = Gdal.Open(args[0], Access.GA_ReadOnly);

            if (ds == null)
            {
                Console.WriteLine("Can't open " + args[0]);
                System.Environment.Exit(-1);
            }

            Console.WriteLine("Raster dataset parameters:");
            Console.WriteLine("  Projection: " + ds.GetProjectionRef());
            Console.WriteLine("  RasterCount: " + ds.RasterCount);
            Console.WriteLine("  RasterSize (" + ds.RasterXSize + "," + ds.RasterYSize + ")");

            /* -------------------------------------------------------------------- */
            /*      Get driver                                                      */
            /* -------------------------------------------------------------------- */
            Driver drv = ds.GetDriver();

            if (drv == null)
            {
                Console.WriteLine("Can't get driver.");
                System.Environment.Exit(-1);
            }

            Console.WriteLine("Using driver " + drv.LongName);

            /* -------------------------------------------------------------------- */
            /*      Processing the raster                                           */
            /* -------------------------------------------------------------------- */
            SaveBitmapDirect(args[1], ds, 0, 0, ds.RasterXSize, ds.RasterYSize, ds.RasterXSize, ds.RasterYSize);
        }
        catch (Exception e)
        {
            Console.WriteLine("Application error: " + e.Message);
        }
    }
Example #29
0
 public Form1()
 {
     GdalConfiguration.ConfigureGdal();
     GdalConfiguration.ConfigureOgr();
     Gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "YES");
     Gdal.AllRegister();
     Gdal.SetConfigOption("SHAPE_ENCODING", "");
     Ogr.RegisterAll();
     InitializeComponent();
 }
 protected override void BeginProcessing()
 {
     GdalConfiguration.ConfigureGdal();
     System.Console.WriteLine("Starting...");
     Gdal.AllRegister();
     if (Destination == null)
     {
         Destination = System.IO.Path.GetDirectoryName(Path) + "/Output.stl";
     }
 }