| | |
| | | { |
| | | 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) |
| | | { |
| | |
| | | SG.Open(this.fly); break; |
| | | case 0xd8: // 加载shp |
| | | LoadShp(); break; |
| | | case 0xd9: // 读取shp |
| | | ReadShp(); break; |
| | | } |
| | | } |
| | | |
| | |
| | | RunExe(GetAbsolutePath("osgblabPath"), null, false); |
| | | } |
| | | |
| | | #region 加载shp + 读取shp |
| | | private void LoadShp() |
| | | { |
| | | OpenFileDialog dialog = new OpenFileDialog(); |
| | |
| | | |
| | | 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) |
| | |
| | | |
| | | 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 |
| | | } |
| | | } |
| | |
| | | <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"/> |