管道基础大数据平台系统开发-【CS】-ExportMap
13693261870
2024-07-18 d20fdf2fccbfdd4a5ac2e6e79523a9558b9a2b51
初始化GDAL
已添加3个文件
已修改3个文件
111 ■■■■■ 文件已修改
SimuTools/FrmMain.cs 16 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SimuTools/SimuTools.csproj 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SimuTools/Tools/GdalHelper.cs 84 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SimuTools/Tools/Handle.cs 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
SimuTools/gdal_wrap.dll 补丁 | 查看 | 原始文档 | blame | 历史
SimuTools/gdalconst_wrap.dll 补丁 | 查看 | 原始文档 | blame | 历史
SimuTools/FrmMain.cs
@@ -17,6 +17,16 @@
        private void FrmMain_Load(object sender, EventArgs e)
        {
            LogOut.Info("启动程序...");
            try
            {
                GdalHelper gdal = GdalHelper.Instance;
                LogOut.Info("> åˆå§‹åŒ–GDAL完成 <");
            }
            catch (Exception ex)
            {
                LogOut.Error(ex.StackTrace);
                ShowErr("GDAL初始化出错:" + ex.Message);
            }
        }
        private void FrmMain_FormClosing(object sender, FormClosingEventArgs e)
@@ -97,9 +107,11 @@
            try
            {
                flag = true;
                LogOut.Info("开始运行 >>");
                LogOut.Info(">> å¼€å§‹è¿è¡Œ >>");
                Tools.Handle.Run(terrainFile, waterPath, flowPath, outPath);
                LogOut.Info("运行结束 >>");
                LogOut.Info("<< è¿è¡Œç»“束 <<");
                flag = false;
            }
            catch (Exception ex)
SimuTools/SimuTools.csproj
@@ -45,6 +45,8 @@
      <SpecificVersion>False</SpecificVersion>
      <HintPath>dlls\log4net4.dll</HintPath>
    </Reference>
    <Reference Include="ogr_csharp, Version=3.5.2.0, Culture=neutral, PublicKeyToken=db5a52b08dc5b321, processorArchitecture=MSIL" />
    <Reference Include="osr_csharp, Version=3.5.2.0, Culture=neutral, PublicKeyToken=db5a52b08dc5b321, processorArchitecture=MSIL" />
    <Reference Include="System" />
    <Reference Include="System.Configuration" />
    <Reference Include="System.Core" />
@@ -71,6 +73,7 @@
    </Compile>
    <Compile Include="Program.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
    <Compile Include="Tools\GdalHelper.cs" />
    <Compile Include="Tools\Handle.cs" />
    <Compile Include="Tools\LogOut.cs" />
    <EmbeddedResource Include="FrmMain.resx">
@@ -560,6 +563,12 @@
    <Content Include="dlls\ogr_wrap.dll" />
    <Content Include="dlls\osr_csharp.dll" />
    <Content Include="dlls\osr_wrap.dll" />
    <EmbeddedResource Include="gdalconst_wrap.dll">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </EmbeddedResource>
    <EmbeddedResource Include="gdal_wrap.dll">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </EmbeddedResource>
    <EmbeddedResource Include="gdal-data\bag_template.xml">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </EmbeddedResource>
SimuTools/Tools/GdalHelper.cs
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,84 @@
using OSGeo.GDAL;
using OSGeo.OGR;
using OSGeo.OSR;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SimuTools.Tools
{
    public class GdalHelper
    {
        private static bool isInited;
        private static GdalHelper instance;
        private static readonly object obj = new object();
        public static SpatialReference sr4326 { set; get; }
        public static SpatialReference sr4490 { set; get; }
        /// <summary>
        /// æž„造函数
        /// </summary>
        private GdalHelper()
        {
            lock (obj)
            {
                if (!isInited)
                {
                    RegisterGDal();
                    sr4326 = new SpatialReference(null);
                    sr4326.ImportFromEPSG(4326);
                    sr4490 = new SpatialReference(null);
                    sr4490.ImportFromEPSG(4490);
                    isInited = true;
                }
            }
        }
        /// <summary>
        /// å®žä¾‹
        /// </summary>
        public static GdalHelper Instance
        {
            get
            {
                lock (obj)
                {
                    if (null == instance)
                    {
                        instance = new GdalHelper();
                    }
                    return instance;
                }
            }
        }
        /// <summary>
        /// æ³¨å†ŒGDAL
        /// </summary>
        public void RegisterGDal()
        {
            string gdalData = Path.Combine(Handle.BaseDir, "gdal-data");
            Environment.SetEnvironmentVariable("GDAL_DATA", gdalData);
            string proj7 = Path.Combine(Handle.BaseDir, "proj7\\share");
            Environment.SetEnvironmentVariable("PROJ_LIB", proj7);
            Gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "YES"); // NO,YES
            Gdal.SetConfigOption("SHAPE_ENCODING", ""); // ç©º,gb2312,CP936
            Ogr.RegisterAll();
            Gdal.AllRegister();
        }
    }
}
SimuTools/Tools/Handle.cs
@@ -9,6 +9,8 @@
{
    public class Handle
    {
        public static readonly string BaseDir = AppDomain.CurrentDomain.BaseDirectory;
        public static void Run(string terrainFile, string waterPath, string flowPath, string outPath)
        {
            //
SimuTools/gdal_wrap.dll
Binary files differ
SimuTools/gdalconst_wrap.dll
Binary files differ