private void LoadDynamicObjectAndLineFromFile() { ICameraTour tour = null; string tourPath = (strMediaPath + @"\xml\CameraTour_2.xml"); if (File.Exists(tourPath)) { StreamReader sr = new StreamReader(tourPath); string xmlstring = sr.ReadToEnd(); sr.Close(); tour = this.axRenderControl1.ObjectManager.CreateCameraTour(rootId); tour.FromXml(xmlstring); } if (tour == null) { MessageBox.Show("xml文件读取失败"); } dynamicObject.CrsWKT = tour.CrsWKT; point.SpatialCRS = new CRSFactory().CreateFromWKT(tour.CrsWKT) as ISpatialCRS; line.SpatialCRS = new CRSFactory().CreateFromWKT(tour.CrsWKT) as ISpatialCRS; for (int i = 0; i < tour.WaypointsNumber; i++) { double duration; gviCameraTourMode mode; tour.GetWaypoint(i, out position, out angle, out duration, out mode); dynamicObject.AddWaypoint(position, 10); point.Position = position; if (line.PointCount == 0) { line.StartPoint = point; } else { line.AddPointAfter(i - 1, point); } } ICurveSymbol cur = new CurveSymbol(); cur.Color = System.Drawing.Color.Yellow; cur.Width = -2; rline = this.axRenderControl1.ObjectManager.CreateRenderPolyline(line, cur, rootId); }
private void LoadMotionPathAndLineFromFile() { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(Application.StartupPath + @"MotionPath.xml"); wkt = xmlDoc.SelectSingleNode("root/WKT").InnerText; // 指定坐标系与xml里的相同 motionPath.CrsWKT = xmlDoc.SelectSingleNode("root/WKT").InnerText; point.SpatialCRS = new CRSFactory().CreateFromWKT(motionPath.CrsWKT) as ISpatialCRS; line.SpatialCRS = new CRSFactory().CreateFromWKT(motionPath.CrsWKT) as ISpatialCRS; XmlNodeList nodes = xmlDoc.SelectNodes("root/Waypoint"); int i = 0; foreach (XmlNode node in nodes) { double x = double.Parse(node.SelectSingleNode("X").InnerText); double y = double.Parse(node.SelectSingleNode("Y").InnerText); double z = double.Parse(node.SelectSingleNode("Z").InnerText); double heading = double.Parse(node.SelectSingleNode("Heading").InnerText); double tilt = double.Parse(node.SelectSingleNode("Tilt").InnerText); double roll = double.Parse(node.SelectSingleNode("Roll").InnerText); double when = double.Parse(node.SelectSingleNode("When").InnerText); position.Set(x, y, z); point.Position = position; if (line.PointCount == 0) { line.StartPoint = point; } else { line.AddPointAfter(i - 1, point); } i++; angle.Set(heading, tilt, roll); scale.Set(1, 1, 1); motionPath.AddWaypoint2(point, angle, scale, when); this.axRenderControl1.ObjectManager.CreateRenderPoint(point, null, rootId); } ICurveSymbol cur = new CurveSymbol(); cur.Color = System.Drawing.Color.Red; cur.Width = -2; rline = this.axRenderControl1.ObjectManager.CreateRenderPolyline(line, cur, rootId); }