Ejemplo n.º 1
0
        /// <summary>
        /// Method to ensure the static constructor is being called.
        /// </summary>
        /// <remarks>Be sure to call this function before using Gdal/Ogr/Osr</remarks>
        public static void ConfigureGdal()
        {
            if (_configuredGdal)
            {
                return;
            }

            // Register drivers
            Gdal.AllRegister();
            _configuredGdal = true;

            PrintDriversGdal();
        }
        /// <summary>
        /// Construction of Gdal/Ogr
        /// </summary>
        static GdalConfiguration()
        {
            string executingAssemblyFile = new Uri(Assembly.GetExecutingAssembly().GetName().CodeBase).LocalPath;
            string executingDirectory    = Path.GetDirectoryName(executingAssemblyFile);

            if (string.IsNullOrEmpty(executingDirectory))
            {
                throw new InvalidOperationException("cannot get executing directory");
            }


            string gdalPath = Path.Combine(executingDirectory, "gdal");
            string path, nativePath;

            if (IsWindows)
            {
                nativePath = Path.Combine(gdalPath, GetPlatform());
                path       = Environment.GetEnvironmentVariable("PATH");
                path       = nativePath + ";" + Path.Combine(nativePath, "plugins") + ";" + path;
            }
            else
            {
                nativePath = gdalPath;
                path       = Environment.GetEnvironmentVariable("LD_LIBRARY_PATH");
                path       = nativePath + ":" + Path.Combine(nativePath, "plugins") + ":" + path;
            }

            // Prepend native path to environment path, to ensure the
            // right libs are being used.
            Environment.SetEnvironmentVariable("PATH", path);

            // Set environment variables
            if (IsWindows)
            {
                // Set the additional GDAL environment variables.
                string gdalData = Path.Combine(gdalPath, "data");
                Environment.SetEnvironmentVariable("GDAL_DATA", gdalData);
                Gdal.SetConfigOption("GDAL_DATA", gdalData);

                string driverPath = Path.Combine(nativePath, "plugins");
                Environment.SetEnvironmentVariable("GDAL_DRIVER_PATH", driverPath);
                Gdal.SetConfigOption("GDAL_DRIVER_PATH", driverPath);

                Environment.SetEnvironmentVariable("GEOTIFF_CSV", gdalData);
                Gdal.SetConfigOption("GEOTIFF_CSV", gdalData);

                string projSharePath = Path.Combine(gdalPath, "share");
                Environment.SetEnvironmentVariable("PROJ_LIB", projSharePath);
                Gdal.SetConfigOption("PROJ_LIB", projSharePath);
            }
        }
Ejemplo n.º 3
0
        private static void PrintDriversGdal()
        {
#if DEBUG
            if (_usable)
            {
                var num = Gdal.GetDriverCount();
                for (var i = 0; i < num; i++)
                {
                    var driver = Gdal.GetDriver(i);
                    Trace.WriteLine($"GDAL {i}: {driver.ShortName}-{driver.LongName}");
                }
            }
#endif
        }
Ejemplo n.º 4
0
        private void runFunc()
        {
            Ogr.RegisterAll();
            Gdal.SetConfigOption("SHAPE_ENCODING", "CP936");

            string strInfo = string.Empty;
            //打开数据
            DataSource ds = Ogr.Open(mFileName, 0);

            if (ds == null)
            {
                strInfo += string.Format("打开文件【{0}】失败!\n", mFileName);
                return;
            }
            strInfo += string.Format("打开文件【{0}】成功!\n", mFileName);

            CGetShp mdbToShp = new CGetShp(mFileName, mOutPath);
            // 获取该数据源中的图层个数,一般shp数据图层只有一个,如果是mdb、dxf等图层就会有多个
            int iLayerCount = ds.GetLayerCount();

            strInfo += string.Format("个人地理数据库共包含{0}个图层!\n", iLayerCount);
            for (int i = 0; i < iLayerCount; i++)
            {
                // 获取第一个图层
                Layer oLayer = ds.GetLayerByIndex(i);

                if (oLayer == null)
                {
                    strInfo += string.Format("获取第{0}个图层失败!\n", i);
                    return;
                }
                strInfo += string.Format("第{0}个图层名称:{1}\n", i, oLayer.GetName());
                //若当前图层为向量数据
                if (oLayer.GetName().Contains("LINE"))
                {
                    //调用方法获取向量信息,并传入想应的点图层名以方便查询
                    mdbToShp.readLine(ref oLayer, oLayer.GetName().Replace("LINE", "POINT"));
                    //break;
                }
                else
                {
                    mdbToShp.readPoint(ref oLayer);
                    //break;
                    //mdbToShp.test(ref oLayer);
                }

                SetTextMessage(100 * (i + 1) / iLayerCount);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Construction of Gdal/Ogr
        /// </summary>
        static GdalConfiguration()
        {
            var executingAssemblyFile = new Uri(Assembly.GetExecutingAssembly().GetName().CodeBase).LocalPath;
            var executingDirectory    = Path.GetDirectoryName(executingAssemblyFile);

            if (string.IsNullOrEmpty(executingDirectory))
            {
                throw new InvalidOperationException("cannot get executing directory");
            }


            var gdalPath   = Path.Combine(executingDirectory, "gdal");
            var nativePath = Path.Combine(gdalPath, GetPlatform());

            Debug.WriteLine(nativePath);

            // Prepend native path to environment path, to ensure the
            // right libs are being used.
            var path = Environment.GetEnvironmentVariable("PATH");

            path = gdalPath + ";" + nativePath + ";" + Path.Combine(nativePath, "plugins") + ";" + Path.Combine(nativePath, "plugins-external") + ";" + path;
            Environment.SetEnvironmentVariable("PATH", path);

            Debug.WriteLine("PATH: " + path);

            // Set the additional GDAL environment variables.
            var gdalData = Path.Combine(gdalPath, "gdal-data");

            Environment.SetEnvironmentVariable("GDAL_DATA", gdalData);
            Gdal.SetConfigOption("GDAL_DATA", gdalData);

            Debug.WriteLine("GDAL_DATA: " + gdalData);

            var driverPath    = Path.Combine(nativePath, "plugins");
            var extDriverPath = Path.Combine(nativePath, "plugins-external");

            Environment.SetEnvironmentVariable("GDAL_DRIVER_PATH", driverPath + ";" + extDriverPath);
            Gdal.SetConfigOption("GDAL_DRIVER_PATH", driverPath + ";" + extDriverPath);

            Environment.SetEnvironmentVariable("GEOTIFF_CSV", gdalData);
            Gdal.SetConfigOption("GEOTIFF_CSV", gdalData);

            var projPath      = Path.Combine(gdalPath, "proj");
            var projSharePath = Path.Combine(projPath, "share");

            Environment.SetEnvironmentVariable("PROJ_LIB", projSharePath);
            Gdal.SetConfigOption("PROJ_LIB", projSharePath);
        }
Ejemplo n.º 6
0
        protected void Awake()
        {
            Debug.Log("AppState awakens");
            if (instance == null)
            {
                Debug.Log("AppState instance assigned");
                instance = this;
            }
            else if (instance != this)
            {
                // there cannot be another instance
                Debug.Log("AppState found another instance");
                Destroy(gameObject);
            }
            DontDestroyOnLoad(gameObject);
            _editSession = new EditSession();
            _layers      = new List <VirgisLayer>();
            Zoom         = new ZoomEvent();
            Project      = new ProjectChange();
            Info         = new InfoEvent();
            ButtonStatus = new ButtonStatus();
            Orientation  = new OrientEvent();
            LayerUpdate  = new LayerChange();

            initsub = Project.Event.Subscribe(proj => Init());
            try {
                GdalConfiguration.ConfigureOgr();
            } catch (Exception e) {
                Debug.LogError(e.ToString());
            };
            try {
                GdalConfiguration.ConfigureGdal();
            } catch (Exception e) {
                Debug.LogError(e.ToString());
            };
            try {
                PdalConfiguration.ConfigurePdal();
            } catch (Exception e) {
                Debug.LogError(e.ToString());
            };
            try {
                Debug.Log($" MDAL Version : {MdalConfiguration.ConfigureMdal()}");
            } catch (Exception e) {
                Debug.LogError(e.ToString());
            }
            Gdal.SetConfigOption("CURL_CA_BUNDLE", Path.Combine(Application.streamingAssetsPath, "gdal", "cacert.pem"));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Construction of Gdal/Ogr
        /// </summary>
        static GdalConfiguration()
        {
            var executingAssemblyFile = new Uri(Assembly.GetExecutingAssembly().GetName().CodeBase).LocalPath;
            var executingDirectory    = Path.GetDirectoryName(executingAssemblyFile);

            if (string.IsNullOrEmpty(executingDirectory))
            {
                throw new InvalidOperationException("cannot get executing directory");
            }


            //var gdalPath = Path.Combine(executingDirectory, "gdal");
            //var nativePath = Path.Combine(gdalPath, GetPlatform());

            // We put all our gdal libs in the lib folder
            string ThePath = Environment.GetEnvironmentVariable("PATH");
            string libPath = Path.Combine(executingDirectory, "lib");
            string NewPath = libPath + ";" + ThePath;

            Environment.SetEnvironmentVariable("PATH", NewPath);

            // Prepend native path to environment path, to ensure the
            // right libs are being used.
            //var path = Environment.GetEnvironmentVariable("PATH");
            //path = nativePath + ";" + Path.Combine(nativePath, "plugins") + ";" + path;
            //Environment.SetEnvironmentVariable("PATH", path);

            // Set the additional GDAL environment variables.
            var gdalData = Path.Combine(libPath, "data");

            Environment.SetEnvironmentVariable("GDAL_DATA", gdalData);
            Gdal.SetConfigOption("GDAL_DATA", gdalData);

            //var driverPath = Path.Combine(nativePath, "plugins");
            //Environment.SetEnvironmentVariable("GDAL_DRIVER_PATH", driverPath);
            //Gdal.SetConfigOption("GDAL_DRIVER_PATH", driverPath);

            //Environment.SetEnvironmentVariable("GEOTIFF_CSV", gdalData);
            //Gdal.SetConfigOption("GEOTIFF_CSV", gdalData);

            //var projSharePath = Path.Combine(gdalPath, "share");
            //Environment.SetEnvironmentVariable("PROJ_LIB", projSharePath);
            //Gdal.SetConfigOption("PROJ_LIB", projSharePath);
        }
Ejemplo n.º 8
0
        private static void PrintDriversGdal()
        {
            var num = Gdal.GetDriverCount();

            for (var i = 0; i < num; i++)
            {
                var driver = Gdal.GetDriver(i);

                string extension = driver.GetMetadataItem("DMD_EXTENSION", "");
                if (!String.IsNullOrWhiteSpace(extension) && !dicDriverExt.ContainsKey(extension))
                {
                    dicDriverExt.Add(extension, string.Format("{1} - {2}|*.{0}", extension, driver.ShortName, driver.LongName));
                }

#if DEBUG
                Console.WriteLine(string.Format("GDAL {0}: {1}-{2}", extension, driver.ShortName, driver.LongName));
#endif
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Method to ensure the static constructor is being called.
        /// </summary>
        /// <remarks>Be sure to call this function before using Gdal/Ogr/Osr</remarks>
        public static void ConfigureGdal()
        {
            if (_configuredGdal)
            {
                return;
            }

            // Register drivers
            try
            {
                Gdal.AllRegister();
                _configuredGdal = true;
            }
            catch (Exception e) {
                Debug.WriteLine(e.Message);
                _configuredGdal = false;
            }

            PrintDriversGdal();
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Construction of Gdal/Ogr
        /// </summary>
        static GdalConfiguration()
        {
            var ghLibFile          = typeof(ImportVector).Assembly.Location;
            var executingDirectory = Path.GetDirectoryName(ghLibFile);

            if (string.IsNullOrEmpty(executingDirectory))
            {
                throw new InvalidOperationException("cannot get executing directory");
            }

            var gdalPath   = Path.Combine(executingDirectory, "gdal");
            var nativePath = Path.Combine(gdalPath, GetPlatform());

            // Prepend native path to environment path, to ensure the
            // right libs are being used.
            var path = Environment.GetEnvironmentVariable("Path");

            path = nativePath + ";" + Path.Combine(nativePath, "plugins") + ";" + path;
            Environment.SetEnvironmentVariable("Path", path);

            // Set the additional GDAL environment variables.
            var gdalData = Path.Combine(gdalPath, "data");

            Environment.SetEnvironmentVariable("GDAL_DATA", gdalData);
            Gdal.SetConfigOption("GDAL_DATA", gdalData);

            var driverPath = Path.Combine(nativePath, "plugins");

            Environment.SetEnvironmentVariable("GDAL_DRIVER_PATH", driverPath);
            Gdal.SetConfigOption("GDAL_DRIVER_PATH", driverPath);

            Environment.SetEnvironmentVariable("GEOTIFF_CSV", gdalData);
            Gdal.SetConfigOption("GEOTIFF_CSV", gdalData);

            var projSharePath = Path.Combine(gdalPath, "share");

            Environment.SetEnvironmentVariable("PROJ_LIB", projSharePath);
            Gdal.SetConfigOption("PROJ_LIB", projSharePath);

            OSGeo.GDAL.Gdal.SetConfigOption("GDAL_HTTP_UNSAFESSL", "YES");
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Construction of Gdal/Ogr
        /// </summary>
        static GdalConfiguration()
        {
            var ghLibDir           = Grasshopper.Folders.DefaultAssemblyFolder;
            var executingDirectory = Path.Combine(ghLibDir, "Heron");

            if (string.IsNullOrEmpty(executingDirectory))
            {
                throw new InvalidOperationException("cannot get executing directory");
            }

            var gdalPath   = Path.Combine(executingDirectory, "gdal");
            var nativePath = Path.Combine(gdalPath, GetPlatform());

            // Prepend native path to environment path, to ensure the
            // right libs are being used.
            var path = Environment.GetEnvironmentVariable("Path");

            path = nativePath + ";" + Path.Combine(nativePath, "plugins") + ";" + path;
            Environment.SetEnvironmentVariable("Path", path);

            // Set the additional GDAL environment variables.
            var gdalData = Path.Combine(gdalPath, "data");

            Environment.SetEnvironmentVariable("GDAL_DATA", gdalData);
            Gdal.SetConfigOption("GDAL_DATA", gdalData);

            var driverPath = Path.Combine(nativePath, "plugins");

            Environment.SetEnvironmentVariable("GDAL_DRIVER_PATH", driverPath);
            Gdal.SetConfigOption("GDAL_DRIVER_PATH", driverPath);

            Environment.SetEnvironmentVariable("GEOTIFF_CSV", gdalData);
            Gdal.SetConfigOption("GEOTIFF_CSV", gdalData);

            var projSharePath = Path.Combine(gdalPath, "share");

            Environment.SetEnvironmentVariable("PROJ_LIB", projSharePath);
            Gdal.SetConfigOption("PROJ_LIB", projSharePath);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Construction of Gdal/Ogr
        /// </summary>
        static GdalConfiguration()
        {
            var executingAssemblyFile = new Uri(Assembly.GetExecutingAssembly().GetName().CodeBase).LocalPath;
            var executingDirectory    = Path.GetDirectoryName(executingAssemblyFile);

            if (string.IsNullOrEmpty(executingDirectory))
            {
                throw new InvalidOperationException("cannot get executing directory");
            }

            var    path    = Environment.GetEnvironmentVariable("PATH");
            String gdalLib = Path.Combine(executingDirectory, "MVActiveX");

            path = gdalLib + ";" + path;
            Environment.SetEnvironmentVariable("PATH", path);

            String gdalData = Path.Combine(executingDirectory, "gdal\\data");

            Environment.SetEnvironmentVariable("GDAL_DATA", gdalData);
            Gdal.SetConfigOption("GDAL_DATA", gdalData);
            Environment.SetEnvironmentVariable("GEOTIFF_CSV", gdalData);
            Gdal.SetConfigOption("GEOTIFF_CSV", gdalData);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Construction of Gdal/Ogr
        /// </summary>
        static GdalConfiguration()
        {
            string executingDirectory = null, gdalPath = null, nativePath = null;

            try
            {
                if (!IsWindows)
                {
                    const string notSet = "_Not_set_";
                    string       tmp    = Gdal.GetConfigOption("GDAL_DATA", notSet);
                    _usable = tmp != notSet;
                    return;
                }

                string executingAssemblyFile = new Uri(Assembly.GetExecutingAssembly().GetName().CodeBase).LocalPath;
                executingDirectory = Path.GetDirectoryName(executingAssemblyFile);

                if (string.IsNullOrEmpty(executingDirectory))
                {
                    throw new InvalidOperationException("cannot get executing directory");
                }


                // modify search place and order
                SetDefaultDllDirectories(DllSearchFlags);

                gdalPath   = Path.Combine(executingDirectory, "gdal");
                nativePath = Path.Combine(gdalPath, GetPlatform());
                if (!Directory.Exists(nativePath))
                {
                    throw new DirectoryNotFoundException($"GDAL native directory not found at '{nativePath}'");
                }
                if (!File.Exists(Path.Combine(nativePath, "gdal_wrap.dll")))
                {
                    throw new FileNotFoundException(
                              $"GDAL native wrapper file not found at '{Path.Combine(nativePath, "gdal_wrap.dll")}'");
                }

                // Add directories
                AddDllDirectory(nativePath);
                AddDllDirectory(Path.Combine(nativePath, "plugins"));

                // Set the additional GDAL environment variables.
                string gdalData = Path.Combine(gdalPath, "data");
                Environment.SetEnvironmentVariable("GDAL_DATA", gdalData);
                Gdal.SetConfigOption("GDAL_DATA", gdalData);

                string driverPath = Path.Combine(nativePath, "plugins");
                Environment.SetEnvironmentVariable("GDAL_DRIVER_PATH", driverPath);
                Gdal.SetConfigOption("GDAL_DRIVER_PATH", driverPath);

                Environment.SetEnvironmentVariable("GEOTIFF_CSV", gdalData);
                Gdal.SetConfigOption("GEOTIFF_CSV", gdalData);

                string projSharePath = Path.Combine(gdalPath, "share");
                Environment.SetEnvironmentVariable("PROJ_LIB", projSharePath);
                Gdal.SetConfigOption("PROJ_LIB", projSharePath);

                _usable = true;
            }
            catch (Exception e)
            {
                _usable = false;
                Trace.WriteLine(e, "error");
                Trace.WriteLine($"Executing directory: {executingDirectory}", "error");
                Trace.WriteLine($"gdal directory: {gdalPath}", "error");
                Trace.WriteLine($"native directory: {nativePath}", "error");

                //throw;
            }
        }