Exemplo n.º 1
0
        private void drawTempLine(INetworkRoute route)
        {
            // 画出停靠点到映射点的虚线
            int segmentCount                   = route.SegmentCount;
            INetworkRouteSegment segment       = null;
            INetworkLocation     startLocation = null;
            INetworkLocation     endLocation   = null;
            IPoint       pointOnNetwork        = null;
            ICurveSymbol tmpLineSym            = new CurveSymbol();

            tmpLineSym.Color = System.Drawing.Color.Yellow;
            tmpLineSym.Width = -2;
            for (int i = 0; i < segmentCount; i++)
            {
                segment        = route.GetSegment(i);
                startLocation  = segment.StartLocation;
                pointOnNetwork = startLocation.NetworkPosition;
                fdepoint       = startLocation.Position;
                IPolyline tmpLine = geoFac.CreateGeometry(gviGeometryType.gviGeometryPolyline, gviVertexAttribute.gviVertexAttributeZ) as IPolyline;
                tmpLine.AppendPoint(fdepoint);
                tmpLine.AppendPoint(pointOnNetwork);
                tmpRenderLineArray.Add(this.axRenderControl1.ObjectManager.CreateRenderPolyline(tmpLine, tmpLineSym, rootId));
                if (i == segmentCount - 1)
                {
                    endLocation    = segment.EndLocation;
                    pointOnNetwork = endLocation.NetworkPosition;
                    fdepoint       = endLocation.Position;
                    tmpLine        = geoFac.CreateGeometry(gviGeometryType.gviGeometryPolyline, gviVertexAttribute.gviVertexAttributeZ) as IPolyline;
                    tmpLine.AppendPoint(fdepoint);
                    tmpLine.AppendPoint(pointOnNetwork);
                    tmpRenderLineArray.Add(this.axRenderControl1.ObjectManager.CreateRenderPolyline(tmpLine, tmpLineSym, rootId));
                }
            }
        }
        private void CreateRenderPolyline(IPoint point)
        {
            if (gfactory == null)
            {
                gfactory = new GeometryFactory();
            }

            fde_polyline            = (IPolyline)gfactory.CreateGeometry(i3dGeometryType.i3dGeometryPolyline, i3dVertexAttribute.i3dVertexAttributeZ);
            fde_polyline.SpatialCRS = crs;

            fde_point            = (IPoint)gfactory.CreateGeometry(i3dGeometryType.i3dGeometryPoint, i3dVertexAttribute.i3dVertexAttributeZ);
            fde_point.SpatialCRS = crs;

            fde_point.SetCoords(point.X, point.Y, point.Z, 0, 0);
            fde_polyline.AppendPoint(fde_point);

            fde_point.SetCoords(point.X + 20, point.Y, point.Z, 0, 0);
            fde_polyline.AppendPoint(fde_point);

            fde_point.SetCoords(point.X + 20, point.Y + 20, point.Z, 0, 0);
            fde_polyline.AppendPoint(fde_point);

            fde_point.SetCoords(point.X + 20, point.Y + 20, point.Z + 20, 0, 0);
            fde_polyline.AppendPoint(fde_point);

            lineSymbol       = new CurveSymbolClass();
            lineSymbol.Color = 0xffff00ff;  // 紫红色

            rpolyline = _axRenderControl.ObjectManager.CreateRenderPolyline(fde_polyline, lineSymbol);

            _axRenderControl.Camera.FlyToObject(rpolyline.Guid, i3dActionCode.i3dActionFlyTo);
        }
Exemplo n.º 3
0
        private void btnConstructPolyline_Click(object sender, EventArgs e)
        {
            if (gfactory == null)
                gfactory = new GeometryFactory();

            point = gfactory.CreatePoint(gviVertexAttribute.gviVertexAttributeZ);
            polyline = gfactory.CreateGeometry(gviGeometryType.gviGeometryPolyline, gviVertexAttribute.gviVertexAttributeZ) as IPolyline;

            int length = 100;
            for (int i = 0; i < length; i++)
            {
                point.SetCoords(i, 2 * i, 0, 0, i + 1);
                polyline.AppendPoint(point);
            }
            if (polyline == null)
                return;

            CompoundLine geo = new CompoundLine();
            // Geometry属性
            geo.Dimension = polyline.Dimension;
            if (polyline.Envelope != null)
            {
                geo.MaxX = polyline.Envelope.MaxX;
                geo.MaxY = polyline.Envelope.MaxY;
                geo.MaxZ = polyline.Envelope.MaxZ;
                geo.MinX = polyline.Envelope.MinX;
                geo.MinY = polyline.Envelope.MinY;
                geo.MinZ = polyline.Envelope.MinZ;
            }
            geo.GeometryType = polyline.GeometryType;
            geo.IsEmpty = polyline.IsEmpty;
            geo.IsValid = polyline.IsValid;
            geo.VertexAttribute = polyline.VertexAttribute;
            geo.HasId = polyline.HasId();
            geo.HasM = polyline.HasM();
            geo.HasZ = polyline.HasZ();
            // Curve属性
            geo.IsClosed = polyline.IsClosed;
            geo.Length = polyline.Length;
            if (polyline.StartPoint != null)
            {
                geo.StartPointX = polyline.StartPoint.X;
                geo.StartPointY = polyline.StartPoint.Y;
                geo.StartPointZ = polyline.StartPoint.Z;
            }
            if (polyline.EndPoint != null)
            {
                geo.EndPointX = polyline.EndPoint.X;
                geo.EndPointY = polyline.EndPoint.Y;
                geo.EndPointZ = polyline.EndPoint.Z;
            }
            // CompoundLine属性
            geo.PointCount = polyline.PointCount;
            geo.SegmentCount = polyline.SegmentCount;

            this.propertyGrid1.SelectedObject = geo;
        }
Exemplo n.º 4
0
        public static bool ConvertBuildingParam(IPolygon footprint, double startZ, double height, out IMultiPolygon segPolygon, out IPolyline route)
        {
            segPolygon = null;
            route      = null;
            IPoint    point      = null;
            IPoint    pointValue = null;
            IEnvelope envelope   = null;
            IPolygon  polygon    = null;

            if (footprint == null)
            {
                return(false);
            }
            try
            {
                envelope   = footprint.Envelope;
                segPolygon = DrawGeometry.geoFactory.CreateGeometry(gviGeometryType.gviGeometryMultiPolygon, gviVertexAttribute.gviVertexAttributeZ) as IMultiPolygon;
                route      = DrawGeometry.geoFactory.CreateGeometry(gviGeometryType.gviGeometryPolyline, gviVertexAttribute.gviVertexAttributeZ) as IPolyline;
                point      = DrawGeometry.geoFactory.CreatePoint(gviVertexAttribute.gviVertexAttributeZ);
                point.SetCoords(envelope.Center.X, envelope.Center.Y, 0.0, 0.0, 0);
                pointValue   = point.Clone() as IPoint;
                pointValue.Z = startZ;
                route.AppendPoint(pointValue);
                pointValue   = point.Clone() as IPoint;
                pointValue.Z = startZ + height;
                route.AppendPoint(pointValue);
                int pointCount = footprint.ExteriorRing.PointCount;
                polygon = DrawGeometry.geoFactory.CreateGeometry(gviGeometryType.gviGeometryPolygon, gviVertexAttribute.gviVertexAttributeZ) as IPolygon;
                for (int i = 0; i < pointCount; i++)
                {
                    pointValue    = footprint.ExteriorRing.GetPoint(i).Clone() as IPoint;
                    pointValue.X -= point.X;
                    pointValue.Y -= point.Y;
                    polygon.ExteriorRing.AppendPoint(pointValue);
                }
                segPolygon.AddPolygon(polygon);
                return(true);
            }
            catch (Exception exception)
            {
                DrawGeometry.WriteLog(exception.StackTrace);
                return(false);
            }
        }
Exemplo n.º 5
0
 public IPoint RadialIntersect(Vector p0, Vector d0, Vector p1, Vector d1)
 {
     try
     {
         IPoint other = DrawGeometry.geoFactory.CreatePoint(gviVertexAttribute.gviVertexAttributeZ);
         other.SetCoords(p0.X, p0.Y, p0.Z, 0.0, -1);
         IPolyline polyline   = DrawGeometry.geoFactory.CreateGeometry(gviGeometryType.gviGeometryPolyline, gviVertexAttribute.gviVertexAttributeZ) as IPolyline;
         IPoint    pointValue = DrawGeometry.geoFactory.CreatePoint(gviVertexAttribute.gviVertexAttributeZ);
         pointValue.SetCoords(p1.X, p1.Y, p1.Z, 0.0, -1);
         polyline.AppendPoint(pointValue);
         pointValue = DrawGeometry.geoFactory.CreatePoint(gviVertexAttribute.gviVertexAttributeZ);
         Vector vector = p1 + ((Vector)(d1.UnitVector() * 10.0));
         pointValue.SetCoords(vector.X, vector.Y, vector.Z, 0.0, -1);
         polyline.AppendPoint(pointValue);
         return((polyline as IProximityOperator).NearestPoint3D(other));
     }
     catch (Exception exception)
     {
         return(null);
     }
 }
Exemplo n.º 6
0
        private void btnConstructMultiPolyline_Click(object sender, EventArgs e)
        {
            if (gfactory == null)
                gfactory = new GeometryFactory();
            multiPolyline = gfactory.CreateGeometry(gviGeometryType.gviGeometryMultiPolyline, gviVertexAttribute.gviVertexAttributeZ) as IMultiPolyline;
            if (multiPolyline == null)
                return;

            // 添加两条Polyline
            point = gfactory.CreatePoint(gviVertexAttribute.gviVertexAttributeZ);
            polyline = gfactory.CreateGeometry(gviGeometryType.gviGeometryPolyline, gviVertexAttribute.gviVertexAttributeZ) as IPolyline;
            int length = 100;
            for (int i = 0; i < length; i++)
            {
                point.SetCoords(i, 2 * i, 0, 0, i + 1);
                polyline.AppendPoint(point);
            }
            IPolyline polylineClone = polyline.Clone() as IPolyline;
            polylineClone.RemovePoints(50, 50);

            multiPolyline.AddPolyline(polyline);
            multiPolyline.AddPolyline(polylineClone);

            MultiCurve geo = new MultiCurve();
            // Geometry属性
            geo.Dimension = multiPolyline.Dimension;
            if (multiPolyline.Envelope != null)
            {
                geo.MaxX = multiPolyline.Envelope.MaxX;
                geo.MaxY = multiPolyline.Envelope.MaxY;
                geo.MaxZ = multiPolyline.Envelope.MaxZ;
                geo.MinX = multiPolyline.Envelope.MinX;
                geo.MinY = multiPolyline.Envelope.MinY;
                geo.MinZ = multiPolyline.Envelope.MinZ;
            }
            geo.GeometryType = multiPolyline.GeometryType;
            geo.IsEmpty = multiPolyline.IsEmpty;
            geo.IsValid = multiPolyline.IsValid;
            geo.VertexAttribute = multiPolyline.VertexAttribute;
            geo.HasId = multiPolyline.HasId();
            geo.HasM = multiPolyline.HasM();
            geo.HasZ = multiPolyline.HasZ();
            // GeometryCollection属性
            geo.GeometryCount = multiPolyline.GeometryCount;
            geo.IsOverlap = multiPolyline.IsOverlap;
            // MultiCurve属性
            geo.Length = multiPolyline.Length;

            this.propertyGrid1.SelectedObject = geo;
        }
Exemplo n.º 7
0
        private void DrawSightLine()
        {
            ClearSightLine();
            ClearRes();
            IPoint ptStart = this._geoFactory.CreatePoint(gviVertexAttribute.gviVertexAttributeZ);

            ptStart.X = (double)this.seObserX.Value;
            ptStart.Y = (double)this.seObserY.Value;
            ptStart.Z = (double)this.seObserZ.Value + (double)this.seObserZOff.Value;
            IPoint ptEnd = this._geoFactory.CreatePoint(gviVertexAttribute.gviVertexAttributeZ);

            ptEnd.X = (double)this.seObjX.Value;
            ptEnd.Y = (double)this.seObjY.Value;
            ptEnd.Z = (double)this.seObjZ.Value + (double)this.seObjZOff.Value;
            IPolyline line = this._geoFactory.CreateGeometry(gviGeometryType.gviGeometryPolyline, gviVertexAttribute.gviVertexAttributeZ) as IPolyline;

            line.AppendPoint(ptStart);
            line.AppendPoint(ptEnd);
            ICurveSymbol cs = new CurveSymbolClass();

            cs.Color    = 0xff00ff00;
            cs.Width    = -1;
            this._rLine = this._3DControl.ObjectManager.CreateRenderPolyline(line, cs, this._3DControl.ProjectTree.RootID);
        }
Exemplo n.º 8
0
 private void ReversePolyline(ref IPolyline ply)
 {
     if ((ply != null) && (ply.PointCount != 0))
     {
         Stack <IPoint> stack = null;
         stack = new Stack <IPoint>();
         for (int i = 0; i < ply.PointCount; i++)
         {
             stack.Push(ply.GetPoint(i));
         }
         ply.RemovePoints(0, ply.PointCount);
         while (stack.Count > 0)
         {
             ply.AppendPoint(stack.Pop());
         }
     }
 }
Exemplo n.º 9
0
        public void RenderTrajectory(List <Trajectory> traceInfos, uint pointColor = 0xAA90EE90, uint lineColor = 0xAA0CE6E5)
        {
            try
            {
                symbol = new SimplePointSymbolClass()
                {
                    FillColor = pointColor,
                    Size      = 10
                };

                #region 创建线
                IPoint    point = _geoFactory.CreatePoint(i3dVertexAttribute.i3dVertexAttributeZ);
                IPolyline line  = (IPolyline)_geoFactory.CreateGeometry(i3dGeometryType.i3dGeometryPolyline, i3dVertexAttribute.i3dVertexAttributeZ);
                line.SpatialCRS = _spatialCRS;


                foreach (Trajectory trajectory in traceInfos)
                {
                    point.SetCoords(trajectory.LongitudeWgs84, trajectory.LatitudeWgs84, 1, 0, 0);
                    point.SpatialCRS = _spatialCRS;

                    line.AppendPoint(point);
                    var rPoint = _axRenderControl.ObjectManager.CreateRenderPoint(point, symbol);
                    rPoint.MaxVisibleDistance = 100000;
                    rPoint.ViewingDistance    = 500000;
                    AppendGuidToStringBuilder(rPoint.Guid);
                }
                //lineColor = 0xFF0CE6E5;
                tracePolyline = _axRenderControl.ObjectManager.CreateRenderPolyline(line, new CurveSymbol {
                    Color = lineColor, Width = -2
                });
                tracePolyline.VisibleMask        = i3dViewportMask.i3dViewAllNormalView;
                tracePolyline.MaxVisibleDistance = 100000;
                tracePolyline.HeightStyle        = i3dHeightStyle.i3dHeightAbsolute;

                AppendGuidToStringBuilder(tracePolyline.Guid);
                //_axRenderControl.Camera.FlyToObject(tracePolyline.Guid, i3dActionCode.i3dActionFollowAbove);
                #endregion
            }
            catch (Exception ex)
            {
                LoggerHelper.Logger.Error(ex, $"执行RenderTrajectory错误");
                throw ex;
            }
        }
Exemplo n.º 10
0
        private void AddPoints(IPoint startPoint, IPoint endPoint)
        {
            double x, y, r;
            IPoint temPont = (IPoint)startPoint.Clone();

            r = Math.Sqrt(Math.Pow(startPoint.X - endPoint.X, 2) + Math.Pow(startPoint.Y - endPoint.Y, 2));
            int step = (int)(r / offSetDis);

            for (int i = 1; i < step; i++)
            {
                x = offSetDis * i * (endPoint.X - startPoint.X) / r + startPoint.X;
                y = offSetDis * i * (endPoint.Y - startPoint.Y) / r + startPoint.Y;

                //Debug.WriteLine($"Point: {x}, {y}, OffSetDis: {offSetDis}");
                temPont.SetCoords(x, y, temPont.Z, temPont.M, temPont.Id);
                //temPont.SetCoords(x, y, 5, temPont.M, temPont.Id);
                polyline.AppendPoint(temPont);
            }
        }
Exemplo n.º 11
0
        public static void TestDrawPolyline(double offX, double offY, double offZ, List <Vector> vLines, ICurveSymbol cvSymbol)
        {
            IPolyline polyline   = null;
            IPoint    pointValue = null;

            polyline = geoFactory.CreateGeometry(gviGeometryType.gviGeometryPolyline, gviVertexAttribute.gviVertexAttributeZ) as IPolyline;
            foreach (Vector vector in vLines)
            {
                pointValue   = geoFactory.CreatePoint(gviVertexAttribute.gviVertexAttributeZ);
                pointValue.X = offX + vector.X;
                pointValue.Y = offY + vector.Y;
                pointValue.Z = offZ + vector.Z;
                polyline.AppendPoint(pointValue);
            }
            IRenderPolyline item = Ocx.ObjectManager.CreateRenderPolyline(polyline, cvSymbol, Ocx.ProjectTree.RootID);

            item.MaxVisibleDistance = maxVisibleDis;
            tmpList.Add(item);
        }
Exemplo n.º 12
0
        /// <summary>
        /// 鼠标点击 拾取线段点
        /// </summary>
        /// <param name="PickResult"></param>
        /// <param name="IntersectPoint"></param>
        /// <param name="Mask"></param>
        /// <param name="EventSender"></param>
        void axRenderControl1_RcMouseClickSelect(IPickResult PickResult, IPoint IntersectPoint, gviModKeyMask Mask, gviMouseSelectMode EventSender)
        {
            if (IntersectPoint == null)
            {
                return;
            }

            if (renderPolyline == null)
            {
                ICurveSymbol cs = new CurveSymbol();
                cs.Color       = System.Drawing.Color.Yellow;
                cs.Width       = -5;
                renderPolyline = this.axRenderControl1.ObjectManager.CreateRenderPolyline(polyline, cs, rootId);
            }

            if (polyline.PointCount < 2)
            {
                polyline.AppendPoint(IntersectPoint);
            }
            if (polyline.PointCount == 2)
            {
                this.axRenderControl1.InteractMode          = gviInteractMode.gviInteractNormal;
                this.axRenderControl1.MouseSelectObjectMask = gviMouseSelectObjectMask.gviSelectNone;
                this.axRenderControl1.MouseSelectMode       = gviMouseSelectMode.gviMouseSelectClick;
                this.axRenderControl1.RcMouseClickSelect   -= new _IRenderControlEvents_RcMouseClickSelectEventHandler(axRenderControl1_RcMouseClickSelect);

                IPoint p = polyline.StartPoint;
                this.startX.Text = p.X.ToString();
                this.startY.Text = p.Y.ToString();
                this.startZ.Text = p.Z.ToString();
                p = polyline.EndPoint;
                this.endX.Text   = p.X.ToString();
                this.endY.Text   = p.Y.ToString();
                this.endZ.Text   = p.Z.ToString();
                flagx            = false;
                this.label7.Text = "线构造成功!请点击“通视分析”按钮";
                this.btnFlyToSourcePoint.Enabled = true;
                this.btnFlyToTargetPoint.Enabled = true;
            }
            renderPolyline.SetFdeGeometry(polyline);
        }
Exemplo n.º 13
0
 // 根据管线起始点高程计算管线中间点高程,返回多段线对象
 private bool GetPipeLineVertexs(IGeometry geo, out IPolyline route)
 {
     route = null;
     try
     {
         IPolyline polyline = null;
         if ((geo == null) || ((polyline = geo as IPolyline) == null))
         {
             return(false);
         }
         IPoint pointValue = null;
         route = DrawGeometry.geoFactory.CreateGeometry(gviGeometryType.gviGeometryPolyline, gviVertexAttribute.gviVertexAttributeZ) as IPolyline;
         for (int i = 0; i < polyline.PointCount; i++)
         {
             pointValue = polyline.GetPoint(i).Clone2(gviVertexAttribute.gviVertexAttributeZ) as IPoint;
             route.AppendPoint(pointValue);
         }
         return(true);
     }
     catch (Exception exception)
     {
         return(false);
     }
 }
Exemplo n.º 14
0
        /// <summary>
        /// 轨迹回放
        /// </summary>
        /// <param name="traceInfo">轨迹数据</param>
        /// <param name="speedTimes">回放倍数</param>
        /// <param name="traceChanged">轨迹是否改变</param>
        public void RenderVehicleTrajectory(IList <Trajectory> traceInfos, int speedTimes, bool traceChanged = true)
        {
            try
            {
                if (traceChanged)
                {
                    if (traceDynamicObj == null)
                    {
                        traceDynamicObj            = _axRenderControl.ObjectManager.CreateDynamicObject();
                        traceDynamicObj.AutoRepeat = false;
                        traceDynamicObj.CrsWKT     = WKT;
                        traceDynamicObj.TurnSpeed  = 300;
                        AppendGuidToStringBuilder(traceDynamicObj.Guid);

                        symbol = new SimplePointSymbolClass()
                        {
                            FillColor = 0xff0000ff,
                            Size      = 10
                        };

                        #region 创建线
                        IPoint    point = _geoFactory.CreatePoint(i3dVertexAttribute.i3dVertexAttributeZ);
                        IPolyline line  = (IPolyline)_geoFactory.CreateGeometry(i3dGeometryType.i3dGeometryPolyline, i3dVertexAttribute.i3dVertexAttributeZ);
                        line.SpatialCRS = _spatialCRS;


                        foreach (Trajectory trajectory in traceInfos)
                        {
                            IVector3 position = new Vector3();
                            position.Set(trajectory.LongitudeWgs84, trajectory.LatitudeWgs84, 1);
                            point.Position   = position;
                            point.SpatialCRS = _spatialCRS;

                            line.AppendPoint(point);
                            traceDynamicObj.AddWaypoint2(point, Convert.ToDouble(30 * speedTimes));

                            var rPoint = _axRenderControl.ObjectManager.CreateRenderPoint(point, symbol);
                            rPoint.MaxVisibleDistance = 12500;
                            rPoint.ViewingDistance    = 50;

                            AppendGuidToStringBuilder(rPoint.Guid);
                            //_axRenderControl.Camera.FlyToObject(rPoint.Guid, i3dActionCode.i3dActionFollowBehindAndAbove);
                        }
                        tracePolyline = _axRenderControl.ObjectManager.CreateRenderPolyline(line, new CurveSymbol {
                            Color = 0xFFFFFF00, Width = -2
                        });
                        tracePolyline.VisibleMask        = i3dViewportMask.i3dViewAllNormalView;
                        tracePolyline.MaxVisibleDistance = 12500;
                        tracePolyline.HeightStyle        = i3dHeightStyle.i3dHeightAbsolute;

                        AppendGuidToStringBuilder(tracePolyline.Guid);
                        #endregion
                    }
                }
                else
                {
                    if (traceDynamicObj == null)
                    {
                        return;
                    }

                    traceDynamicObj.Stop();
                    traceDynamicObj.TurnSpeed = 300 * speedTimes;
                    for (int i = 0; i < traceInfos.Count; i++)
                    {
                        traceDynamicObj.GetWaypoint2(i, out IPoint point, out double speed);
                        traceDynamicObj.ModifyWaypoint2(i, point, 30);
                    }
                }

                TraceObjectsPlay("111", traceDynamicObj, true);
            }
            catch (Exception ex)
            {
                LoggerHelper.Logger.Error(ex, $"执行RenderVehicleTrajectory错误");
                throw ex;
            }
        }
Exemplo n.º 15
0
        private void AddGeometry()
        {
            try
            {
                this.beforeRowBufferMap.Clear();
                SelectCollection.Instance().Clear();
                DF3DFeatureClass featureClassInfo = CommonUtils.Instance().CurEditLayer;
                if (featureClassInfo == null)
                {
                    return;
                }
                IFeatureClass fc = featureClassInfo.GetFeatureClass();
                if (fc == null)
                {
                    return;
                }
                IFieldInfoCollection fields = fc.GetFields();
                int indexGeo = fields.IndexOf(this._strGeometryFieldName);
                if (indexGeo == -1)
                {
                    return;
                }

                IGeometry geo    = this._drawTool.GetGeo();
                IGeometry geoOut = null;
                switch (geo.GeometryType)
                {
                case gviGeometryType.gviGeometryModelPoint:
                    geoOut = geo;
                    break;

                case gviGeometryType.gviGeometryPoint:
                    IPoint pt  = geo as IPoint;
                    IPoint pt1 = pt.Clone2(gviVertexAttribute.gviVertexAttributeZM) as IPoint;
                    pt1.SetCoords(pt.X, pt.Y, pt.Z, 0, 0);
                    geoOut = pt1;
                    break;

                case gviGeometryType.gviGeometryPolyline:
                    IPolyline line  = geo as IPolyline;
                    IPolyline line1 = this._geoFact.CreateGeometry(gviGeometryType.gviGeometryPolyline, gviVertexAttribute.gviVertexAttributeZM) as IPolyline;
                    for (int i = 0; i < line.PointCount; i++)
                    {
                        IPoint ptGet  = line.GetPoint(i);
                        IPoint pttemp = ptGet.Clone2(gviVertexAttribute.gviVertexAttributeZM) as IPoint;
                        pttemp.SetCoords(ptGet.X, ptGet.Y, ptGet.Z, 0, 0);
                        line1.AppendPoint(pttemp);
                    }
                    geoOut = line1;
                    break;

                case gviGeometryType.gviGeometryPolygon:
                    IPolygon polygon  = geo as IPolygon;
                    IPolygon polygon1 = this._geoFact.CreateGeometry(gviGeometryType.gviGeometryPolygon, gviVertexAttribute.gviVertexAttributeZM) as IPolygon;
                    for (int i = 0; i < polygon.ExteriorRing.PointCount; i++)
                    {
                        IPoint ptGet  = polygon.ExteriorRing.GetPoint(i);
                        IPoint pttemp = ptGet.Clone2(gviVertexAttribute.gviVertexAttributeZM) as IPoint;
                        pttemp.SetCoords(ptGet.X, ptGet.Y, ptGet.Z, 0, 0);
                        polygon1.ExteriorRing.AppendPoint(pttemp);
                    }
                    geoOut = polygon1;
                    break;
                }
                if (geoOut == null)
                {
                    return;
                }
                if (geo.GeometryType == gviGeometryType.gviGeometryModelPoint)
                {
                    //导入模型到数据库中
                    string      mn   = BitConverter.ToString(ObjectIdGenerator.Generate()).Replace("-", string.Empty).ToLowerInvariant();
                    IModelPoint mp   = geoOut as IModelPoint;
                    bool        bRes = this.ImportOsg(mn, mp.ModelName);
                    if (!bRes)
                    {
                        return;
                    }
                    mp.ModelName = mn;
                    geoOut       = mp;
                }
                IRowBufferCollection rowCol = new RowBufferCollection();
                IRowBufferFactory    fac    = new RowBufferFactory();
                IRowBuffer           row    = fac.CreateRowBuffer(fields);
                row.SetValue(indexGeo, geoOut);
                rowCol.Add(row);
                beforeRowBufferMap[featureClassInfo] = rowCol;
            }
            catch (Exception ex)
            {
            }
        }
Exemplo n.º 16
0
        private void btnAnalyse_Click(object sender, EventArgs e)
        {
            try
            {
                ClearRes();
                WaitForm.Start("正在分析...", "请稍后");
                if (this._rLine == null)
                {
                    return;
                }
                List <DF3DFeatureClass> list = DF3DFeatureClassManager.Instance.GetAllFeatureClass();
                if (list == null || list.Count == 0)
                {
                    return;
                }

                IPolyline line = this._rLine.GetFdeGeometry() as IPolyline;
                ILine     l    = this._geoFactory.CreateGeometry(gviGeometryType.gviGeometryLine, gviVertexAttribute.gviVertexAttributeZ) as ILine;
                l.StartPoint = line.StartPoint;
                l.EndPoint   = line.EndPoint;

                ISpatialFilter filter = new SpatialFilter();
                filter.SpatialRel    = gviSpatialRel.gviSpatialRelEnvelope;
                filter.GeometryField = "Geometry";

                List <InterPt> listInterPts = new List <InterPt>();

                foreach (DF3DFeatureClass dffc in list)
                {
                    IFeatureClass fc = dffc.GetFeatureClass();
                    if (fc == null)
                    {
                        continue;
                    }
                    IFeatureLayer fl = dffc.GetFeatureLayer();
                    if (fl != null)
                    {
                        if (fl.VisibleMask == gviViewportMask.gviViewNone)
                        {
                            continue;
                        }
                    }
                    int indexGeo = fc.GetFields().IndexOf("Geometry");
                    if (indexGeo == -1)
                    {
                        continue;
                    }

                    filter.Geometry = l;
                    IFdeCursor cursor = null;
                    IRowBuffer row    = null;
                    try
                    {
                        cursor = fc.Search(filter, false);
                        while ((row = cursor.NextRow()) != null)
                        {
                            if (!row.IsNull(indexGeo))
                            {
                                IGeometry geo = row.GetValue(indexGeo) as IGeometry;
                                if (geo.GeometryType == gviGeometryType.gviGeometryModelPoint)
                                {
                                    IModelPoint        modelPoint = geo as IModelPoint;
                                    IModel             model      = (fc.FeatureDataSet as IResourceManager).GetModel(modelPoint.ModelName);
                                    IGeometryConvertor gc         = new GeometryConvertor();
                                    IMultiTriMesh      triMesh    = gc.ModelPointToTriMesh(model, modelPoint, false);
                                    if (triMesh != null)
                                    {
                                        IVector3 v3 = triMesh.LineSegmentIntersect(l);
                                        if (v3 != null)
                                        {
                                            IPoint pttemp = this._geoFactory.CreatePoint(gviVertexAttribute.gviVertexAttributeZ);
                                            pttemp.X = v3.X;
                                            pttemp.Y = v3.Y;
                                            pttemp.Z = v3.Z;
                                            double dis = (pttemp.X - line.StartPoint.X) * (pttemp.X - line.StartPoint.X) +
                                                         (pttemp.Y - line.StartPoint.Y) * (pttemp.Y - line.StartPoint.Y) +
                                                         (pttemp.Z - line.StartPoint.Z) * (pttemp.Z - line.StartPoint.Z);
                                            InterPt ip = new InterPt();
                                            ip.pt  = pttemp;
                                            ip.dis = dis;
                                            listInterPts.Add(ip);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                    finally
                    {
                        if (row != null)
                        {
                            System.Runtime.InteropServices.Marshal.ReleaseComObject(row);
                            row = null;
                        }
                        if (cursor != null)
                        {
                            System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor);
                            cursor = null;
                        }
                    }
                }
                if (listInterPts.Count > 0)
                {
                    this._rLine.VisibleMask = gviViewportMask.gviViewNone;
                    listInterPts.Sort(new CmpInterPt());
                    IPoint    pt        = listInterPts[0].pt;
                    IPolyline lineStart = this._geoFactory.CreateGeometry(gviGeometryType.gviGeometryPolyline, gviVertexAttribute.gviVertexAttributeZ) as IPolyline;
                    lineStart.AppendPoint(line.StartPoint);
                    lineStart.AppendPoint(pt);
                    ICurveSymbol csS = new CurveSymbolClass();
                    csS.Color = 0xff0000ff;
                    csS.Width = -2;
                    IRenderPolyline rLineStart = this._3DControl.ObjectManager.CreateRenderPolyline(lineStart, csS, this._3DControl.ProjectTree.RootID);
                    this._listRes.Add(rLineStart.Guid);

                    IPolyline lineEnd = this._geoFactory.CreateGeometry(gviGeometryType.gviGeometryPolyline, gviVertexAttribute.gviVertexAttributeZ) as IPolyline;
                    lineEnd.AppendPoint(line.EndPoint);
                    lineEnd.AppendPoint(pt);
                    ICurveSymbol csE = new CurveSymbolClass();
                    csE.Color = 0xffff0000;
                    csE.Width = -2;
                    IRenderPolyline rLineEnd = this._3DControl.ObjectManager.CreateRenderPolyline(lineEnd, csE, this._3DControl.ProjectTree.RootID);
                    this._listRes.Add(rLineEnd.Guid);
                }
                else
                {
                    this._rLine.VisibleMask = gviViewportMask.gviViewNone;
                    ICurveSymbol csS = new CurveSymbolClass();
                    csS.Color = 0xff0000ff;
                    csS.Width = -2;
                    IRenderPolyline rLine = this._3DControl.ObjectManager.CreateRenderPolyline(line, csS, this._3DControl.ProjectTree.RootID);
                    this._listRes.Add(rLine.Guid);
                }
            }
            catch (Exception ex)
            {
            }
            finally
            {
                WaitForm.Stop();
            }
        }
Exemplo n.º 17
0
        void axRenderControl1_RcMouseClickSelect(IPickResult PickResult, IPoint IntersectPoint, gviModKeyMask Mask, gviMouseSelectMode EventSender)
        {
            //删除包围框
            for (int i = 0; i < rPolylinelist.Count; i++)
            {
                this.axRenderControl1.ObjectManager.DeleteObject((rPolylinelist[i] as IRenderPolyline).Guid);
            }
            rPolylinelist.Clear();
            for (int i = 0; i < rPolylinelistWhole.Count; i++)
            {
                this.axRenderControl1.ObjectManager.DeleteObject((rPolylinelistWhole[i] as IRenderPolyline).Guid);
            }
            rPolylinelistWhole.Clear();

            for (int i = 0; i < tableLabelList.Count; i++)
            {
                this.axRenderControl1.ObjectManager.DeleteObject((tableLabelList[i] as ITableLabel).Guid);
            }
            tableLabelList.Clear();

            for (int i = 0; i < modelpointList.Count; i++)
            {
                this.axRenderControl1.ObjectManager.DeleteObject((modelpointList[i] as IRenderModelPoint).Guid);
            }
            modelpointList.Clear();

            if (rpl1 != null)
            {
                this.axRenderControl1.ObjectManager.DeleteObject(rpl1.Guid);
            }
            if (rpl2 != null)
            {
                this.axRenderControl1.ObjectManager.DeleteObject(rpl2.Guid);
            }

            this.axRenderControl1.HighlightHelper.SetRegion(null);

            if (EventSender == gviMouseSelectMode.gviMouseSelectClick)
            {
                IPickResult pr = PickResult;
                if (pr == null)
                {
                    return;
                }
                if (pr.Type == gviObjectType.gviObject3DTileLayer)
                {
                    if (Mode == 1)
                    {
                        IPoint intersectPoint          = IntersectPoint;
                        IRelationalOperator2D relation = intersectPoint as IRelationalOperator2D;

                        foreach (IFeatureClass fc in fcMap.Keys)
                        {
                            List <string> geoNames = fcMap[fc] as List <string>;
                            if (geoNames.Count == 0)
                            {
                                continue;
                            }

                            IFdeCursor        cursor = null;
                            IRowBuffer        row    = null;
                            List <IRowBuffer> list   = new List <IRowBuffer>();
                            try
                            {
                                ISpatialFilter filter = new SpatialFilter();
                                filter.Geometry      = intersectPoint;
                                filter.SpatialRel    = gviSpatialRel.gviSpatialRelEnvelope;
                                filter.GeometryField = "Geometry";
                                cursor = fc.Search(filter, false);
                                while ((row = cursor.NextRow()) != null)
                                {
                                    list.Add(row);
                                }
                                //开始遍历
                                foreach (IRowBuffer r in list)
                                {
                                    int geometryIndex = -1;
                                    geometryIndex = r.FieldIndex(geoNames[0].ToString());
                                    if (geometryIndex != -1)
                                    {
                                        IGeometry polygon = r.GetValue(geometryIndex) as IGeometry;
                                        if (relation.Within2D(polygon))
                                        {
                                            this.axRenderControl1.HighlightHelper.SetRegion(polygon);
                                        }
                                    }
                                }
                            }
                            catch (System.Exception ex)
                            {
                                if (ex.GetType().Name.Equals("UnauthorizedAccessException"))
                                {
                                    MessageBox.Show("需要标准runtime授权");
                                }
                                else
                                {
                                    MessageBox.Show(ex.Message);
                                }
                            }
                            finally
                            {
                                if (cursor != null)
                                {
                                    //System.Runtime.InteropServices.//Marshal.ReleaseComObject(cursor);
                                    cursor = null;
                                }
                            }

                            if (Mask != gviModKeyMask.gviModKeyCtrl && Mask != gviModKeyMask.gviModKeyShift)
                            {
                                if (list.Count > 0)
                                {
                                    break;
                                }
                            }
                        }
                    }
                    else if (Mode == 2)
                    {
                        this.axRenderControl1.Camera.GetCamera2(out cameraPoint, out cameraAngle);
                        IProximityOperator disOperator = cameraPoint as IProximityOperator;
                        double             length      = disOperator.Distance3D(IntersectPoint);
                        //向相机方向延伸n米:n跟眼睛到交点距离有关,当距离远时n大,当距离近时n小。
                        factor = length * 0.001;

                        IPoint    aimingPoint      = this.axRenderControl1.Camera.GetAimingPoint2(IntersectPoint, cameraAngle, factor);
                        IPoint    sourcePoint      = this.axRenderControl1.Camera.GetAimingPoint2(IntersectPoint, cameraAngle, -factor);
                        IPolyline intersetPolyline = geoFactory.CreateGeometry(gviGeometryType.gviGeometryPolyline, gviVertexAttribute.gviVertexAttributeZ) as IPolyline;
                        intersetPolyline.SpatialCRS = _currentCRS;
                        intersetPolyline.AppendPoint(sourcePoint);
                        //瓦片焦点可能在ModelPoint内部,导致拾取不上。因此要向intersectPoint内外各拉一定距离。
                        //intersetPolyline.AppendPoint(IntersectPoint);
                        intersetPolyline.AppendPoint(aimingPoint);

                        ICurveSymbol cs = new CurveSymbol();
                        cs.Color = System.Drawing.Color.Yellow;
                        cs.Width = -5;
                        rpl1     = this.axRenderControl1.ObjectManager.CreateRenderPolyline(intersetPolyline, cs, rootId);
                        rpl1.Glow(-1);

                        //IPolyline intersetPolyline2 = geoFactory.CreateGeometry(gviGeometryType.gviGeometryPolyline, gviVertexAttribute.gviVertexAttributeZ) as IPolyline;
                        //intersetPolyline2.AppendPoint(cameraPoint);
                        //intersetPolyline2.AppendPoint(IntersectPoint);
                        //cs.Color = System.Drawing.Color.Yellow;
                        //rpl2 = this.axRenderControl1.ObjectManager.CreateRenderPolyline(intersetPolyline2, cs, rootId);
                        //rpl2.Glow(-1);


                        foreach (IFeatureClass fc in fcMap.Keys)
                        {
                            ISpatialFilter sp = new SpatialFilter();
                            sp.Geometry      = intersetPolyline;
                            sp.SpatialRel    = gviSpatialRel.gviSpatialRelIntersects;
                            sp.GeometryField = "Geometry";
                            IFdeCursor cursor = null;
                            try
                            {
                                cursor = fc.Search(sp, false);
                                IRowBuffer row = null;
                                while ((row = cursor.NextRow()) != null)
                                {
                                    int         index = row.FieldIndex("Geometry");
                                    IModelPoint mp    = row.GetValue(index) as IModelPoint;
                                    //DrawEnvelope(mp.Envelope, mp.SpatialCRS, out rPolylinelist);
                                    //rPolylinelistWhole.AddRange(rPolylinelist);

                                    //创建RenderModelPoint,显示轮廓线
                                    //IModelPointSymbol mps = new ModelPointSymbol();
                                    //mps.Color = 0; //防止与瓦片同时显示时打架
                                    //mps.EnableColor = true;
                                    //mps.SetResourceDataSet(fc.FeatureDataSet);
                                    //IRenderModelPoint rmp = this.axRenderControl1.ObjectManager.CreateRenderModelPoint(mp, mps, rootId);
                                    //rmp.ShowOutline = true;
                                    //modelpointList.Add(rmp);

                                    //创建RenderModelPoint,禁止深度检测
                                    IModelPointSymbol mps = new ModelPointSymbol();
                                    mps.Color         = System.Drawing.Color.Red;
                                    mps.EnableColor   = true;
                                    mps.EnableTexture = false;
                                    mps.SetResourceDataSet(fc.FeatureDataSet);
                                    IRenderModelPoint rmp = this.axRenderControl1.ObjectManager.CreateRenderModelPoint(mp, mps, rootId);
                                    rmp.DepthTestMode = gviDepthTestMode.gviDepthTestDisable; //防止与瓦片同时显示时打架
                                    modelpointList.Add(rmp);

                                    //创建TableLabel
                                    if (fde_point == null)
                                    {
                                        fde_point = (new GeometryFactory()).CreatePoint(gviVertexAttribute.gviVertexAttributeZ);
                                    }
                                    fde_point.Position   = mp.Position;
                                    fde_point.SpatialCRS = mp.SpatialCRS;
                                    tableLabelList.Add(DrawTableLabel(row, fde_point));
                                }
                            }
                            catch (COMException ex)
                            {
                                System.Diagnostics.Trace.WriteLine(ex.Message);
                            }
                            finally
                            {
                                if (cursor != null)
                                {
                                    //System.Runtime.InteropServices.//Marshal.ReleaseComObject(cursor);
                                    cursor = null;
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 18
0
 // Shap数据中含各顶点高程数据
 private bool GetPipeLineVertexs(IGeometry geo, double sHeight, double eHeight, out IPolyline route)
 {
     route = null;
     try
     {
         IPolyline polyline = null;
         if ((geo == null) || ((polyline = geo as IPolyline) == null))
         {
             return(false);
         }
         IPoint pointValue = null;
         route = DrawGeometry.geoFactory.CreateGeometry(gviGeometryType.gviGeometryPolyline, gviVertexAttribute.gviVertexAttributeZ) as IPolyline;
         if (polyline.PointCount == 2)
         {
             pointValue   = polyline.StartPoint.Clone2(gviVertexAttribute.gviVertexAttributeZ) as IPoint;
             pointValue.Z = sHeight;
             route.AppendPoint(pointValue);
             pointValue   = polyline.EndPoint.Clone2(gviVertexAttribute.gviVertexAttributeZ) as IPoint;
             pointValue.Z = eHeight;
             route.AppendPoint(pointValue);
         }
         else
         {
             IPoint      point;
             Stack <int> stack = new Stack <int>();
             double      num4  = eHeight - sHeight;
             if (Math.Abs(num4) < 0.0015)
             {
                 point = null;
                 for (int i = 0; i < polyline.PointCount; i++)
                 {
                     pointValue = polyline.GetPoint(i).Clone2(gviVertexAttribute.gviVertexAttributeZ) as IPoint;
                     if (i < 1)
                     {
                         pointValue.Z = sHeight;
                         route.AppendPoint(pointValue);
                         point = pointValue;
                     }
                     else if (Math.Sqrt(((pointValue.X - point.X) * (pointValue.X - point.X)) + ((pointValue.Y - point.Y) * (pointValue.Y - point.Y))) < (this._dia1 * 1.5))
                     {
                         stack.Push(i);
                     }
                     else
                     {
                         pointValue.Z = sHeight;
                         route.AppendPoint(pointValue);
                         point = pointValue;
                     }
                 }
             }
             else
             {
                 double    num3   = sHeight;
                 IPolyline o      = polyline.Clone2(gviVertexAttribute.gviVertexAttributeNone) as IPolyline;
                 double    length = o.Length;
                 Marshal.ReleaseComObject(o);
                 point = null;
                 for (int j = 0; j < polyline.PointCount; j++)
                 {
                     pointValue = polyline.GetPoint(j).Clone2(gviVertexAttribute.gviVertexAttributeZ) as IPoint;
                     if (j < 1)
                     {
                         pointValue.Z = sHeight;
                         route.AppendPoint(pointValue);
                         point = pointValue;
                     }
                     else
                     {
                         double num2;
                         if ((num2 = Math.Sqrt(((pointValue.X - point.X) * (pointValue.X - point.X)) + ((pointValue.Y - point.Y) * (pointValue.Y - point.Y)))) < (this._dia1 * 1.5))
                         {
                             stack.Push(j);
                         }
                         else
                         {
                             num3        += (num2 / length) * num4;
                             pointValue.Z = num3;
                             route.AppendPoint(pointValue);
                             point = pointValue;
                         }
                     }
                 }
             }
             while (stack.Count > 0)
             {
                 polyline.RemovePoints(stack.Pop(), 1);
             }
         }
         return(true);
     }
     catch (Exception exception)
     {
         return(false);
     }
 }
Exemplo n.º 19
0
        void axRenderControl1_RcMouseClickSelect(IPickResult PickResult, IPoint IntersectPoint, gviModKeyMask Mask, gviMouseSelectMode EventSender)
        {
            if (PickResult.Type == gviObjectType.gviObjectLabel)
            {
                ILabelPickResult tlpr = PickResult as ILabelPickResult;
                gviObjectType    type = tlpr.Type;
                ILabel           fl   = tlpr.Label;
                MessageBox.Show("拾取到" + type + "类型,内容为" + fl.Text);
            }
            else if (PickResult.Type == gviObjectType.gviObjectRenderModelPoint)
            {
                IRenderModelPointPickResult tlpr = PickResult as IRenderModelPointPickResult;
                gviObjectType     type           = tlpr.Type;
                IRenderModelPoint fl             = tlpr.ModelPoint;
                MessageBox.Show("拾取到" + type + "类型,模型名称为" + fl.ModelName);
            }
            else if (PickResult.Type == gviObjectType.gviObjectRenderPoint)
            {
                IRenderPointPickResult tlpr = PickResult as IRenderPointPickResult;
                gviObjectType          type = tlpr.Type;
                IRenderPoint           fl   = tlpr.Point;
                MessageBox.Show("拾取到" + type + "类型,大小为" + fl.Symbol.Size);
            }
            else if (PickResult.Type == gviObjectType.gviObjectRenderPolyline)
            {
                IRenderPolylinePickResult tlpr = PickResult as IRenderPolylinePickResult;
                gviObjectType             type = tlpr.Type;
                IRenderPolyline           fl   = tlpr.Polyline;
                MessageBox.Show("拾取到" + type + "类型,GUID为" + fl.Guid);
            }
            else if (PickResult.Type == gviObjectType.gviObjectRenderPolygon)
            {
                IRenderPolygonPickResult tlpr = PickResult as IRenderPolygonPickResult;
                gviObjectType            type = tlpr.Type;
                IRenderPolygon           fl   = tlpr.Polygon;
                MessageBox.Show("拾取到" + type + "类型,GUID为" + fl.Guid);
            }
            else if (PickResult.Type == gviObjectType.gviObjectRenderPOI)
            {
                IRenderPOIPickResult tlpr = PickResult as IRenderPOIPickResult;
                gviObjectType        type = tlpr.Type;
                IRenderPOI           fl   = tlpr.POI;
                MessageBox.Show("拾取到" + type + "类型,名称为" + ((IPOI)fl.GetFdeGeometry()).Name);
            }
            else if (PickResult.Type == gviObjectType.gviObjectTerrainRegularPolygon)
            {
                ITerrainRegularPolygonPickResult regPolygonPick = PickResult as ITerrainRegularPolygonPickResult;
                gviObjectType          type       = regPolygonPick.Type;
                ITerrainRegularPolygon regPolygon = regPolygonPick.TerrainRegularPolygon;
                MessageBox.Show("拾取到" + type + "类型,geometryCount为" + regPolygon.GetFdeGeometry().GeometryType);
            }
            else if (PickResult.Type == gviObjectType.gviObjectTerrainArrow)
            {
                ITerrainArrowPickResult arrowPickResult = PickResult as ITerrainArrowPickResult;
                gviObjectType           type            = arrowPickResult.Type;
                ITerrainArrow           arrow           = arrowPickResult.TerrainArrow;
                MessageBox.Show("拾取到" + type + "类型,geometryType" + arrow.GetFdeGeometry().GeometryType);
            }
            else if (PickResult.Type == gviObjectType.gviObjectReferencePlane)
            {
                switch (this.toolStripComboBoxObjectManager.Text)
                {
                case "CreateLabel":
                {
                    label                     = this.axRenderControl1.ObjectManager.CreateLabel(rootId);
                    label.Text                = "我是testlabel";
                    label.Position            = IntersectPoint;
                    textSymbol                = new TextSymbol();
                    textAttribute             = new TextAttribute();
                    textAttribute.TextColor   = System.Drawing.Color.Yellow;
                    textAttribute.TextSize    = 20;
                    textAttribute.Underline   = true;
                    textAttribute.Font        = "楷体";
                    textSymbol.TextAttribute  = textAttribute;
                    textSymbol.VerticalOffset = 10;
                    textSymbol.DrawLine       = true;
                    textSymbol.MarginColor    = System.Drawing.Color.Yellow;
                    label.TextSymbol          = textSymbol;
                    this.axRenderControl1.Camera.FlyToObject(label.Guid, gviActionCode.gviActionFlyTo);
                }
                break;

                case "CreateRenderModelPoint":
                {
                    if (gfactory == null)
                    {
                        gfactory = new GeometryFactory();
                    }

                    string tmpOSGPath = (strMediaPath + @"\osg\Buildings\Apartment\Apartment.osg");
                    fde_modelpoint = gfactory.CreateGeometry(gviGeometryType.gviGeometryModelPoint,
                                                             gviVertexAttribute.gviVertexAttributeZ) as IModelPoint;
                    fde_modelpoint.SetCoords(IntersectPoint.X, IntersectPoint.Y, IntersectPoint.Z, 0, 0);
                    fde_modelpoint.ModelName = tmpOSGPath;
                    rmodelpoint = this.axRenderControl1.ObjectManager.CreateRenderModelPoint(fde_modelpoint, null, rootId);
                    rmodelpoint.MaxVisibleDistance = double.MaxValue;
                    rmodelpoint.MinVisiblePixels   = 0;
                    rmodelpoint.ShowOutline        = checkShowOutline.Checked;
                    IEulerAngle angle = new EulerAngle();
                    angle.Set(0, -20, 0);
                    this.axRenderControl1.Camera.LookAt(IntersectPoint.Position, 100, angle);
                }
                break;

                case "CreateRenderPoint":
                {
                    if (gfactory == null)
                    {
                        gfactory = new GeometryFactory();
                    }

                    fde_point = (IPoint)gfactory.CreateGeometry(gviGeometryType.gviGeometryPoint,
                                                                gviVertexAttribute.gviVertexAttributeZ);
                    fde_point.SetCoords(IntersectPoint.X, IntersectPoint.Y, IntersectPoint.Z, 0, 0);

                    pointSymbol           = new SimplePointSymbol();
                    pointSymbol.FillColor = System.Drawing.Color.Red;
                    pointSymbol.Size      = 10;
                    rpoint             = this.axRenderControl1.ObjectManager.CreateRenderPoint(fde_point, pointSymbol, rootId);
                    rpoint.ShowOutline = checkShowOutline.Checked;
                    this.axRenderControl1.Camera.FlyToObject(rpoint.Guid, gviActionCode.gviActionFlyTo);
                }
                break;

                case "CreateRenderPolyline":
                {
                    if (gfactory == null)
                    {
                        gfactory = new GeometryFactory();
                    }

                    fde_polyline = (IPolyline)gfactory.CreateGeometry(gviGeometryType.gviGeometryPolyline,
                                                                      gviVertexAttribute.gviVertexAttributeZ);
                    fde_point = (IPoint)gfactory.CreateGeometry(gviGeometryType.gviGeometryPoint,
                                                                gviVertexAttribute.gviVertexAttributeZ);
                    fde_point.SetCoords(IntersectPoint.X, IntersectPoint.Y, IntersectPoint.Z, 0, 0);
                    fde_polyline.AppendPoint(fde_point);
                    fde_point.SetCoords(IntersectPoint.X + 20, IntersectPoint.Y, IntersectPoint.Z, 0, 0);
                    fde_polyline.AppendPoint(fde_point);
                    fde_point.SetCoords(IntersectPoint.X + 20, IntersectPoint.Y + 20, IntersectPoint.Z, 0, 0);
                    fde_polyline.AppendPoint(fde_point);
                    fde_point.SetCoords(IntersectPoint.X + 20, IntersectPoint.Y + 20, IntersectPoint.Z + 20, 0, 0);
                    fde_polyline.AppendPoint(fde_point);

                    lineSymbol            = new CurveSymbol();
                    lineSymbol.Color      = System.Drawing.Color.Red;     // 紫红色
                    rpolyline             = this.axRenderControl1.ObjectManager.CreateRenderPolyline(fde_polyline, lineSymbol, rootId);
                    rpolyline.ShowOutline = checkShowOutline.Checked;
                    this.axRenderControl1.Camera.FlyToObject(rpolyline.Guid, gviActionCode.gviActionFlyTo);
                }
                break;

                case "CreateRenderPolygon":
                {
                    if (gfactory == null)
                    {
                        gfactory = new GeometryFactory();
                    }

                    fde_polygon = (IPolygon)gfactory.CreateGeometry(gviGeometryType.gviGeometryPolygon,
                                                                    gviVertexAttribute.gviVertexAttributeZ);

                    fde_point = (IPoint)gfactory.CreateGeometry(gviGeometryType.gviGeometryPoint,
                                                                gviVertexAttribute.gviVertexAttributeZ);
                    fde_point.SetCoords(IntersectPoint.X, IntersectPoint.Y, IntersectPoint.Z, 0, 0);
                    fde_polygon.ExteriorRing.AppendPoint(fde_point);
                    fde_point.SetCoords(IntersectPoint.X + 10, IntersectPoint.Y, IntersectPoint.Z, 0, 0);
                    fde_polygon.ExteriorRing.AppendPoint(fde_point);
                    fde_point.SetCoords(IntersectPoint.X + 10, IntersectPoint.Y + 10, IntersectPoint.Z, 0, 0);
                    fde_polygon.ExteriorRing.AppendPoint(fde_point);
                    fde_point.SetCoords(IntersectPoint.X, IntersectPoint.Y + 10, IntersectPoint.Z, 0, 0);
                    fde_polygon.ExteriorRing.AppendPoint(fde_point);

                    surfaceSymbol        = new SurfaceSymbol();
                    surfaceSymbol.Color  = System.Drawing.Color.Blue;         // 蓝色
                    rpolygon             = this.axRenderControl1.ObjectManager.CreateRenderPolygon(fde_polygon, surfaceSymbol, rootId);
                    rpolygon.ShowOutline = checkShowOutline.Checked;
                    this.axRenderControl1.Camera.FlyToObject(rpolygon.Guid, gviActionCode.gviActionFlyTo);
                }
                break;

                case "CreateRenderPOI":
                {
                    if (gfactory == null)
                    {
                        gfactory = new GeometryFactory();
                    }

                    fde_poi = (IPOI)gfactory.CreateGeometry(gviGeometryType.gviGeometryPOI, gviVertexAttribute.gviVertexAttributeZ);
                    fde_poi.SetCoords(IntersectPoint.X, IntersectPoint.Y, IntersectPoint.Z, 0, 0);
                    fde_poi.ImageName = "#(1)";
                    fde_poi.Name      = (++poiCount).ToString();
                    fde_poi.Size      = 50;
                    rpoi             = this.axRenderControl1.ObjectManager.CreateRenderPOI(fde_poi);
                    rpoi.ShowOutline = checkShowOutline.Checked;
                    this.axRenderControl1.Camera.FlyToObject(rpoi.Guid, gviActionCode.gviActionFlyTo);
                }
                break;

                case "CreateFixedBillboard":
                {
                    TextAttribute ta = new TextAttribute();
                    ta.TextSize  = 10;
                    ta.TextColor = System.Drawing.Color.Yellow;
                    IImage image     = null;
                    IModel model     = null;
                    string imageName = "";
                    this.axRenderControl1.Utility.CreateFixedBillboard("I'm fixed billboard!", ta, 50, 100, true, out model, out image, out imageName);
                    this.axRenderControl1.ObjectManager.AddModel("fixedModel", model);
                    this.axRenderControl1.ObjectManager.AddImage(imageName, image);

                    if (gfactory == null)
                    {
                        gfactory = new GeometryFactory();
                    }
                    fde_modelpoint = gfactory.CreateGeometry(gviGeometryType.gviGeometryModelPoint,
                                                             gviVertexAttribute.gviVertexAttributeZ) as IModelPoint;
                    fde_modelpoint.SetCoords(IntersectPoint.X, IntersectPoint.Y, IntersectPoint.Z, 0, 0);
                    fde_modelpoint.ModelName = "fixedModel";
                    rmodelpoint = this.axRenderControl1.ObjectManager.CreateRenderModelPoint(fde_modelpoint, null, rootId);
                    rmodelpoint.MaxVisibleDistance = double.MaxValue;
                    rmodelpoint.MinVisiblePixels   = 0;
                    rmodelpoint.ShowOutline        = checkShowOutline.Checked;
                    IEulerAngle angle = new EulerAngle();
                    angle.Set(0, -20, 0);
                    this.axRenderControl1.Camera.LookAt(IntersectPoint.Position, 100, angle);
                }
                break;

                case "CreateRegularPolygon":
                {
                    IPosition pos = new Position();
                    pos.X        = IntersectPoint.X;
                    pos.Y        = IntersectPoint.Y;
                    pos.Altitude = IntersectPoint.Z;
                    ITerrainRegularPolygon regPolygon = this.axRenderControl1.ObjectManager.CreateRegularPolygon(pos, 10, 10, System.Drawing.Color.Red, System.Drawing.Color.White, rootId);
                    this.axRenderControl1.Camera.FlyToObject(regPolygon.Guid, gviActionCode.gviActionFlyTo);
                }
                break;

                case "CreateArrow":
                {
                    IPosition pos = new Position();
                    pos.X        = IntersectPoint.X;
                    pos.Y        = IntersectPoint.Y;
                    pos.Altitude = IntersectPoint.Z;
                    ITerrainArrow regArrow = this.axRenderControl1.ObjectManager.CreateArrow(pos, 30, 4, System.Drawing.Color.Red, System.Drawing.Color.White, rootId);
                    this.axRenderControl1.Camera.FlyToObject(regArrow.Guid, gviActionCode.gviActionFlyTo);
                }
                break;
                }
            }
        }
Exemplo n.º 20
0
        private void _3DControl_RcMouseClickSelect(object sender, Gvitech.CityMaker.Controls._IRenderControlEvents_RcMouseClickSelectEvent e)
        {
            try
            {
                if (e.intersectPoint != null)
                {
                    IPoint pt1 = this._geoFactory.CreateGeometry(gviGeometryType.gviGeometryPoint, gviVertexAttribute.gviVertexAttributeZ) as IPoint;
                    pt1.X = e.intersectPoint.X;
                    pt1.Y = e.intersectPoint.Y;
                    pt1.Z = e.intersectPoint.Z;
                    if (e.eventSender == gviMouseSelectMode.gviMouseSelectClick)
                    {
                        if (!this._isStarted)
                        {
                            this.Close();
                            if (this._onStartDraw != null)
                            {
                                this._onStartDraw();
                            }
                            if (_polyline != null)
                            {
                                _polyline = null;
                            }
                            startPoint = pt1;
                            double radius = 0.0000001;
                            this._geo             = (startPoint as ITopologicalOperator2D).Buffer2D(radius, gviBufferStyle.gviBufferCapround);
                            _rPolygon             = this._3DControl.ObjectManager.CreateRenderPolygon(this._geo as IPolygon, this._surfaceSymbol, this._rootID);
                            _rPolygon.HeightStyle = this._heightStyle;

                            this._3DControl.HighlightHelper.SetRegion(this._geo);
                            this._3DControl.HighlightHelper.VisibleMask = 1;

                            _polyline = this._geoFactory.CreateGeometry(gviGeometryType.gviGeometryPolyline, gviVertexAttribute.gviVertexAttributeZ) as IPolyline;
                            _polyline.AppendPoint(pt1);
                            IPoint pt2 = pt1.Clone() as IPoint;
                            pt2.X += 0.000001;
                            _polyline.AppendPoint(pt2);
                            _rPolyline      = this._3DControl.ObjectManager.CreateRenderPolyline(_polyline, this._curveSymbol, this._3DControl.ProjectTree.RootID);
                            _label          = this._3DControl.ObjectManager.CreateLabel(this._3DControl.ProjectTree.RootID);
                            _label.Position = _polyline.Midpoint;
                            _label.Text     = _polyline.Length.ToString("0.00") + " 米";
                            ITextSymbol   ts = new TextSymbolClass();
                            TextAttribute ta = new TextAttribute();
                            ta.TextColor      = Convert.ToUInt32(SystemInfo.Instance.TextColor, 16);
                            ta.TextSize       = SystemInfo.Instance.TextSize;
                            ts.TextAttribute  = ta;
                            _label.TextSymbol = ts;
                            this._isStarted   = true;
                            this._isFinished  = false;
                        }
                        else
                        {
                            //this.End();
                            this._isStarted  = false;
                            this._isFinished = true;

                            _polyline.UpdatePoint(1, pt1);
                            _rPolyline.SetFdeGeometry(_polyline);

                            _label.Position = _polyline.Midpoint;
                            _label.Text     = _polyline.Length.ToString("0.00") + " 米";


                            double radius = Math.Sqrt((startPoint.X - pt1.X) * (startPoint.X - pt1.X)
                                                      + (startPoint.Y - pt1.Y) * (startPoint.Y - pt1.Y) + (startPoint.Z - pt1.Z) * (startPoint.Z - pt1.Z));
                            this._geo = (startPoint as ITopologicalOperator2D).Buffer2D(radius, gviBufferStyle.gviBufferCapround);
                            _rPolygon.SetFdeGeometry(this._geo);
                            this._3DControl.HighlightHelper.SetRegion(this._geo);
                            this._geo = this._geo.Clone2(gviVertexAttribute.gviVertexAttributeNone);
                            if (this._onFinishedDraw != null)
                            {
                                this._onFinishedDraw();
                            }
                        }
                    }
                    else if (e.eventSender == gviMouseSelectMode.gviMouseSelectMove)
                    {
                        if (_rPoint != null)
                        {
                            this._objectManager.DeleteObject(_rPoint.Guid);
                            System.Runtime.InteropServices.Marshal.ReleaseComObject(_rPoint);
                            _rPoint = null;
                        }
                        _rPoint = this._objectManager.CreateRenderPoint(pt1, this._simplePointSymbol, this._rootID);
                        if (this._isStarted)
                        {
                            _polyline.UpdatePoint(1, pt1);
                            _rPolyline.SetFdeGeometry(_polyline);

                            _label.Position = _polyline.Midpoint;
                            _label.Text     = _polyline.Length.ToString("0.00") + " 米";

                            double radius = Math.Sqrt((startPoint.X - pt1.X) * (startPoint.X - pt1.X)
                                                      + (startPoint.Y - pt1.Y) * (startPoint.Y - pt1.Y) + (startPoint.Z - pt1.Z) * (startPoint.Z - pt1.Z));
                            this._geo = (startPoint as ITopologicalOperator2D).Buffer2D(radius, gviBufferStyle.gviBufferCapround);
                            _rPolygon.SetFdeGeometry(this._geo);
                            this._3DControl.HighlightHelper.SetRegion(this._geo);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LoggingService.Error(ex.Message + "\r\n" + ex.StackTrace);
            }
        }
Exemplo n.º 21
0
        private void ClickQuery()
        {
            DF3DApplication app = DF3DApplication.Application;

            if (app == null || app.Current3DMapControl == null)
            {
                return;
            }
            try
            {
                IFeatureLayer fl = this._drawTool.GetSelectFeatureLayerPickResult().FeatureLayer;
                if (fl == null)
                {
                    return;
                }
                int           featureId = this._drawTool.GetSelectFeatureLayerPickResult().FeatureId;
                FacilityClass facc      = Dictionary3DTable.Instance.GetFacilityClassByDFFeatureClassID(fl.FeatureClassId.ToString());
                if (facc == null || facc.Name != "PipeNode")
                {
                    XtraMessageBox.Show("您选中的不是管点设施,请选择管点设施。", "提示");
                    return;
                }
                DF3DFeatureClass dffc = DF3DFeatureClassManager.Instance.GetFeatureClassByID(fl.FeatureClassId.ToString());
                if (dffc == null || dffc.GetFeatureClass() == null)
                {
                    return;
                }
                IFeatureClass fc = dffc.GetFeatureClass();
                if (this._bFinished)
                {
                    Clear();
                    this._startFCGuid = fc.Guid.ToString();
                    this._startOid    = featureId;
                    this._bFinished   = false;

                    ILabel label = app.Current3DMapControl.ObjectManager.CreateLabel(app.Current3DMapControl.ProjectTree.RootID);
                    label.Text = "起点";
                    ITextSymbol ts = new TextSymbol();
                    ts.TextAttribute.TextSize  = SystemInfo.Instance.TextSize;
                    ts.TextAttribute.TextColor = Convert.ToUInt32(SystemInfo.Instance.TextColor, 16);
                    label.TextSymbol           = ts;
                    label.Position             = this._drawTool.GetSelectPoint();
                    this._listRGuid.Add(label.Guid);
                }
                else
                {
                    if (this._startFCGuid == fc.Guid.ToString() && this._startOid == featureId)
                    {
                        XtraMessageBox.Show("您选中的是同一个管点设施。", "提示");
                        return;
                    }
                    this._bFinished = true;
                    ILabel label = app.Current3DMapControl.ObjectManager.CreateLabel(app.Current3DMapControl.ProjectTree.RootID);
                    label.Text = "终点";
                    ITextSymbol ts = new TextSymbol();
                    ts.TextAttribute.TextSize  = SystemInfo.Instance.TextSize;
                    ts.TextAttribute.TextColor = Convert.ToUInt32(SystemInfo.Instance.TextColor, 16);
                    label.TextSymbol           = ts;
                    label.Position             = this._drawTool.GetSelectPoint();
                    this._listRGuid.Add(label.Guid);
                    if (this._startFCGuid != fc.Guid.ToString())
                    {
                        XtraMessageBox.Show("您选中的不是同一类管点设施。", "提示");
                        return;
                    }
                    else
                    {
                        WaitForm.Start("正在分析...", "请稍后");
                        FacClassReg reg = FacilityInfoService.GetFacClassRegByFeatureClassID(fc.Guid.ToString());
                        if (reg == null)
                        {
                            return;
                        }
                        TopoClass tc = FacilityInfoService.GetTopoClassByFacClassCode(reg.FacClassCode);
                        if (tc == null)
                        {
                            return;
                        }
                        TopoNetwork net = tc.GetNetwork();
                        if (net == null)
                        {
                            XtraMessageBox.Show("构建拓扑网络失败!", "提示");
                            return;
                        }
                        else
                        {
                            string        startId = this._startFCGuid + "_" + this._startOid.ToString();
                            string        endId   = fc.Guid.ToString() + "_" + featureId.ToString();
                            List <string> path;
                            double        shortestLength = net.SPFA(startId, endId, out path);
                            if ((shortestLength > 0.0 && shortestLength != double.MaxValue) || (path != null && path.Count > 0))
                            {
                                List <IPoint> listPt = new List <IPoint>();
                                foreach (string nodeId in path)
                                {
                                    int              index    = nodeId.LastIndexOf("_");
                                    string           fcguid   = nodeId.Substring(0, index);
                                    string           oid      = nodeId.Substring(index + 1, nodeId.Length - index - 1);
                                    DF3DFeatureClass dffcTemp = DF3DFeatureClassManager.Instance.GetFeatureClassByID(fcguid);
                                    if (dffcTemp == null || dffcTemp.GetFeatureClass() == null)
                                    {
                                        continue;
                                    }
                                    if (dffcTemp.GetFacilityClassName() != "PipeNode")
                                    {
                                        continue;
                                    }
                                    IQueryFilter filter = new QueryFilter();
                                    filter.WhereClause = "oid = " + oid;
                                    filter.SubFields   = "oid,Shape";
                                    IRowBuffer row    = null;
                                    IFdeCursor cursor = null;
                                    try
                                    {
                                        cursor = dffcTemp.GetFeatureClass().Search(filter, false);
                                        while ((row = cursor.NextRow()) != null)
                                        {
                                            if (!row.IsNull(1) && (row.GetValue(1) is IGeometry))
                                            {
                                                IGeometry geo = row.GetValue(1) as IGeometry;
                                                switch (geo.GeometryType)
                                                {
                                                case gviGeometryType.gviGeometryPoint:
                                                    IPoint pt = geo as IPoint;
                                                    pt.Z = pt.Z + 1;
                                                    listPt.Add(pt);
                                                    break;
                                                }
                                            }
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                    }
                                    finally
                                    {
                                        if (cursor != null)
                                        {
                                            System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor);
                                            cursor = null;
                                        }
                                        if (row != null)
                                        {
                                            System.Runtime.InteropServices.Marshal.ReleaseComObject(row);
                                            row = null;
                                        }
                                    }
                                }
                                IPolyline polyline = (new GeometryFactory()).CreateGeometry(gviGeometryType.gviGeometryPolyline, gviVertexAttribute.gviVertexAttributeZ) as IPolyline;
                                foreach (IPoint pt in listPt)
                                {
                                    ISimplePointSymbol ps = new SimplePointSymbol();
                                    ps.Size      = 5;
                                    ps.Style     = gviSimplePointStyle.gviSimplePointCircle;
                                    ps.FillColor = Convert.ToUInt32(SystemInfo.Instance.FillColor, 16);
                                    IRenderPoint rp = app.Current3DMapControl.ObjectManager.CreateRenderPoint(pt, ps, app.Current3DMapControl.ProjectTree.RootID);
                                    rp.Glow(5000);
                                    polyline.AppendPoint(pt);
                                    this._listRGuid.Add(rp.Guid);
                                }
                                ICurveSymbol cs = new CurveSymbol();
                                cs.Color = Convert.ToUInt32(SystemInfo.Instance.LineColor, 16);
                                cs.Width = -5;
                                IRenderPolyline rpl = app.Current3DMapControl.ObjectManager.CreateRenderPolyline(polyline, cs, app.Current3DMapControl.ProjectTree.RootID);
                                rpl.Glow(5000);
                                this._listRGuid.Add(rpl.Guid);
                            }
                            else
                            {
                                XtraMessageBox.Show("两点不连通!", "提示");
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show("分析出错!", "提示");
            }
            finally
            {
                WaitForm.Stop();
            }
        }
Exemplo n.º 22
0
        private void AddRecord()
        {
            try
            {
                this.beforeRowBufferMap.Clear();
                SelectCollection.Instance().Clear();
                DF3DFeatureClass featureClassInfo = CommonUtils.Instance().CurEditLayer;
                if (featureClassInfo == null)
                {
                    return;
                }
                IFeatureClass fc = featureClassInfo.GetFeatureClass();
                if (fc == null)
                {
                    return;
                }
                IFeatureLayer fl = featureClassInfo.GetFeatureLayer();
                if (fl == null)
                {
                    return;
                }
                IFieldInfoCollection fields = fc.GetFields();
                int indexGeo = fields.IndexOf(fl.GeometryFieldName);
                if (indexGeo == -1)
                {
                    return;
                }
                IFieldInfo fiGeo = fields.Get(indexGeo);
                if (fiGeo == null || fiGeo.GeometryDef == null)
                {
                    return;
                }

                IGeometry geo = this._drawTool.GetGeo();
                if (geo.GeometryType != gviGeometryType.gviGeometryPolyline)
                {
                    return;
                }
                IPolyline line   = geo as IPolyline;
                IPolyline geoOut = this._geoFact.CreateGeometry(gviGeometryType.gviGeometryPolyline, fiGeo.GeometryDef.VertexAttribute) as IPolyline;
                for (int i = 0; i < line.PointCount; i++)
                {
                    IPoint ptGet  = line.GetPoint(i);
                    IPoint pttemp = ptGet.Clone2(fiGeo.GeometryDef.VertexAttribute) as IPoint;
                    if (fiGeo.GeometryDef.HasZ)
                    {
                        pttemp.SetCoords(ptGet.X, ptGet.Y, ptGet.Z, 0, 0);
                    }
                    else
                    {
                        pttemp.SetCoords(ptGet.X, ptGet.Y, 0, 0, 0);
                    }
                    geoOut.AppendPoint(pttemp);
                }

                IRowBufferCollection rowCol = new RowBufferCollection();
                IRowBufferFactory    fac    = new RowBufferFactory();
                IRowBuffer           row    = fac.CreateRowBuffer(fields);
                row.SetValue(indexGeo, geoOut);
                foreach (DataRow dr in this._dt.Rows)
                {
                    IFieldInfo fi = dr["F"] as IFieldInfo;
                    if (fi == null)
                    {
                        continue;
                    }
                    string fn    = fi.Name;
                    int    index = fields.IndexOf(fn);
                    if (index != -1)
                    {
                        if (dr["FV"] == null)
                        {
                            row.SetNull(index);
                        }
                        else
                        {
                            string strobj = dr["FV"].ToString();
                            bool   bRes   = false;
                            switch (fi.FieldType)
                            {
                            case gviFieldType.gviFieldBlob:
                            case gviFieldType.gviFieldGeometry:
                            case gviFieldType.gviFieldUnknown:
                                break;

                            case gviFieldType.gviFieldFloat:
                                float f;
                                bRes = float.TryParse(strobj, out f);
                                if (bRes)
                                {
                                    row.SetValue(index, f);
                                }
                                else
                                {
                                    row.SetNull(index);
                                }
                                break;

                            case gviFieldType.gviFieldDouble:
                                double d;
                                bRes = double.TryParse(strobj, out d);
                                if (bRes)
                                {
                                    row.SetValue(index, d);
                                }
                                else
                                {
                                    row.SetNull(index);
                                }
                                break;

                            case gviFieldType.gviFieldFID:
                            case gviFieldType.gviFieldUUID:
                            case gviFieldType.gviFieldInt16:
                                Int16 i16;
                                bRes = Int16.TryParse(strobj, out i16);
                                if (bRes)
                                {
                                    row.SetValue(index, i16);
                                }
                                else
                                {
                                    row.SetNull(index);
                                }
                                break;

                            case gviFieldType.gviFieldInt32:
                                Int32 i32;
                                bRes = Int32.TryParse(strobj, out i32);
                                if (bRes)
                                {
                                    row.SetValue(index, i32);
                                }
                                else
                                {
                                    row.SetNull(index);
                                }
                                break;

                            case gviFieldType.gviFieldInt64:
                                Int64 i64;
                                bRes = Int64.TryParse(strobj, out i64);
                                if (bRes)
                                {
                                    row.SetValue(index, i64);
                                }
                                else
                                {
                                    row.SetNull(index);
                                }
                                break;;

                            case gviFieldType.gviFieldString:
                                row.SetValue(index, strobj);
                                break;

                            case gviFieldType.gviFieldDate:
                                DateTime dt;
                                bRes = DateTime.TryParse(strobj, out dt);
                                if (bRes)
                                {
                                    row.SetValue(index, dt);
                                }
                                else
                                {
                                    row.SetNull(index);
                                }
                                break;

                            default:
                                break;
                            }
                        }
                    }
                }
                rowCol.Add(row);
                beforeRowBufferMap[featureClassInfo] = rowCol;
                UpdateDatabase();
            }
            catch (Exception ex)
            {
            }
        }
Exemplo n.º 23
0
        private void AddRecord()
        {
            try
            {
                this.beforeRowBufferMap.Clear();
                SelectCollection.Instance().Clear();
                if (reg == null)
                {
                    return;
                }
                FacStyleClass style = this.cmbStyle.EditValue as FacStyleClass;
                if (style == null)
                {
                    return;
                }
                SubClass sc = this.cmbClassify.EditValue as SubClass;

                DF3DFeatureClass featureClassInfo = CommonUtils.Instance().CurEditLayer;
                if (featureClassInfo == null)
                {
                    return;
                }
                IFeatureClass fc = featureClassInfo.GetFeatureClass();
                if (fc == null)
                {
                    return;
                }
                IResourceManager manager = fc.FeatureDataSet as IResourceManager;
                if (manager == null)
                {
                    return;
                }
                IFeatureLayer fl = featureClassInfo.GetFeatureLayer();
                if (fl == null)
                {
                    return;
                }
                IFieldInfoCollection fields = fc.GetFields();
                int indexOid = fields.IndexOf(fc.FidFieldName);
                if (indexOid == -1)
                {
                    return;
                }
                int mpindex = fields.IndexOf(fl.GeometryFieldName);
                if (mpindex == -1)
                {
                    return;
                }
                int indexShape = fields.IndexOf("Shape");
                if (indexShape == -1)
                {
                    return;
                }
                int indexFootPrint = fields.IndexOf("FootPrint");
                if (indexFootPrint == -1)
                {
                    return;
                }
                int indexStyleId = fields.IndexOf("StyleId");
                if (indexStyleId == -1)
                {
                    return;
                }
                int indexFacilityId = fields.IndexOf("FacilityId");
                if (indexFacilityId == -1)
                {
                    return;
                }

                IFieldInfo fiShape = fields.Get(indexShape);
                if (fiShape == null || fiShape.GeometryDef == null)
                {
                    return;
                }

                IGeometry geo = this._drawTool.GetGeo();
                if (geo.GeometryType != gviGeometryType.gviGeometryPolygon)
                {
                    return;
                }

                IGeometry geoOut = null;
                if (this._drawType == DrawType.Polyline)
                {
                    IPolygon  polygon = geo as IPolygon;
                    IPolyline geoOut1 = this._geoFact.CreateGeometry(gviGeometryType.gviGeometryPolyline, fiShape.GeometryDef.VertexAttribute) as IPolyline;
                    for (int i = 0; i < polygon.ExteriorRing.PointCount; i++)
                    {
                        IPoint ptGet  = polygon.ExteriorRing.GetPoint(i);
                        IPoint pttemp = ptGet.Clone2(fiShape.GeometryDef.VertexAttribute) as IPoint;
                        if (fiShape.GeometryDef.HasZ)
                        {
                            pttemp.SetCoords(ptGet.X, ptGet.Y, ptGet.Z, 0, 0);
                        }
                        else
                        {
                            pttemp.SetCoords(ptGet.X, ptGet.Y, 0, 0, 0);
                        }
                        geoOut1.AppendPoint(pttemp);
                    }
                    geoOut = geoOut1;
                }
                else if (this._drawType == DrawType.Polygon)
                {
                    IPolygon polygon = geo as IPolygon;
                    IPolygon geoOut1 = this._geoFact.CreateGeometry(gviGeometryType.gviGeometryPolygon, fiShape.GeometryDef.VertexAttribute) as IPolygon;
                    for (int i = 0; i < polygon.ExteriorRing.PointCount; i++)
                    {
                        IPoint ptGet  = polygon.ExteriorRing.GetPoint(i);
                        IPoint pttemp = ptGet.Clone2(fiShape.GeometryDef.VertexAttribute) as IPoint;
                        if (fiShape.GeometryDef.HasZ)
                        {
                            pttemp.SetCoords(ptGet.X, ptGet.Y, ptGet.Z, 0, 0);
                        }
                        else
                        {
                            pttemp.SetCoords(ptGet.X, ptGet.Y, 0, 0, 0);
                        }
                        geoOut1.ExteriorRing.AppendPoint(pttemp);
                    }
                    geoOut = geoOut1;
                }
                if (geoOut == null)
                {
                    return;
                }

                IQueryFilter filter = new QueryFilter();
                filter.WhereClause      = "1=1";
                filter.ResultBeginIndex = 0;
                filter.ResultLimit      = 1;
                filter.PostfixClause    = "ORDER BY " + fc.FidFieldName + " desc";
                IFdeCursor cursor = null;
                cursor = fc.Search(filter, false);
                IRowBuffer rowtemp = cursor.NextRow();
                int        oid     = 0;
                if (rowtemp != null)
                {
                    oid = int.Parse(rowtemp.GetValue(indexOid).ToString());
                }
                if (cursor != null)
                {
                    System.Runtime.InteropServices.Marshal.ReleaseComObject(cursor);
                    cursor = null;
                }

                IRowBufferFactory fac = new RowBufferFactory();
                IRowBuffer        row = fac.CreateRowBuffer(fields);
                row.SetValue(indexOid, oid + 1);
                row.SetValue(indexShape, geoOut);
                row.SetValue(indexFootPrint, geoOut.Clone2(gviVertexAttribute.gviVertexAttributeNone));
                row.SetValue(indexStyleId, style.ObjectId);
                row.SetValue(indexFacilityId, BitConverter.ToString(ObjectIdGenerator.Generate()).Replace("-", string.Empty).ToLowerInvariant());
                if (sc != null)
                {
                    int indexClassify = fields.IndexOf(this._classifyName);
                    int indexGroupId  = fields.IndexOf("GroupId");
                    if (indexClassify != -1 && indexGroupId != -1)
                    {
                        row.SetValue(indexClassify, sc.Name);
                        row.SetValue(indexGroupId, sc.GroupId);
                    }
                }
                foreach (DataRow dr in this._dt.Rows)
                {
                    IFieldInfo fi = dr["F"] as IFieldInfo;
                    if (fi == null)
                    {
                        continue;
                    }
                    string fn    = fi.Name;
                    int    index = fields.IndexOf(fn);
                    if (index != -1)
                    {
                        if (dr["FV"] == null)
                        {
                            row.SetNull(index);
                        }
                        else
                        {
                            string strobj = dr["FV"].ToString();
                            bool   bRes   = false;
                            switch (fi.FieldType)
                            {
                            case gviFieldType.gviFieldBlob:
                            case gviFieldType.gviFieldGeometry:
                            case gviFieldType.gviFieldUnknown:
                                break;

                            case gviFieldType.gviFieldFloat:
                                float f;
                                bRes = float.TryParse(strobj, out f);
                                if (bRes)
                                {
                                    row.SetValue(index, f);
                                }
                                else
                                {
                                    row.SetNull(index);
                                }
                                break;

                            case gviFieldType.gviFieldDouble:
                                double d;
                                bRes = double.TryParse(strobj, out d);
                                if (bRes)
                                {
                                    row.SetValue(index, d);
                                }
                                else
                                {
                                    row.SetNull(index);
                                }
                                break;

                            case gviFieldType.gviFieldFID:
                            case gviFieldType.gviFieldUUID:
                            case gviFieldType.gviFieldInt16:
                                Int16 i16;
                                bRes = Int16.TryParse(strobj, out i16);
                                if (bRes)
                                {
                                    row.SetValue(index, i16);
                                }
                                else
                                {
                                    row.SetNull(index);
                                }
                                break;

                            case gviFieldType.gviFieldInt32:
                                Int32 i32;
                                bRes = Int32.TryParse(strobj, out i32);
                                if (bRes)
                                {
                                    row.SetValue(index, i32);
                                }
                                else
                                {
                                    row.SetNull(index);
                                }
                                break;

                            case gviFieldType.gviFieldInt64:
                                Int64 i64;
                                bRes = Int64.TryParse(strobj, out i64);
                                if (bRes)
                                {
                                    row.SetValue(index, i64);
                                }
                                else
                                {
                                    row.SetNull(index);
                                }
                                break;;

                            case gviFieldType.gviFieldString:
                                row.SetValue(index, strobj);
                                break;

                            case gviFieldType.gviFieldDate:
                                DateTime dt;
                                bRes = DateTime.TryParse(strobj, out dt);
                                if (bRes)
                                {
                                    row.SetValue(index, dt);
                                }
                                else
                                {
                                    row.SetNull(index);
                                }
                                break;

                            default:
                                break;
                            }
                        }
                    }
                }
                Fac plf = new PipeBuildFac(reg, style, row);

                IModelPoint mp          = null;
                IModel      finemodel   = null;
                IModel      simplemodel = null;
                string      name        = "";
                if (UCAuto3DCreate.RebuildModel(plf, style, out mp, out finemodel, out simplemodel, out name))
                {
                    if (finemodel == null || mp == null)
                    {
                        return;
                    }
                    mp.ModelEnvelope = finemodel.Envelope;
                    row.SetValue(mpindex, mp);
                    //if (mc != null)
                    //{
                    //    if (indexClassify != -1 && indexGroupid != -1)
                    //    {

                    //    }
                    //}
                    bool bRes = false;
                    if (!string.IsNullOrEmpty(mp.ModelName))
                    {
                        if (!manager.ModelExist(mp.ModelName))
                        {
                            if (manager.AddModel(mp.ModelName, finemodel, simplemodel))
                            {
                                bRes = true;
                            }
                        }
                        else
                        {
                            if (manager.UpdateModel(mp.ModelName, finemodel) && manager.UpdateSimplifiedModel(mp.ModelName, simplemodel))
                            {
                                bRes = true;
                            }
                        }
                    }
                    if (!bRes)
                    {
                        return;
                    }
                    IRowBufferCollection rowCol = new RowBufferCollection();
                    rowCol.Add(row);
                    beforeRowBufferMap[featureClassInfo] = rowCol;
                    UpdateDatabase();
                    app.Current3DMapControl.FeatureManager.RefreshFeatureClass(fc);
                }
            }
            catch (Exception ex)
            {
            }
        }
Exemplo n.º 24
0
 // 抽稀坐标点
 private bool SimplifyPolyline(IGeometry geo, out IPolyline route)
 {
     route = null;
     try
     {
         IPolyline polyline = null;
         if ((geo == null) || ((polyline = geo as IPolyline) == null))
         {
             return(false);
         }
         List <Vector> list  = new List <Vector>();
         IPoint        p     = null;
         IPoint        point = null;
         route = DrawGeometry.geoFactory.CreateGeometry(gviGeometryType.gviGeometryPolyline, gviVertexAttribute.gviVertexAttributeZ) as IPolyline;
         int    num2       = 0;
         IPoint pointValue = null;
         Vector vector     = null;
         Vector vector2    = null;
         Vector vector3    = null;
         Vector vector4    = null;
         if (polyline.PointCount == 2)
         {
             list.Add(new Vector(polyline.StartPoint));
             route.AppendPoint(polyline.StartPoint);
             list.Add(new Vector(polyline.EndPoint));
             route.AppendPoint(polyline.EndPoint);
         }
         else
         {
             new Stack <int>();
             p = null;
             for (int i = 0; i < polyline.PointCount; i++)
             {
                 point = polyline.GetPoint(i);
                 if (i == 0)
                 {
                     //DrawGeometry.Ocx.ObjectManager.CreateRenderPoint(point, null, this._);
                     list.Add(new Vector(point));
                     route.AppendPoint(point);
                     num2 = i;
                     p    = point;
                 }
                 else if (Math.Sqrt((((point.X - p.X) * (point.X - p.X)) + ((point.Y - p.Y) * (point.Y - p.Y))) + ((point.Z - p.Z) * (point.Z - p.Z))) < (this._dia1 / 2.0))
                 {
                     p = point;
                 }
                 else
                 {
                     vector2 = new Vector(p);
                     vector4 = new Vector(p.X - point.X, p.Y - point.Y, p.Z - point.Z);
                     if ((num2 > 0) && (num2 == (i - 1)))
                     {
                         list.Add(new Vector(p));
                         route.AppendPoint(p);
                     }
                     else if ((vector != null) && (vector3 != null))
                     {
                         pointValue = this.RadialIntersect(vector, vector3, vector2, vector4);
                         if (pointValue != null)
                         {
                             route.AppendPoint(pointValue);
                             list.Add(new Vector(pointValue.X, pointValue.Y, pointValue.Z));
                         }
                         num2 = i;
                     }
                     vector  = new Vector(point);
                     vector3 = -vector4;
                     p       = point;
                     if (i == (polyline.PointCount - 1))
                     {
                         list.Add(new Vector(point));
                         route.AppendPoint(point);
                     }
                 }
             }
         }
         return(true);
     }
     catch (Exception exception)
     {
         return(false);
     }
 }