private void button1_Click(object sender, EventArgs e) { string s1 = textBox1.Text; string s2 = textBox2.Text; string s3 = textBox3.Text; string s4 = textBox4.Text; string mes = String.Empty; IPosition61 cpos = null; ITerrain3DRegBase61 drill = null; try { double dxcoord = double.Parse(s1); double dycoord = double.Parse(s2); double altitude = double.Parse(s3); AltitudeTypeCode ealit = AltitudeTypeCode.ATC_TERRAIN_RELATIVE; cpos = MainForm.sgworld.Creator.CreatePosition(dxcoord, dycoord, altitude, ealit, -90, -30, 180, 1000); { drill = MainForm.sgworld.Creator.CreateCone(cpos, 10, 50, nrgb, nrgb, -1, 0, s4); MainForm.sgworld.Navigate.FlyTo(cpos, ActionCode.AC_FLYTO); } } catch (Exception ex) { mes = String.Format("CreateLabelButton_Click Exception :{0}", ex.Message); Log4NetHelper.WriteLog(typeof(AdddrillForm), ex); MessageBox.Show(mes); } }
private void button1_Click(object sender, EventArgs e) { string path = textBox5.Text; string s1 = textBox1.Text; string s2 = textBox2.Text; string s3 = textBox3.Text; string s4 = textBox4.Text; string mes = String.Empty; IPosition61 dztpos = null; TECoClass = new TerraExplorerClass(); ITerraExplorer = (ITerraExplorer5)TECoClass; IInfoTree = (IInformationTree5)TECoClass; IObjectManager = (IObjectManager5)TECoClass; try { double dxcoord = double.Parse(s1); double dycoord = double.Parse(s2); double altitude = double.Parse(s3); AltitudeTypeCode ealit = AltitudeTypeCode.ATC_TERRAIN_RELATIVE; dztpos = MainForm.sgworld.Creator.CreatePosition(dxcoord, dycoord, altitude, ealit, 0, 90, 100.0, 1000); dzt = MainForm.sgworld.Creator.CreateModel(dztpos, path, 1, ModelTypeCode.MT_NORMAL, 0, s4); } catch (Exception ex) { mes = String.Format("CreateLabelButton_Click Exception :{0}", ex.Message); Log4NetHelper.WriteLog(typeof(AddgeologicbodyForm), ex); MessageBox.Show(mes); } }
private void gridView1_DoubleClick(object sender, EventArgs e) { try { if (this.TYPE == 0 && this.gridView1.RowCount != 0) { string FID = this.gridView1.GetFocusedRowCellValue("OBJECTID").ToString(); IQueryFilter pQuery = new QueryFilterClass(); pQuery.WhereClause = ModelID + " = " + FID; IFeatureCursor featureCursor = this.tFeatureClass.Search(pQuery, true); IFeature esriFeature = featureCursor.NextFeature(); ESRI.ArcGIS.Geometry.IPoint pPoint = esriFeature.Shape as ESRI.ArcGIS.Geometry.IPoint; IPosition61 _Position6 = Program.pCreator6.CreatePosition(pPoint.X, pPoint.Y, 100, AltitudeTypeCode.ATC_TERRAIN_RELATIVE, 0, -89, 0, 100); Program.pNavigate6.FlyTo(_Position6, ActionCode.AC_FLYTO); //var x = this.gridView1.GetFocusedRowCellValue("CX"); //var y = this.gridView1.GetFocusedRowCellValue("CY"); //ActionClass.Vertical3DFlyTo(Convert.ToDouble(x), Convert.ToDouble(y),-89,100); } else if (this.TYPE == 1 && this.gridView1.RowCount != 0) { var Longitude = this.gridView1.GetFocusedRowCellValue("CX"); var Latitude = this.gridView1.GetFocusedRowCellValue("CY"); IPosition61 _Position6 = Program.pCreator6.CreatePosition(Convert.ToDouble(Longitude), Convert.ToDouble(Latitude), 100, AltitudeTypeCode.ATC_TERRAIN_RELATIVE, 0, -89, 0, 820); Program.pNavigate6.FlyTo(_Position6, ActionCode.AC_FLYTO); } } catch (Exception ex) { // throw; } }
void m_TerraExplorer_OnLButtonDown(int Flags, int X, int Y, ref object pbHandled) { object x, y, z, oid; m_TerraExplorer.ScreenToWorld(X, Y, ref pbHandled, out x, out z, out y, out oid); double[] array = new double[] { (double)x, (double)y, 2 }; IPosition61 p = m_SGWorld.Creator.CreatePosition((double)x, (double)y, 2);//, AltitudeTypeCode.ATC_TERRAIN_RELATIVE,0,0,0,0); ITerrainImageLabel61 lbl = m_SGWorld.Creator.CreateImageLabel(p, ConfigurationManager.AppSettings["LabelModelFile"]); if (m_Flag == 1) { m_FromPoint = array; lblFromPoint.Text = "已选择"; lblFromPoint.ForeColor = Color.Green; m_From = lbl; } else { m_ToPoint = array; lblToPoint.Text = "已选择"; lblToPoint.ForeColor = Color.Green; m_To = lbl; } m_TerraExplorer.OnLButtonDown -= new _ITerraExplorerEvents5_OnLButtonDownEventHandler(m_TerraExplorer_OnLButtonDown); }
void OnProjectLoadFinished() { IPosition61 beijing = sgworld.Creator.CreatePosition(116.216667, 39.775111, 15000, AltitudeTypeCode.ATC_TERRAIN_RELATIVE, -60, -60, 0, 0); sgworld.Navigate.JumpTo(beijing); //不加载天地图 IInfoTree.SetVisibility(0, 0); }
public override void OnClick() { IPosition61 CurrentPos = Program.pNavigate6.GetPosition(AltitudeTypeCode.ATC_TERRAIN_RELATIVE); CurrentPos.Altitude = 2; CurrentPos.Distance = 0; CurrentPos.Pitch = 0; CurrentPos.Roll = 0; Program.pNavigate6.SetPosition(CurrentPos); }
private void 地下场景显示ToolStripMenuItem1_Click(object sender, EventArgs e) { //启用地下模式 sgworld.Command.Execute(1027, 0); //获取中心坐标 IPosition61 center = sgworld.Window.CenterPixelToWorld().Position; //设置视角 sgworld.Navigate.SetPosition(center); }
//左键单击 bool sgworld_OnLButtonDown(int Flags, int X, int Y) { try { if (pbhander == "modify") { LClickCount++; //点击三个点以前画线,三个点以后画面 double longitude, latitude, height; (this.TerraExplorer as IRender5).ScreenToTerrain(X, Y, out longitude, out latitude, out height); IPosition61 pIPosition = this.SgWorld.Navigate.GetPosition(AltitudeTypeCode.ATC_TERRAIN_RELATIVE); if (LClickCount < 3) { this.pITerrainPolyline.AddVertex(longitude, height, latitude, 0); ListVerticsArray.Add(longitude); ListVerticsArray.Add(latitude); ListVerticsArray.Add(pIPosition.Distance); } else { if (LClickCount == 3) { ListVerticsArray.Add(longitude); ListVerticsArray.Add(latitude); ListVerticsArray.Add(pIPosition.Distance); double[] tripletArray = new double[ListVerticsArray.Count]; ListVerticsArray.CopyTo(tripletArray, 0); IColor61 LineColor = this.SgWorld.Creator.CreateColor(Color.Red.R, Color.Red.G, Color.Red.B, Color.Red.A); IColor61 FillColor = this.SgWorld.Creator.CreateColor(Color.Red.R, Color.Red.G, Color.Red.B, 0); AltitudeTypeCode eAltitudeTypeCode = AltitudeTypeCode.ATC_TERRAIN_RELATIVE; pITerrainPolygon = this.SgWorld.Creator.CreatePolygonFromArray(tripletArray, LineColor, FillColor, eAltitudeTypeCode, GroupID, "TempPolygon"); this.SgWorld.ProjectTree.DeleteItem(this.pITerrainPolyline.InfoTreeItemID); } else { if (pITerrainPolygon != null) { IPolygon pPolygon = pITerrainPolygon.Geometry as IPolygon; pPolygon.StartEdit(); foreach (ILinearRing r in pPolygon.Rings) { r.Points.AddPoint(longitude, latitude, pIPosition.Distance); } pITerrainPolygon.Geometry = pPolygon.EndEdit(); } } } } } catch { MessageBox.Show("地形调整范围绘制失败!"); } return(true); }
private void gridView1_DoubleClick(object sender, EventArgs e) { try { string FID = this.gridView1.GetFocusedRowCellValue("OBJECTID").ToString(); IQueryFilter pQuery = new QueryFilterClass(); pQuery.WhereClause = String.Format("{0} = {1}", this.ModelID, FID); IFeatureCursor featureCursor = this.tFeatureClass.Search(pQuery, true); IFeature esriFeature = featureCursor.NextFeature(); ESRI.ArcGIS.Geometry.IPoint pPoint = esriFeature.Shape as ESRI.ArcGIS.Geometry.IPoint; IPosition61 _Position6 = Program.pCreator6.CreatePosition(pPoint.X, pPoint.Y, 100, AltitudeTypeCode.ATC_TERRAIN_RELATIVE, 0, -89, 0, 100); Program.pNavigate6.FlyTo(_Position6, ActionCode.AC_FLYTO); //double x = 0; //double y = 0; //try //{ // x = Convert.ToDouble(this.gridView1.GetFocusedRowCellDisplayText(gridColumn8)); // y = Convert.ToDouble(this.gridView1.GetFocusedRowCellDisplayText(gridColumn9)); //} //catch (Exception ex) //{ // MessageBox.Show("缺失坐标信息!","警告",MessageBoxButtons.OK,MessageBoxIcon.Warning); //} //int FeatureCount = pf.Count; //int FCount = this.pf.Count; //IFeature61 pfeature = null; //for (int i = 0; i < FCount; i++) //{ // pfeature = this.pf[i] as IFeature61; // string fid = pfeature.FeatureAttributes.GetFeatureAttribute("FID").Value.ToString(); // if (fid==FID) // { // break; // } // pfeature = null; //} //if (pfeature!=null) //{ // Program.sgworld.Navigate.FlyTo(pfeature, ActionCode.AC_FLYTO); //} // this.ShowBuilderInfo(ObjectID.ToString()); // this.xtraTabControl1.SelectedTabPageIndex = 1; } catch (Exception ex) { // throw; } }
private void button1_Click(object sender, EventArgs e) { string s1 = textBox1.Text; string s2 = textBox2.Text; string s3 = textBox3.Text; string s4 = textBox4.Text; string s5 = textBox4.Text + "\r\n" + textBox5.Text; string mes = String.Empty; IPosition61 cpos = null; ILabelStyle61 clabelstyle = null; ITerrainLabel61 ctextlabel = null; try { double dxcoord = double.Parse(s1); double dycoord = double.Parse(s2); double altitude = double.Parse(s3); AltitudeTypeCode ealit = AltitudeTypeCode.ATC_TERRAIN_RELATIVE; cpos = MainForm.sgworld.Creator.CreatePosition(dxcoord, dycoord, altitude, ealit, -30, -30, 0.0, 10000); { SGLabelStyle elabelstyle = SGLabelStyle.LS_DEFAULT; clabelstyle = MainForm.sgworld.Creator.CreateLabelStyle(elabelstyle); { double alpha = 0.5; IColor61 cbackground = clabelstyle.BackgroundColor; cbackground.FromBGRColor(nrgb); cbackground.SetAlpha(alpha); clabelstyle.FontName = "Arial"; clabelstyle.FontSize = 50; clabelstyle.TextColor.FromABGRColor(nrgb); clabelstyle.Italic = true; clabelstyle.Scale = 3; ctextlabel = MainForm.sgworld.Creator.CreateTextLabel(cpos, s5, clabelstyle, 0, s4); IPosition61 cflypos = cpos.Copy(); cflypos.Pitch = -30.0; MainForm.sgworld.Navigate.FlyTo(cflypos, ActionCode.AC_FLYTO); } } } catch (Exception ex) { mes = String.Format("CreateLabelButton_Click Exception :{0}", ex.Message); Log4NetHelper.WriteLog(typeof(LabelForm), ex); MessageBox.Show(mes); } }
private void FrmSetPlaneParam_Load(object sender, EventArgs e) { //this.comboBoxEdit2.SelectedIndex = 0; //this.comboBoxEdit3.SelectedIndex = 0; try { //相对高度 _Position61 = dynamicObj.Position; pRouteWaypoints61 = dynamicObj.Waypoints;//路点 IRouteWaypoint61 pRouteWaypoint = this.pRouteWaypoints61[0] as IRouteWaypoint61; spinEdit2.Value = Convert.ToDecimal(pRouteWaypoint.Speed); spinEdit1.Value = Convert.ToDecimal(dynamicObj.TurnSpeed); this.spinEdit4.Value = Convert.ToDecimal(pRouteWaypoint.Altitude); if (this.dynamicObj.DynamicType == DynamicObjectType.DYNAMIC_VIRTUAL) { this.comboBoxEdit2.SelectedIndex = 0; this.Model = false; comboBoxEdit3.Enabled = false; } else { this.comboBoxEdit2.SelectedIndex = 1; this.Model = true; comboBoxEdit3.Enabled = true; } if (this.dynamicObj.MotionStyle == DynamicMotionStyle.MOTION_AIRPLANE) { this.comboBoxEdit3.SelectedIndex = 1; } else if (this.dynamicObj.MotionStyle == DynamicMotionStyle.MOTION_HELICOPTER) { this.comboBoxEdit3.SelectedIndex = 2; } else if (this.dynamicObj.MotionStyle == DynamicMotionStyle.MOTION_GROUND_VEHICLE) { this.comboBoxEdit3.SelectedIndex = 0; } } catch (Exception) { } }
private void tree_dataSet_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) { try { File3dattribute bo = (File3dattribute)e.Node.Tag; QueryFilter pQuery = new QueryFilterClass(); pQuery.WhereClause = ModelID + " = " + bo.Objectid.ToString(); IFeatureCursor featureCursor = this.tFeatureClass.Search(pQuery, true); IFeature esriFeature = featureCursor.NextFeature(); ESRI.ArcGIS.Geometry.IPoint pPoint = esriFeature.Shape as ESRI.ArcGIS.Geometry.IPoint; IPosition61 _Position6 = Program.pCreator6.CreatePosition(pPoint.X, pPoint.Y, 100, AltitudeTypeCode.ATC_TERRAIN_RELATIVE, 0, -89, 0, 100); Program.pNavigate6.FlyTo(_Position6, ActionCode.AC_FLYTO); } catch (Exception ex) { //throw; } }
void TerraExplorer_OnLButtonDown(int Flags, int X, int Y, ref object pbHandled) { try { IPosition61 _Position6 = this.m_SkylineHook.SGWorld.Window.PixelToWorld(X, Y, WorldPointType.WPT_ALL).Position; int GroupID = this.m_SkylineHook.SGWorld.ProjectTree.FindItem("粒子特效"); if (GroupID == 0) { GroupID = this.m_SkylineHook.SGWorld.ProjectTree.CreateGroup("粒子特效", 0); } this.m_SkylineHook.SGWorld.Creator.CreateImageLabel(_Position6, Application.StartupPath + "\\Particle\\" + m_GifName + ".gif", null, GroupID, m_Prefix + System.Guid.NewGuid().ToString().Substring(0, 6)); } catch { } finally { this.m_SkylineHook.TerraExplorer.OnLButtonDown -= new TerraExplorerX._ITerraExplorerEvents5_OnLButtonDownEventHandler(TerraExplorer_OnLButtonDown); } }
private void FlyToTeePoint_Click(object sender, EventArgs e) { if (textBox1.Text == "" || textBox2.Text == "") { MessageBox.Show("请输入坐标!"); return; } double x; double y; if (Double.TryParse(textBox1.Text, out x) && Double.TryParse(textBox2.Text, out y)) { IPosition61 position = this.m_Sgworld.Creator.CreatePosition(x, y, 1000, AltitudeTypeCode.ATC_TERRAIN_RELATIVE, 0, -89, 0, 1000); this.m_Sgworld.Navigate.FlyTo(position, ActionCode.AC_FLYTO); } else { MessageBox.Show("请输入正确格式!"); } // creatpoint }
void m_Hook_OnLButtonDown(int Flags, int X, int Y, ref object pbHandled) { try { object obj1, obj2, obj3; this.m_TerraExplorer.GetMouseInfo(out obj1, out obj2, out obj3); double longitude, latitude, height; this.m_TerraExplorer.ScreenToTerrain(X, Y, out longitude, out latitude, out height); IPosition61 position = m_Hook.Creator.CreatePosition(longitude, latitude, 0, AltitudeTypeCode.ATC_PIVOT_RELATIVE); int tempGroup = this.m_Hook.ProjectTree.FindItem(m_TempGroupName); if (tempGroup > -1) { this.m_Hook.ProjectTree.DeleteItem(tempGroup); } tempGroup = this.m_Hook.ProjectTree.CreateGroup(m_TempGroupName); this.m_Model = this.m_Hook.Creator.CreateModel(position, ConfigurationManager.AppSettings["LampModelFile"], 1, ModelTypeCode.MT_NORMAL, tempGroup, m_TempModelName); if (cbAuto.Checked) { LampAnalysis(); } pbHandled = true; m_Flag = false; } catch { MessageBox.Show("您当前的配置不能完成此操作,请修改配置!"); } finally { this.m_TerraExplorer.OnLButtonDown -= new TerraExplorerX._ITerraExplorerEvents5_OnLButtonDownEventHandler(m_Hook_OnLButtonDown); } }
private void InsertValueAndGetPos2(string FieldName)//位置和要素要同时获取,否则值和位置可能不对应 { //try //{ if (fatherform.MFGridView2 != null) { //添加列 if (fatherform.MFGridView2.ColumnCount == 0) { if (TitleField == "") { fatherform.MFGridView2.Columns.Add("FeatureID", "FeatureID"); } else { fatherform.MFGridView2.Columns.Add(TitleField, TitleField); } fatherform.MFGridView2.Columns.Add(FieldName, FieldName); } else { fatherform.MFGridView2.Columns.Add(FieldName, FieldName); } //添加值 ILayer61 SlctdLyr = Program.sgworld.ProjectTree.GetLayer(LayerID); string[] ExtractFile = SlctdLyr.DataSourceInfo.ConnectionString.Split(';'); string FilePath = ExtractFile[0].Substring(9); IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactoryClass(); IFeatureWorkspace pFeatureWorkspace = (IFeatureWorkspace)pWorkspaceFactory.OpenFromFile(System.IO.Path.GetDirectoryName(FilePath), 0); IFeatureClass pFeatureClass = (IFeatureClass)pFeatureWorkspace.OpenFeatureClass(System.IO.Path.GetFileName(FilePath)); bool ReProjectOrNot = false; //标记是否需要重投影 string LayerCord = SlctdLyr.CoordinateSystem.WktDescription; string TerrainCord = Program.sgworld.Terrain.CoordinateSystem.WktDescription; if (LayerCord != TerrainCord) { ReProjectOrNot = true; } string AValue = ""; IPosition61 cPos = null; List <IPosition61> Positions = new List <IPosition61>(); double dXCoord; double dYCoord; double dAltitude = 0; AltitudeTypeCode eAltitudeTypeCode = AltitudeTypeCode.ATC_ON_TERRAIN; double dYaw = 0.0; double dPitch = 0.0; double dRoll = 0.0; double dDistance = 20000; for (int i = 0; i < pFeatureClass.FeatureCount(null); i++) { //插入值 AValue = pFeatureClass.GetFeature(i).get_Value(pFeatureClass.FindField(FieldName)).ToString(); if (fatherform.MFGridView2.ColumnCount == 2) { if (fatherform.MFGridView2.Columns[0].Name == "FeatureID") { this.fatherform.MFGridView2.Rows.Add(pFeatureClass.GetFeature(i).OID, AValue); } else { this.fatherform.MFGridView2.Rows.Add(pFeatureClass.GetFeature(i).get_Value(pFeatureClass.FindField(TitleField)).ToString(), AValue); } } else { if (this.fatherform.MFGridView2.RowCount > 0) { fatherform.MFGridView2.Rows[i].Cells[FieldName].Value = AValue; } } //获取位置 ESRI.ArcGIS.Geometry.IGeometry pGeometry = pFeatureClass.GetFeature(i).Shape; if (ReProjectOrNot) { ESRI.ArcGIS.Geometry.ISpatialReferenceFactory srFactory = new ESRI.ArcGIS.Geometry.SpatialReferenceEnvironmentClass(); ESRI.ArcGIS.Geometry.IGeographicCoordinateSystem gcs = srFactory.CreateGeographicCoordinateSystem((int)ESRI.ArcGIS.Geometry.esriSRGeoCSType.esriSRGeoCS_WGS1984); ESRI.ArcGIS.Geometry.ISpatialReference sr1 = gcs; pGeometry.Project(sr1); } ESRI.ArcGIS.Geometry.IPoint pPoint = null; switch (pFeatureClass.ShapeType) { case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint: pPoint = (ESRI.ArcGIS.Geometry.IPoint)pGeometry; break; case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline: pPoint = ((ESRI.ArcGIS.Geometry.IPolyline)pGeometry).ToPoint; break; case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon: pPoint = ((ESRI.ArcGIS.Geometry.IArea)(ESRI.ArcGIS.Geometry.IPolygon) pGeometry).Centroid; break; default: break; } dXCoord = pPoint.X; dYCoord = pPoint.Y; cPos = Program.sgworld.Creator.CreatePosition(dXCoord, dYCoord, dAltitude, eAltitudeTypeCode, dYaw, dPitch, dRoll, dDistance); Positions.Add(cPos); } if (Positions != null) { fatherform.StaThemePos = Positions; } } //} //catch (Exception ex) //{ // MessageBox.Show("Unexpected Error:" + ex.Message); //} /***20130227杨漾(去掉trycatch,抛给上层trycatch处理异常)****/ }
bool m_EventHook_OnLButtonUp(int Flags, int X, int Y) { double longitude, latitude, height; this.m_TerraExplorer.ScreenToTerrain(X, Y, out longitude, out latitude, out height); double viewerHeight = (double)speViewer.Value; if (m_Root == null) { m_RootX = longitude; m_RootY = latitude; double[] points = { longitude, latitude, 0, longitude, latitude, viewerHeight }; ILineString geoLine = m_Hook.Creator.GeometryCreator.CreateLineStringGeometry(points); // 创建Root m_Root = m_Hook.Creator.CreatePolyline(geoLine as IGeometry, 0xFF00ffff, AltitudeTypeCode.ATC_TERRAIN_RELATIVE, m_GroupID, m_RootName); m_Root.ExtendToGround = true; m_Root.SaveInFlyFile = false; } else { try { // 创建视域分析 double dis = this.m_TerraExplorer.ICoordSys3_GetDistance(m_RootX, m_RootY, longitude, latitude); //Math.Sqrt((latitude - m_RootY) * (latitude - m_RootY) + (longitude - m_RootX) * (longitude - m_RootX)); //if (dis < 0.1) // 防止除以0 // dis = 0.1; if (dis <= viewerHeight)// 操他妈的必须大于视点高 { dis = viewerHeight + 0.01; } double rawArc = Math.Atan2(latitude - m_RootY, longitude - m_RootX); rawArc = 180 * rawArc / Math.PI; //double rawArc = Math.Asin((latitude - m_RootY) / dis);//(longitude - m_RootX)); //rawArc = 180 * rawArc / Math.PI; //if (longitude < m_RootX) // rawArc = 180 - rawArc; // skyline中视域分析角度与数学角度转换 rawArc = rawArc - 90; double disViewshed = dis; disViewshed = Math.Sqrt(disViewshed * disViewshed - viewerHeight * viewerHeight); IPosition61 pMouse = m_Hook.Creator.CreatePosition(m_RootX, m_RootY, viewerHeight, AltitudeTypeCode.ATC_TERRAIN_RELATIVE, rawArc, 0, 0, disViewshed); int index = 1; while (true) { if (m_Hook.ProjectTree.FindItem(string.Format("视域分析\\视域分析{0}", index)) > 0) { index++; } else { break; } } string strViewshed = string.Format("视域分析{0}", index); int viewshedID = m_Hook.Analysis.CreateViewshed(pMouse, (double)speField.Value, (double)speSample.Value, (double)speRay.Value, (double)speTarget.Value, null, null, m_GroupID, strViewshed); if (viewshedID <= 0) { MessageBox.Show("分析出现了错误"); return(false); } // 修改视域分析结果 string viewshedFull = string.Format("视域分析\\视域分析{0}", index); // 删掉Root m_Hook.ProjectTree.DeleteItem(m_Root.TreeItem.ItemID); m_Root = null; // 换掉Left,Right,Arc int leftRay = m_Hook.ProjectTree.FindItem(string.Format("{0}\\{1}", viewshedFull, m_LeftRayName)); if (leftRay > 0) { m_Hook.ProjectTree.DeleteItem(leftRay); } int rightRay = m_Hook.ProjectTree.FindItem(string.Format("{0}\\{1}", viewshedFull, m_RightRayName)); if (rightRay > 0) { m_Hook.ProjectTree.DeleteItem(rightRay); } int arc = m_Hook.ProjectTree.FindItem(string.Format("{0}\\{1}", viewshedFull, m_ArcName)); if (arc > 0) { m_Hook.ProjectTree.DeleteItem(arc); } m_Hook.ProjectTree.SetParent(m_LeftRay.TreeItem.ItemID, viewshedID); m_Hook.ProjectTree.SetParent(m_RightRay.TreeItem.ItemID, viewshedID); m_Hook.ProjectTree.SetParent(m_Arc.TreeItem.ItemID, viewshedID); // Visible和InVisible修改高度方式和高度 int vID = m_Hook.ProjectTree.FindItem(string.Format("{0}\\{1}", viewshedFull, m_VisibleArea)); int invID = m_Hook.ProjectTree.FindItem(string.Format("{0}\\{1}", viewshedFull, m_InvisibleArea)); if (vID > 0 && invID > 0) { object[] objAreas = { m_Hook.ProjectTree.GetObject(vID), m_Hook.ProjectTree.GetObject(invID) }; foreach (object objArea in objAreas) { ITerrainPolygon61 polygon = objArea as ITerrainPolygon61; polygon.Position.AltitudeType = AltitudeTypeCode.ATC_TERRAIN_RELATIVE; polygon.Position.Altitude = (double)speTarget.Value; } } m_LeftRay = null; m_RightRay = null; m_Arc = null; this.Close(); } catch { MessageBox.Show("很抱歉,分析过程出现错误"); } } return(false); }
void m_ControlHook_MouseMove(object sender, MouseEventArgs e) { // 若Root还没有建立,则返回 if (m_Root == null) { return; } double viewerHeight = (double)speViewer.Value; double longitude, latitude, height; this.m_TerraExplorer.ScreenToTerrain(e.X, e.Y, out longitude, out latitude, out height); // Arc double rArc = this.m_TerraExplorer.ICoordSys3_GetDistance(m_RootX, m_RootY, longitude, latitude); //Math.Sqrt((latitude - m_RootY) * (latitude - m_RootY) + (longitude - m_RootX) * (longitude - m_RootX)); //if (rArc < 0.1) // 防止除以0 // rArc = 0.1; if (rArc <= viewerHeight) // 操他妈的必须大于视点高 { rArc = viewerHeight + 0.01; } else { // 计算左右斜线时要使用图上距离 disInMap = Math.Sqrt((latitude - m_RootY) * (latitude - m_RootY) + (longitude - m_RootX) * (longitude - m_RootX)); } //double degree = Math.Asin((latitude - m_RootY) / rArc); //degree = 180 * degree / Math.PI; //if (longitude < m_RootX) // degree = 180 - degree; double degree = Math.Atan2(latitude - m_RootY, longitude - m_RootX); degree = 180 * degree / Math.PI; // skyline中角度与数学角度转换 double rawArc = degree - 90; rawArc = 360 - rawArc; // 顺时针方向 txtDistance.Text = Math.Sqrt(rArc * rArc - viewerHeight * viewerHeight).ToString(); IPosition61 pMouse = m_Hook.Creator.CreatePosition(longitude, latitude, (double)speTarget.Value, AltitudeTypeCode.ATC_TERRAIN_RELATIVE);//, rawArc); double fieldOffset = (double)speField.Value / 2.0; double degreeLeft = (degree - fieldOffset) * Math.PI / 180; double degreeRight = (degree + fieldOffset) * Math.PI / 180; double[] pointsLeft = { m_RootX, m_RootY, viewerHeight, m_RootX + disInMap * Math.Cos(degreeLeft), m_RootY + disInMap * Math.Sin(degreeLeft), (double)speTarget.Value }; double[] pointsRight = { m_RootX, m_RootY, viewerHeight, m_RootX + disInMap * Math.Cos(degreeRight), m_RootY + disInMap * Math.Sin(degreeRight), (double)speTarget.Value }; IGeometry geoLeft = m_Hook.Creator.GeometryCreator.CreateLineStringGeometry(pointsLeft) as IGeometry; IGeometry geoRight = m_Hook.Creator.GeometryCreator.CreateLineStringGeometry(pointsRight) as IGeometry; // 若左右射线和Arc没建立,则建立 if (m_Arc == null) { // 创建Left,Right,Arc // Left m_LeftRay = m_Hook.Creator.CreatePolyline(geoLeft as IGeometry, 0xFF00ffff, AltitudeTypeCode.ATC_TERRAIN_RELATIVE, m_GroupID, m_LeftRayName); // Right m_RightRay = m_Hook.Creator.CreatePolyline(geoRight as IGeometry, 0xFF00ffff, AltitudeTypeCode.ATC_TERRAIN_RELATIVE, m_GroupID, m_RightRayName); // Arc m_Arc = m_Hook.Creator.CreateArc(pMouse, rArc, rArc, rawArc - fieldOffset, rawArc + fieldOffset, 0xff00ffff, 0x00000000, 12, m_GroupID, m_ArcName); m_Arc.SaveInFlyFile = false; } // 否则动态改变 else { // Left m_LeftRay.Geometry = geoLeft; // Right m_RightRay.Geometry = geoRight; // Arc m_Arc.Radius = rArc; m_Arc.Radius2 = rArc; m_Arc.StartAngle = rawArc - fieldOffset; m_Arc.EndAngle = rawArc + fieldOffset; } }
bool sgworld_OnLButtonDown(int Flags, int X, int Y) { if (pbhander == "modify") { LClickCount++; IWorldPointInfo61 pIWPInfo = this.SgWorld.Window.PixelToWorld(X, Y, WorldPointType.WPT_TERRAIN); IPosition61 pIPosition = this.SgWorld.Navigate.GetPosition(AltitudeTypeCode.ATC_TERRAIN_RELATIVE); if (pITerrainPolygon == null) { try { ILinearRing cRing = null; double[] cVerticesArray = null; cVerticesArray = new double[] { pIPosition.X, pIPosition.Y, 0, pIWPInfo.Position.X, pIWPInfo.Position.Y, 0, pIWPInfo.Position.X, pIWPInfo.Position.Y, 0, }; cRing = this.SgWorld.Creator.GeometryCreator.CreateLinearRingGeometry(cVerticesArray); uint nLineColor = 0xFF00FF00; uint nFillColor = 0x7FFF0000; AltitudeTypeCode eAltitudeTypeCode = AltitudeTypeCode.ATC_TERRAIN_RELATIVE; pITerrainPolygon = this.SgWorld.Creator.CreatePolygon(cRing, nLineColor, nFillColor, eAltitudeTypeCode, 0, "Polygon"); IPolygon polygonGeometry = pITerrainPolygon.Geometry as IPolygon; polygonGeometry.StartEdit(); foreach (ILinearRing ring in polygonGeometry.Rings) { double dx = pIWPInfo.Position.X; double dy = pIWPInfo.Position.Y; double dh = pIWPInfo.Position.Distance; ring.Points.AddPoint(dx, dy, dh); ring.Points.DeletePoint(0); } IGeometry editedGeometry = polygonGeometry.EndEdit(); pITerrainPolygon.Geometry = editedGeometry; } catch (Exception) { } } else { try { IPolygon polygonGeometry = pITerrainPolygon.Geometry as IPolygon; polygonGeometry.StartEdit(); foreach (ILinearRing ring in polygonGeometry.Rings) { double dx = pIWPInfo.Position.X; double dy = pIWPInfo.Position.Y; double dh = pIWPInfo.Position.Distance; ring.Points.AddPoint(dx, dy, dh); } IGeometry editedGeometry = polygonGeometry.EndEdit(); pITerrainPolygon.Geometry = editedGeometry; } catch (Exception) { } } } return(false); }
private void LampAnalysis() { try { if (m_Model == null) { MessageBox.Show("请先安放信号灯!"); return; } this.txtResult.Clear(); Application.DoEvents(); SendMessage("正在获取路口信息..."); string lyr = ConfigurationManager.AppSettings["CrossLayer"]; int lyrID = m_Hook.ProjectTree.FindItem(lyr); if (lyrID < 0) { MessageBox.Show("您的配置有问题或者路口图层没有加载"); return; } ILayer61 teLayer = m_Hook.ProjectTree.GetLayer(lyrID); if (teLayer == null) { return; } //IFeature61 tefCurrent = teLayer.FeatureGroups.Point[0] as IFeature61; // 严格来说要根据所点的位置来确定是哪个路口 // 取第一个作为路口信息 // 先直接从数据库中读取,模拟计算 string strOld = teLayer.DataSourceInfo.ConnectionString; string[] strs = strOld.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); strOld = strs[0]; strOld = strOld.Substring(strOld.IndexOf("=") + 1); string strFolder = System.IO.Path.GetDirectoryName(strOld); string strName = System.IO.Path.GetFileNameWithoutExtension(strOld); IWorkspaceFactory wsf = new ShapefileWorkspaceFactoryClass(); IWorkspace wsShp = wsf.OpenFromFile(strFolder, 0); IFeatureClass fClass = (wsShp as IFeatureWorkspace).OpenFeatureClass(strName); IPosition61 position = m_Model.Position; ESRI.ArcGIS.Geometry.IPoint pModel = new ESRI.ArcGIS.Geometry.PointClass(); pModel.SpatialReference = (fClass as IGeoDataset).SpatialReference; pModel.PutCoords(position.X, position.Y); ESRI.ArcGIS.Geometry.ITopologicalOperator topoOperator = pModel as ESRI.ArcGIS.Geometry.ITopologicalOperator; ESRI.ArcGIS.Geometry.IGeometry geoModel = topoOperator.Buffer(50); ISpatialFilter qFilter = new SpatialFilterClass(); qFilter.Geometry = geoModel; qFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; IFeatureCursor fCursor = fClass.Search(qFilter, false); IFeature fCross = fCursor.NextFeature(); if (fCross == null) { SendMessage("在当前位置的50米范围内没有找到路口信息。"); SendMessage("若您的路口信息是全面的,则您所安放的位置偏离了路口过多,理论上不适合安放信号灯!"); SendMessage("分析结束"); return; } double lampHeight = (double)spinEdit1.Value; double carHeight = (double)spinEdit2.Value; double setHeight = (double)spinEdit3.Value; double carLength = (double)spinEdit4.Value; double lampMustDistance = (double)spinEdit5.Value; double roadWidth = 30; roadWidth = Convert.ToDouble(fCross.get_Value(fClass.FindField("NorthWidth"))); System.Threading.Thread.Sleep(1000); SendMessage("正在计算有大车情况下是否能在规定的最小必须可见距离内看到信号灯..."); System.Threading.Thread.Sleep(1000); double lampMustHeight = (carHeight - setHeight) * lampMustDistance / (carLength + roadWidth) + setHeight; if (lampHeight < lampMustHeight) { SendMessage(string.Format(" 信号灯在有大车情况下不能在规定的最小距离内看到信号灯,必须在路对面增加辅助信号灯。")); SendMessage("当前位置不合适安放信号灯或必须添加辅助信号灯!"); SendMessage("分析结束。"); return; } SendMessage("正在计算是否会因为建筑物及绿化带等引起信号灯盲区..."); //int tempGroup = this.m_Hook.ProjectTree.FindItem(m_TempGroup); //if (tempGroup < 0) //{ // tempGroup = this.m_Hook.ProjectTree.CreateGroup(m_TempGroup); //} //IPosition61 position = m_Model.Position; //m_Hook.CoordServices.MoveCoordEx(ref position, 0, 0, lampHeight); //int analysisGroup = m_Hook.Analysis.CreateViewshed(position, 360, 1, roadWidth + lampMustDistance, setHeight, null, null, tempGroup, m_TempAnalysisName); //int invisibleItem = m_Hook.ProjectTree.FindItem(string.Format(@"{0}\{1}\Invisible Area",m_TempGroup,m_TempAnalysisName)); //object obj = m_Hook.ProjectTree.GetObject(invisibleItem); System.Threading.Thread.Sleep(5000); if (Convert.ToInt32(fCross.get_Value(fClass.FindField("Flag"))) > 0) { SendMessage(" 由于建筑物及绿化带等将引起信号灯盲区,必须在路对面增加辅助信号灯."); SendMessage("当前位置不合适安放信号灯或必须添加辅助信号灯!"); SendMessage("分析结束。"); return; } SendMessage("当前位置安放信号灯后不需要添加辅助信号灯!"); SendMessage("分析结束。"); } catch { SendMessage("分析过程出错了,分析结束"); } }
/// <summary> /// 创建等高线*.shp文件的主方法 /// </summary> /// <param name="lux">左上投影x坐标</param> /// <param name="luy">左上投影y坐标</param> /// <param name="luz">左上投影z坐标</param> /// <param name="rlx">右下投影x坐标</param> /// <param name="rly">右下投影y坐标</param> /// <param name="rlz">右下投影z坐标</param> /// <param name="m_interval">采样间隔</param> /// <returns>等高线*.shp文件的文件名</returns> public string CreateContourShape(ISGWorld61 sgworld, double lux, double luy, double luz, double rlx, double rly, double rlz, double m_interval) { double width = sgworld.CoordServices.GetDistance(lux, luy, rlx, luy); double hight = sgworld.CoordServices.GetDistance(lux, luy, lux, rly); if (width < 5 || hight < 10) { MessageBox.Show("范围过小!", "SUNZ", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(null); } if ((width / 1000) * (hight / 1000) > 40) { if (MessageBox.Show("范围超出40平分公里,系统计算时间比较长,是否继续?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { } else { return(null); } } this.Interval = m_interval; this.Random = System.Guid.NewGuid().ToString().Substring(0, 6).ToLower(); CopyFolder(Application.StartupPath + "\\Convert\\TemPoints", Application.StartupPath + "\\Convert\\PointsResult\\" + this.Random); IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactory(); IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(Application.StartupPath + "\\Convert\\PointsResult\\" + this.Random, 0); IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace; IFeatureClass pFeatureClass = pFeatureWorkspace.OpenFeatureClass(System.IO.Path.GetFileNameWithoutExtension(Application.StartupPath + "\\Convert\\PointsResult\\" + Random + "\\TemPointLayer.shp")); IFeatureClassWrite fr = (IFeatureClassWrite)pFeatureClass; IWorkspaceEdit w = (pFeatureClass as IDataset).Workspace as IWorkspaceEdit; IFeature f; w.StartEditing(true); w.StartEditOperation(); int EastPointCount = (int)(width / 5); int NothPointCount = (int)(hight / 5); for (int j = 0; j < NothPointCount; j++) { ESRI.ArcGIS.Geometry.IPoint p; p = new ESRI.ArcGIS.Geometry.PointClass(); ESRI.ArcGIS.Geometry.IZAware iz = p as ESRI.ArcGIS.Geometry.IZAware; iz.ZAware = true; p.X = lux; p.Y = luy; p.Z = luz; ESRI.ArcGIS.Geometry.IGeometry peo; peo = p; f = pFeatureClass.CreateFeature(); f.Shape = peo; f.set_Value(3, p.Z); f.Store(); fr.WriteFeature(f); for (int i = 0; i < EastPointCount; i++) { IPosition61 positionLU = null; ICoord2D pPoint = null; if ((j + 2) % 2 == 0) { pPoint = sgworld.CoordServices.MoveCoord(lux, luy, 5, 0); } else { pPoint = sgworld.CoordServices.MoveCoord(lux, luy, -5, 0); } IWorldPointInfo61 pW = sgworld.Terrain.GetGroundHeightInfo(pPoint.X, pPoint.Y, AccuracyLevel.ACCURACY_BEST_FROM_MEMORY, true); positionLU = pW.Position; luz = positionLU.Altitude; lux = positionLU.X; luy = positionLU.Y; p = new ESRI.ArcGIS.Geometry.PointClass(); iz = p as ESRI.ArcGIS.Geometry.IZAware; iz.ZAware = true; p.X = lux; p.Y = luy; p.Z = luz; peo = p; f = pFeatureClass.CreateFeature(); f.Shape = peo; f.set_Value(3, p.Z); f.Store(); fr.WriteFeature(f); } ICoord2D pPointL = sgworld.CoordServices.MoveCoord(lux, luy, 0, -5); IWorldPointInfo61 pWL = sgworld.Terrain.GetGroundHeightInfo(pPointL.X, pPointL.Y, AccuracyLevel.ACCURACY_FORCE_BEST_RENDERED, true); luz = pWL.Position.Altitude; lux = pWL.Position.X; luy = pWL.Position.Y; } w.StopEditOperation(); w.StopEditing(true); CreateTinFromFeature(pFeatureClass); return(this.Random); }
private void simpleButton1_Click(object sender, EventArgs e) { if (m_Flag) { if (MessageBox.Show("已经分析过了,确定要再次分析吗?", "Sunz", MessageBoxButtons.YesNo) != DialogResult.Yes) { return; } } else { this.Height = this.Height + txtResult.Height; this.Refresh(); Application.DoEvents(); } Clear(); try { // 获取设置 double lampHeight = (double)spinEdit1.Value; double carHeight = (double)spinEdit2.Value; double setHeight = (double)spinEdit3.Value; double carLength = (double)spinEdit4.Value; double lampMustDistance = (double)spinEdit5.Value; LampSetting lampSetting = new LampSetting(); lampSetting.MostLampHeight = lampHeight; lampSetting.MostCarHeight = carHeight; lampSetting.LestSetHeight = setHeight; lampSetting.MostCarLength = carLength; lampSetting.MustViewDistance = lampMustDistance; m_Result.Setting = lampSetting; object[] args = { lampHeight, carHeight, setHeight, carLength, lampMustDistance }; string strArgs = string.Format("信号灯最大高度:{0}米;车辆最大高度:{1}米;车座最小高度:{2}米;车辆最大长度:{3}米;信号灯最小必须可见距离:{4}米", args); string lyr = ConfigurationManager.AppSettings["CrossLayer"]; int lyrID = m_Hook.ProjectTree.FindItem(lyr); if (lyrID < 0) { MessageBox.Show("您的配置有问题或者路口图层没有加载"); return; } ILayer61 teLayer = null; try { teLayer = m_Hook.ProjectTree.GetLayer(lyrID); if (teLayer == null) { return; } } catch { MessageBox.Show("您配置的路口图层不是矢量图层"); return; } // 准备信号灯图层 int lampGroup = m_Hook.ProjectTree.FindItem(m_LampGroup); if (lampGroup > -1) { m_Hook.ProjectTree.DeleteItem(lampGroup); } lampGroup = m_Hook.ProjectTree.CreateGroup(m_LampGroup); int fCount = teLayer.FeatureGroups.Point.Count; string[] strDirects = { "东", "南", "西", "北" }; int fIndex = 0; while (true) { double crossWidth = 10; SendMessage(string.Format("正在分析第{0}个路口...", fIndex + 1)); IFeature61 tefCurrent = teLayer.FeatureGroups.Point[fIndex] as IFeature61; for (int i = 0; i < 4; i++) { SendMessage(string.Format(" 正在分析{0}面的信号灯...", strDirects[i])); crossWidth = Convert.ToDouble(tefCurrent.FeatureAttributes.GetFeatureAttribute(m_RoadWidthFields[i]).Value); if (crossWidth <= 0) { SendMessage(string.Format(" {0}没有支路,不需要信号灯。", strDirects[i])); continue; } string strRoadInfo = string.Format("路口宽度:{0}米", crossWidth); SendMessage(string.Format(" 加载参数:{0};{1}...", strArgs, strRoadInfo)); SendMessage(string.Format(" 正在添加信号灯...")); // 添加信号灯 IPoint fPoint = tefCurrent.Geometry as IPoint; double offSet = crossWidth / 2.0; if (fPoint.X < 180) // 坐标转换 { offSet = offSet / 102166.66666666666666666666666667; } // 按东南西北移动到对面的斑马线 double modelX = fPoint.X + (i == 0 ? -offSet : (i == 2 ? offSet : 0)); double modelY = fPoint.Y + (i == 1 ? offSet : (i == 3 ? -offSet : 0)); // 按东南西北移动到右侧 modelX = modelX + (i == 1 ? offSet : (i == 3 ? -offSet : 0)); modelY = modelY + (i == 0 ? offSet : (i == 2 ? -offSet : 0)); // 根据路口实际方位与正东南西北方位偏移角做位置调整 double rawOffSet = Convert.ToDouble(tefCurrent.FeatureAttributes.GetFeatureAttribute(m_RoadOffsetFields[i]).Value); double dgree = rawOffSet / 180 * Math.PI; double dgreeBase = Math.PI / 4; double dOffsetX = 0; double dOffsetY = 0; switch (i) { case 0: dOffsetX = offSet * (Math.Cos(dgreeBase) - Math.Cos(dgree + dgreeBase)); dOffsetY = offSet * (Math.Sin(dgree + dgreeBase) - Math.Sin(dgreeBase)); break; case 1: dOffsetX = offSet * (Math.Sin(dgree + dgreeBase) - Math.Sin(dgreeBase)); dOffsetY = -offSet * (Math.Cos(dgreeBase) - Math.Cos(dgree + dgreeBase)); break; case 2: dOffsetX = -offSet * (Math.Cos(dgreeBase) - Math.Cos(dgree + dgreeBase)); dOffsetY = -offSet * (Math.Sin(dgree + dgreeBase) - Math.Sin(dgreeBase)); break; case 3: dOffsetX = -offSet * (Math.Sin(dgree + dgreeBase) - Math.Sin(dgreeBase)); dOffsetY = offSet * (Math.Cos(dgreeBase) - Math.Cos(dgree + dgreeBase)); break; } modelX = modelX + dOffsetX; modelY = modelY + dOffsetY; double raw = (rawOffSet + 90 * (1 + i)) % 360; IPosition61 position = m_Hook.Creator.CreatePosition(modelX, modelY, fPoint.Z, AltitudeTypeCode.ATC_TERRAIN_RELATIVE, raw); string strName = string.Format("第{0}个路口{1}面支路", fIndex + 1, strDirects[i]); ITerrainModel61 theModel = m_Hook.Creator.CreateModel(position, m_ModelFile, 1, ModelTypeCode.MT_NORMAL, lampGroup, strName); //m_Hook.Navigate.SetPosition(position); //Application.DoEvents(); // 信号灯信息 LampInfo lampInfo = new LampInfo(); lampInfo.CrossName = (fIndex + 1).ToString(); lampInfo.Name = strName; lampInfo.DirectString = strDirects[i]; lampInfo.CrossWidth = crossWidth; lampInfo.RawOffset = rawOffSet; lampInfo.TheLamp = theModel; lampInfo.X = modelX; lampInfo.Y = modelY; m_Result.AddLamp(lampInfo); // 无论后来计算的结果如何,先添加到结果 // 计算大车遮挡 // 计算时间太短,停一秒 System.Threading.Thread.Sleep(Convert.ToInt32(ConfigurationManager.AppSettings["HeightSleep"])); double lampMustHeight = (carHeight - setHeight) * (lampMustDistance + crossWidth) / (lampMustDistance - carLength) + setHeight; lampInfo.LestHeight = lampMustHeight; SendMessage(string.Format(" 信号最小理论高度为{0}米...", lampMustHeight)); if (lampHeight < lampMustHeight) { lampInfo.HeightFlag = true; SendMessage(string.Format(" 信号灯在有大车情况下不能在规定的最小距离内看到信号灯,必须在路对面增加辅助信号灯.")); SendMessage(string.Format(" 正在添加辅助信号灯...")); // 添加辅助信号灯 position = m_Hook.Creator.CreatePosition(fPoint.X + (i < 1 ? -offSet : offSet), fPoint.Y + (i == 1 || i == 2 ? offSet : -offSet), fPoint.Z); ITerrainModel61 assistantModel = m_Hook.Creator.CreateModel(position, m_ModelFile, 1, ModelTypeCode.MT_NORMAL, lampGroup, string.Format("第{0}个路口{1}辅助", fIndex + 1, strDirects[i])); lampInfo.AssistantLamp = assistantModel; continue; } SendMessage(string.Format(" 正在计算是否会因为建筑物及绿化带等引起信号灯盲区...")); // 计算因为建筑物及绿化带等引起的 // 计算过程就先不计算了,从数据里读吧,停2秒 System.Threading.Thread.Sleep(Convert.ToInt32(ConfigurationManager.AppSettings["BuildingSleep"])); if (Convert.ToInt32(tefCurrent.FeatureAttributes.GetFeatureAttribute(m_FlagField).Value) > 0) // 引起盲区 { lampInfo.ViewFlag = false; SendMessage(string.Format(" 由于建筑物及绿化带等将引起信号灯盲区,必须在路对面增加辅助信号灯.")); SendMessage(string.Format(" 正在添加辅助信号灯...")); // 添加辅助信号灯 position = m_Hook.Creator.CreatePosition(fPoint.X + (i < 1 ? -offSet : offSet), fPoint.Y + (i == 1 || i == 2 ? offSet : -offSet), fPoint.Z); ITerrainModel61 assistantModel = m_Hook.Creator.CreateModel(position, m_ModelFile, 1, ModelTypeCode.MT_NORMAL, lampGroup, string.Format("第{0}个路口{1}辅助", fIndex + 1, strDirects[i])); lampInfo.AssistantLamp = assistantModel; } } fIndex++; if (fIndex == fCount) { break; } } SendMessage("自动化分析已完成。"); m_Result.LampAnalysisFinished(); m_Flag = true; } catch { MessageBox.Show("对不起,分析过程出现错误,这通常是由配置与数据不匹配引起的"); return; } }
/// <summary> /// 加载shape文件添加模型 /// 模型数据要与shape在同一路径下 /// 2012-09-21 张航宇 /// 添加Z修正 -56 /// </summary> /// <param name="FileName"></param> /// public void LoadShapeAdd3model(ISGWorld61 sgworld, ITerraExplorer te, string FileName) { IInformationTree5 infoTree5 = te as IInformationTree5; if (string.IsNullOrEmpty(FileName)) { return; } if (File.Exists(FileName)) { bool PathType = true; string PathFileName = ""; string GroupName = "模型组群" + System.Guid.NewGuid().ToString().Substring(0, 6); infoTree5.CreateGroup(GroupName, 0); int GroupID = sgworld.ProjectTree.FindItem(GroupName); string ModelFilename = ""; string UNModelFilename = ""; string _XMLLayerInfo = "<PlugData>" + "<PlugType>shape</PlugType>" + "<LayerName>" + FileName + "</LayerName>" + "<Server></Server>" + "<user></user>" + "<password></password>" + "<TableName></TableName>" + "<AttributesToLoad>*</AttributesToLoad >" + "<Feature>1</Feature >" + "<Annotation>1</Annotation>" + "<SaveItems>0</SaveItems>" + "<GroupKey>LAT-LONG</GroupKey>" + "<SysKey>LAT-LONG</SysKey>" + "<DatumKey>WGS84</DatumKey>" + "<UnitKey>METERS</UnitKey>" + "<UseZValue>0</UseZValue>" + "<AltitudeUnit>Meters</AltitudeUnit>" + "<Reproject>1</Reproject>" + "<StreamedLayer>0</StreamedLayer></PlugData >"; ILayer5 iLyr = infoTree5.CreateLayer("3DModleGoto", _XMLLayerInfo, GroupID);//在根目录下装载shp数据 iLyr.Load(); IFeature61 sqfeature61 = null; int itemid = sgworld.ProjectTree.FindItem("" + GroupName + "\\3DModleGoto"); ILayer61 m_layer61 = sgworld.ProjectTree.GetLayer(itemid); m_layer61.Streaming = false; IFeatureGroups61 pFeatureGroups61 = m_layer61.FeatureGroups; IFeatureGroup61 pFeatureGroup61 = pFeatureGroups61.Point as IFeatureGroup61; if (pFeatureGroup61 == null) { MessageBox.Show("当前操作要求是正确的点图层"); return; } else { if (pFeatureGroup61.Count == 0) { MessageBox.Show("图层为空!"); return; } else { sqfeature61 = pFeatureGroup61[0] as IFeature61; IFeatureAttributes61 m_FeatureAttributes = sqfeature61.FeatureAttributes; int AttributesCount = m_FeatureAttributes.Count; string[] FiledArry = new string[AttributesCount]; for (int f = 0; f < AttributesCount; f++) { IFeatureAttribute61 m_FeatureAttribute = m_FeatureAttributes[f] as IFeatureAttribute61; FiledArry[f] = m_FeatureAttribute.Name; } Skyline.Core.UI.FrmAddModelShape pFrmAddModelShape = new Skyline.Core.UI.FrmAddModelShape(); pFrmAddModelShape.GetFiledName = FiledArry; pFrmAddModelShape.ShowDialog(); PathFileName = pFrmAddModelShape.Filed; PathType = pFrmAddModelShape.PathType; pFrmAddModelShape.Dispose(); int m_FeatureCount = pFeatureGroup61.Count; int ImportFeatureCount = pFeatureGroup61.Count; for (int i = 0; i < m_FeatureCount; i++) { sqfeature61 = pFeatureGroup61[i] as IFeature61; IFeatureAttributes61 _FeatureAttributes = sqfeature61.FeatureAttributes; TerraExplorerX.IGeometry _Geometry = sqfeature61.GeometryZ; TerraExplorerX.IPoint pPoint = _Geometry as TerraExplorerX.IPoint; //IPosition61 TPosition61 = sgworld.Window.PixelToWorld(pPoint.X, pPoint.Y, WorldPointType.WPT_ALL).Position; IPosition61 TPosition61 = sgworld.Creator.CreatePosition(pPoint.X, pPoint.Y, -56, AltitudeTypeCode.ATC_TERRAIN_RELATIVE, 0, 0); IFeatureAttribute61 _FeatureAttribute = _FeatureAttributes.GetFeatureAttribute(PathFileName); UNModelFilename = _FeatureAttribute.Value.ToString(); if (PathType) { ModelFilename = System.IO.Path.GetDirectoryName(FileName) + "\\" + UNModelFilename; } else { ModelFilename = UNModelFilename; } try { sgworld.Creator.CreateModel(TPosition61, ModelFilename, 1, ModelTypeCode.MT_NORMAL, GroupID, UNModelFilename); } catch { ImportFeatureCount--; continue; } } MessageBox.Show(ImportFeatureCount + "个模型加载成功," + (m_FeatureCount - ImportFeatureCount) + "个模型加载失败!"); /****20130227杨漾(添加文件有效性判断,分步判断图层有效性,增加加载统计情况提示)****/ } } } }