| | |
| | | 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) |
| | |
| | | try |
| | | { |
| | | flag = true; |
| | | LogOut.Info("å¼å§è¿è¡ >>"); |
| | | LogOut.Info(">> å¼å§è¿è¡ >>"); |
| | | |
| | | Tools.Handle.Run(terrainFile, waterPath, flowPath, outPath); |
| | | LogOut.Info("è¿è¡ç»æ >>"); |
| | | |
| | | LogOut.Info("<< è¿è¡ç»æ <<"); |
| | | flag = false; |
| | | } |
| | | catch (Exception ex) |
| | |
| | | <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" /> |
| | |
| | | </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"> |
| | |
| | | <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> |
¶Ô±ÈÐÂÎļþ |
| | |
| | | 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(); |
| | | } |
| | | } |
| | | } |
| | |
| | | { |
| | | public class Handle |
| | | { |
| | | public static readonly string BaseDir = AppDomain.CurrentDomain.BaseDirectory; |
| | | |
| | | public static void Run(string terrainFile, string waterPath, string flowPath, string outPath) |
| | | { |
| | | // |