From de78cc06152f9954f62d74cf451358dcf817e655 Mon Sep 17 00:00:00 2001 From: 13693261870 <252740454@qq.com> Date: 星期三, 24 四月 2024 14:15:08 +0800 Subject: [PATCH] 加载shp + 读取shp --- TEWin/FrmWin.cs | 85 ++++++++++++++++++++++++++++++++++++++---- TEWin/app.config | 1 TEWin/FrmTool.cs | 6 ++ 3 files changed, 83 insertions(+), 9 deletions(-) diff --git a/TEWin/FrmTool.cs b/TEWin/FrmTool.cs index 2fcf483..39244bc 100644 --- a/TEWin/FrmTool.cs +++ b/TEWin/FrmTool.cs @@ -13,7 +13,11 @@ { FrmWin win; - List<string> codes = new List<string> { "閲嶇疆榧犳爣", "鎵撳紑鏂规", "淇濆瓨鏂规", "鐭㈤噺鏁版嵁", "褰卞儚鏁版嵁", "鍦板舰鏁版嵁", "妯″瀷鏁版嵁(osgb)", "妯″瀷鏁版嵁(obj)", "缂栬緫鏁版嵁", "鐐归噺绠�", "鍧″悜鍒嗘瀽", "绾块噺绠�", "闈㈤噺绠�", "浣撻噺绠�", "瑙掗噺绠�", "绌洪棿缁熻", "绌洪棿鍒嗘瀽", "鍓栭潰鍒嗘瀽", "鍧″害鍒嗘瀽", "绛夊�肩嚎", "鍓栧垏鍒嗘瀽", "鍦扮悊鍦烘櫙浜у搧缁勮", "浼犵粺4D浜у搧娲剧敓", "鎵撳紑fly", "鍔犺浇shp" }; + List<string> codes = new List<string> { "閲嶇疆榧犳爣", "鎵撳紑鏂规", "淇濆瓨鏂规", "鐭㈤噺鏁版嵁", + "褰卞儚鏁版嵁", "鍦板舰鏁版嵁", "妯″瀷鏁版嵁(osgb)", "妯″瀷鏁版嵁(obj)", "缂栬緫鏁版嵁", "鐐归噺绠�", + "鍧″悜鍒嗘瀽", "绾块噺绠�", "闈㈤噺绠�", "浣撻噺绠�", "瑙掗噺绠�", "绌洪棿缁熻", "绌洪棿鍒嗘瀽", + "鍓栭潰鍒嗘瀽", "鍧″害鍒嗘瀽", "绛夊�肩嚎", "鍓栧垏鍒嗘瀽", "鍦扮悊鍦烘櫙浜у搧缁勮", "浼犵粺4D浜у搧娲剧敓", + "鎵撳紑fly", "鍔犺浇shp", "璇诲彇shp" }; public FrmTool(FrmWin win) { diff --git a/TEWin/FrmWin.cs b/TEWin/FrmWin.cs index 9757f88..4ea0d93 100644 --- a/TEWin/FrmWin.cs +++ b/TEWin/FrmWin.cs @@ -182,6 +182,8 @@ SG.Open(this.fly); break; case 0xd8: // 鍔犺浇shp LoadShp(); break; + case 0xd9: // 璇诲彇shp + ReadShp(); break; } } @@ -497,6 +499,7 @@ RunExe(GetAbsolutePath("osgblabPath"), null, false); } + #region 鍔犺浇shp + 璇诲彇shp private void LoadShp() { OpenFileDialog dialog = new OpenFileDialog(); @@ -505,20 +508,33 @@ if (dialog.ShowDialog() == DialogResult.OK) { - LoadShp(dialog.FileName); + string shpFile = dialog.FileName; + if (LoadShp(shpFile)) + { + sendShpFile(shpFile); + } } } - private void LoadShp(string shpFile) + private bool LoadShp(string shpFile) { - string gid = GetGroupIdByName(shpGroupName); - string conn = "FileName=" + shpFile + ";TEPlugName=OGR;"; // 杩炴帴瀛楃涓� - string shpName = Path.GetFileNameWithoutExtension(shpFile); + try + { + string gid = GetGroupIdByName(shpGroupName); + string conn = "FileName=" + shpFile + ";TEPlugName=OGR;"; // 杩炴帴瀛楃涓� + string shpName = Path.GetFileNameWithoutExtension(shpFile); - IFeatureLayer71 layer = SG.Creator.CreateFeatureLayer(shpName, conn, gid); // 鍔犺浇shp - layer.Refresh(); + IFeatureLayer71 layer = SG.Creator.CreateFeatureLayer(shpName, conn, gid); // 鍔犺浇shp + layer.Refresh(); + SG.Navigate.FlyTo(layer.ID); - SG.Navigate.FlyTo(layer.ID); + return true; + } + catch (Exception ex) + { + LogOut.Error(ex.Message + "\r\n" + ex.StackTrace); + return false; + } } private string GetGroupIdByName(string groupName) @@ -531,5 +547,58 @@ return gid; } + + private void sendShpFile(string shpFile) + { + try + { + string shpTxtPath = GetShpTxtPath(); + using (StreamWriter sw = new StreamWriter(shpTxtPath, false)) + { + sw.Write(shpFile.Replace("\\", "/")); + } + } + catch (Exception ex) + { + LogOut.Error(ex.Message + "\r\n" + ex.StackTrace); + } + } + + private void ReadShp() + { + try + { + string shpTxtPath = GetShpTxtPath(); + if (string.IsNullOrEmpty(shpTxtPath) || !File.Exists(shpTxtPath)) + { + return; + } + + string shpFile = File.ReadAllText(shpTxtPath); + if (string.IsNullOrEmpty(shpFile) || !shpFile.ToLower().EndsWith(".shp") || !File.Exists(shpFile)) + { + return; + } + + LoadShp(shpFile); + File.Delete(shpTxtPath); + } + catch (Exception ex) + { + LogOut.Error(ex.Message + "\r\n" + ex.StackTrace); + } + } + + private string GetShpTxtPath() + { + string shpTxtPath = ConfigurationManager.AppSettings["shpTxtPath"]; + if (!shpTxtPath.Contains(":\\")) + { + shpTxtPath = Path.Combine(Application.StartupPath, shpTxtPath); + } + + return shpTxtPath; + } + #endregion } } diff --git a/TEWin/app.config b/TEWin/app.config index 0403c18..e6eaaca 100644 --- a/TEWin/app.config +++ b/TEWin/app.config @@ -8,6 +8,7 @@ <add key="tePath" value="C:\Program Files\SmartEarth\TerraExplorer Pro"/> <!--<add key="osgblabPath" value="C:\Program Files\OSGBLab\Trial\OSGBLab.exe"/>--> <add key="osgblabPath" value="OSGBLab\Trial\OSGBLab.exe"/> + <add key="shpTxtPath" value="shp.txt"/> </appSettings> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/> -- Gitblit v1.9.3