예제 #1
0
        private List <(double lon, double lat)> GetPlots()
        {
            GdalBase.ConfigureAll();
            double[] pointList = { 0, 0, 0 };
            var      points    = new List <(double lon, double lat)>();

            foreach (var file in Directory.GetFiles("files", "*.shp"))
            {
                var dataSource = Ogr.Open(file, 0);
                var layer      = dataSource.GetLayerByIndex(0);

                var envelop = new Envelope();
                layer.GetExtent(envelop, 0);

                for (var i = 0; i < layer.GetFeatureCount(0); ++i)
                {
                    var feature    = layer.GetFeature(i);
                    var geo        = feature.GetGeometryRef();
                    var ring       = geo.GetGeometryRef(0);
                    var pointCount = ring.GetPointCount();

                    for (var l = 0; l < pointCount; ++l)
                    {
                        ring.GetPoint(l, pointList);
                        points.Add((pointList[0], pointList[1]));
                        // pointList[0] is the Longitude.
                        // pointList[1] is the Latitude.
                        // pointList[2] is the Altitude.
                    }
                }
            }

            return(points);
        }
예제 #2
0
        public static void Main()
        {
            GdalBase.ConfigureAll();

            string dataSetPath = Path.GetFullPath(Program.TestDataSetPath, Directory.GetCurrentDirectory());

            Program.Open(dataSetPath);

            Program.Details(dataSetPath);

            Program.AttributeIndex(dataSetPath);

            Program.SpatialIndex(dataSetPath);

            Program.SpatialIndexAdvanced(dataSetPath);

            Program.SelectRandomFeatures(dataSetPath, 3);

            Program.SelectRandomFeatureWeighted(dataSetPath, 3);

            Coordinate coordinate = new Coordinate(4793000, 2809000);             // Vienna Town Hall (Rathaus)

            Program.SelectFeatureAtLocations(dataSetPath, new List <Coordinate> {
                coordinate
            });
        }
예제 #3
0
        static void Main(string[] args)
        {
            try
            {
                Console.WriteLine("Working directory: " + Directory.GetCurrentDirectory());
                Console.WriteLine("Trying to configure all twice");
                GdalBase.ConfigureAll();
                GdalBase.ConfigureAll();
                Console.WriteLine("GDAL configured");

                Console.WriteLine(string.Join('\n',
                                              "GDAL Version: " + Gdal.VersionInfo("RELEASE_NAME"),
                                              "GDAL INFO: " + Gdal.VersionInfo("")));
                var spatialReference = new SpatialReference(null);
                spatialReference.SetWellKnownGeogCS("wgs84");

                var dataset = OSGeo.OGR.Ogr.Open("test222.shp", 0);
                var layer   = dataset.GetLayerByIndex(0);
                var feature = layer.GetNextFeature();
                var field   = feature.GetFieldAsString("overflade");
                Console.WriteLine("test222 overflade attribute value");
                Console.WriteLine("expected:" + "Befæstet");
                Console.WriteLine("actual:" + field);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
예제 #4
0
        public static bool RunConfigureCore(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = null)] HttpRequest req,
            ILogger log)
        {
            GdalBase.ConfigureAll();

            return(GdalBase.IsConfigured);
        }
예제 #5
0
        public Utf8Tests(ITestOutputHelper outputHelper)
        {
            _outputHelper = outputHelper;
            GdalBase.ConfigureAll();

            dataDirectoryPath     = Extensions.GetTestDataFolder("utf8-data");
            englishInputFilePath  = Path.Combine(dataDirectoryPath, "input.tif");
            cyrillicInputFilePath = Path.Combine(dataDirectoryPath, "тест.tif");
        }
예제 #6
0
        static void Main(string[] args)
        {
            try
            {
                Console.WriteLine($"Working directory: {Directory.GetCurrentDirectory()}");
                Console.WriteLine("Trying to configure all twice");
                GdalBase.ConfigureAll();
                GdalBase.ConfigureAll();
                Console.WriteLine("GDAL configured");

                var version = Assembly.GetAssembly(typeof(MaxRev.Gdal.Core.GdalBase))
                              .GetCustomAttribute <AssemblyInformationalVersionAttribute>()
                              .InformationalVersion;

                Console.WriteLine($"Package version: {version}");

                Console.WriteLine(string.Join('\n',
                                              $"GDAL Version: {Gdal.VersionInfo("RELEASE_NAME")}",
                                              $"GDAL INFO: {Gdal.VersionInfo("")}"));
                var spatialReference = new SpatialReference(null);
                spatialReference.SetWellKnownGeogCS("wgs84");

                // list of common drivers
                var drivers = new[]
                {
                    "hdf4", "hdf5", "gtiff", "aaigrid", "adrg", "airsar", "arg", "blx", "bmp", "bsb", "cals", "ceos",
                    "coasp", "cosar", "ctg", "dimap", "dted", "e00grid", "elas", "ers", "fit", "gff", "gxf", "hf2",
                    "idrisi", "ignfheightasciigrid", "ilwis", "ingr", "iris", "jaxapalsar", "jdem", "kmlsuperoverlay",
                    "l1b", "leveller", "map", "mrf", "msgn", "ngsgeoid", "nitf", "pds", "prf", "r", "rmf", "rs2",
                    "safe", "saga", "sdts", "sentinel2", "sgi", "sigdem", "srtmhgt", "terragen", "til", "tsx",
                    "usgsdem", "xpm", "xyz", "zmap", "rik", "ozi", "grib", "rasterlite", "mbtiles", "pdf", "aeronavfaa",
                    "arcgen", "bna", "cad", "csv", "dgn", "dxf", "edigeo", "geoconcept", "georss", "gml", "gpsbabel",
                    "gpx", "htf", "jml", "mvt", "openair", "openfilegdb", "pgdump", "rec", "s57", "segukooa", "segy",
                    "selafin", "ESRI Shapefile", "sua", "svg", "sxf", "tiger", "vdv", "wasp", "xplane", "idrisi", "pds",
                    "sdts", "gpkg", "vfk", "osm", "PostgreSQL"
                };

                foreach (var driver in drivers)
                {
                    var driverByName = Gdal.GetDriverByName(driver);
                    Console.WriteLine(
                        driverByName != default ? $"{driver} loaded successfully" : $"Failed to load {driver}");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
예제 #7
0
        static void Main(string[] args)
        {
            try
            {
                Console.WriteLine($"Working directory: {Directory.GetCurrentDirectory()}");
                Console.WriteLine("Trying to configure all twice");
                GdalBase.ConfigureAll();
                GdalBase.ConfigureAll();
                Console.WriteLine("GDAL configured");

                var version = Assembly.GetAssembly(typeof(MaxRev.Gdal.Core.GdalBase))
                              .GetCustomAttribute <AssemblyInformationalVersionAttribute>()
                              .InformationalVersion;

                Console.WriteLine($"Package version: {version}");

                Console.WriteLine(string.Join('\n',
                                              $"GDAL Version: {Gdal.VersionInfo("RELEASE_NAME")}",
                                              $"GDAL INFO: {Gdal.VersionInfo("")}"));
                var spatialReference = new SpatialReference(null);
                spatialReference.SetWellKnownGeogCS("wgs84");

                for (int driverIndex = 0; driverIndex < Gdal.GetDriverCount(); driverIndex++)
                {
                    var driverByName = Gdal.GetDriver(driverIndex);
                    Console.WriteLine(
                        driverByName != default ? $"{driverByName.ShortName} loaded successfully" : $"Failed to load {driverByName.ShortName}");
                }

                // retrieve list of drivers for tests
                Console.WriteLine("Test string:");
                var driverList = string.Join(',', Enumerable.Range(0, Gdal.GetDriverCount())
                                             .Select(i => Gdal.GetDriver(i).ShortName)
                                             .OrderBy(x => x)
                                             .Select(x => $"\"{x}\""));
                Console.WriteLine(driverList);
                Console.WriteLine("Drivers:" + Gdal.GetDriverCount());
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
예제 #8
0
        public static Raster Load(string inputFilePath)
        {
            GdalBase.ConfigureAll();

            if (!File.Exists(inputFilePath))
            {
                return(null);
            }

            try
            {
                using Dataset dataset = Gdal.Open(inputFilePath, Access.GA_ReadOnly);

                Band band = dataset.GetRasterBand(1);
                band.GetNoDataValue(out double noDataValue, out int hasVal);

                int[] buffer = new int[band.XSize * band.YSize];
                band.ReadRaster(0, 0, band.XSize, band.YSize, buffer, band.XSize, band.YSize, 0, 0);

                return(new Raster
                {
                    driver = dataset.GetDriver(),
                    projection = dataset.GetProjection(),
                    Cols = band.XSize,
                    Rows = band.YSize,
                    hasNoDataValue = hasVal == 1,
                    noDataValue = noDataValue,
                    Cells = buffer,
                });
            }
#pragma warning disable CA1031 // Do not catch general exception types
            catch (Exception)
            {
                return(null);
            }
#pragma warning restore CA1031 // Do not catch general exception types
        }
예제 #9
0
 public CommonTests(ITestOutputHelper outputHelper)
 {
     _outputHelper = outputHelper;
     GdalBase.ConfigureAll();
 }
예제 #10
0
 /// <summary>
 /// Configure and initialize GDAL libraries
 /// </summary>
 public static void Configure() => GdalBase.ConfigureAll();
예제 #11
0
 public void Configure()
 {
     GdalBase.ConfigureAll();
 }