Exemplo n.º 1
0
        private List <IPoint> DisPerseLine(IPoint pStart, IPoint pEnd, double disperse)
        {
            if (pStart == null || pEnd == null)
            {
                return(null);
            }
            List <IPoint> result = new List <IPoint>();
            IVector3      vector = new Vector3();

            vector.Set(pStart.X, pStart.Y, pStart.Z);
            IVector3 vector2 = new Vector3();

            vector2.Set(pEnd.X - pStart.X, pEnd.Y - pStart.Y, pEnd.Z - pStart.Z);
            double           length  = vector2.Length;
            int              num     = int.Parse(Math.Floor(length / disperse).ToString());
            IGeometryFactory geoFact = new GeometryFactoryClass();

            for (var i = 0; i <= num; i++)
            {
                var gvitechPoint = geoFact.CreatePoint(gviVertexAttribute.gviVertexAttributeZ);
                if (i == 0)
                {
                    gvitechPoint.X = pStart.X;
                    gvitechPoint.Y = pStart.Y;
                    gvitechPoint.Z = pStart.Z;
                }
                else
                {
                    if (i == num)
                    {
                        gvitechPoint.X = pEnd.X;
                        gvitechPoint.Y = pEnd.Y;
                        gvitechPoint.Z = pEnd.Z;
                    }
                    else
                    {
                        gvitechPoint.X = vector.X + vector2.X * i / num;
                        gvitechPoint.Y = vector.Y + vector2.Y * i / num;
                        gvitechPoint.Z = vector.Z + vector2.Z * i / num;
                    }
                }
                result.Add(gvitechPoint);
            }
            return(result);
        }
Exemplo n.º 2
0
        private void DrawBox()
        {
            try
            {
                IPolyline line = this._drawTool.GetGeo() as IPolyline;
                if (line == null || line.PointCount != 2)
                {
                    return;
                }
                DF3DApplication app = DF3DApplication.Application;
                if (app == null || app.Current3DMapControl == null)
                {
                    return;
                }


                if (this._renderBox != null)
                {
                    app.Current3DMapControl.ObjectManager.DeleteObject(this._renderBox.Guid);
                    this._renderBox = null;
                }
                if (this._renderPolygon != null)
                {
                    app.Current3DMapControl.ObjectManager.DeleteObject(this._renderPolygon.Guid);
                    this._renderPolygon = null;
                }

                double      middleZ    = (line.StartPoint.Z + line.EndPoint.Z) / 2;
                double      minZ       = middleZ + (double)this.seMinHeight.Value;
                double      maxZ       = middleZ + (double)this.seMaxHeight.Value;
                IPoint      startPoint = line.StartPoint;
                IPoint      endPoint   = line.EndPoint;
                IEulerAngle ang        = app.Current3DMapControl.Camera.GetAimingAngles2(startPoint, endPoint);
                IEulerAngle angcz      = new EulerAngle();
                angcz.Set(ang.Heading - 90, ang.Tilt, ang.Roll);
                IPoint pt1 = app.Current3DMapControl.Camera.GetAimingPoint2(startPoint, angcz, this.tbcClipDis.Value);
                IPoint pt2 = app.Current3DMapControl.Camera.GetAimingPoint2(endPoint, angcz, this.tbcClipDis.Value);

                ICRSFactory      crsFact = new CRSFactory();
                ISpatialCRS      crs     = crsFact.CreateFromWKT(app.Current3DMapControl.GetCurrentCrsWKT()) as ISpatialCRS;
                IGeometryFactory geoFact = new GeometryFactoryClass();
                IPoint           pointb1 = geoFact.CreatePoint(gviVertexAttribute.gviVertexAttributeZ);
                pointb1.SpatialCRS = crs;
                pointb1.SetCoords(startPoint.X, startPoint.Y, minZ, 0, 0);
                IPoint pointb2 = geoFact.CreatePoint(gviVertexAttribute.gviVertexAttributeZ);
                pointb2.SpatialCRS = crs;
                pointb2.SetCoords(endPoint.X, endPoint.Y, minZ, 0, 0);
                IPoint pointb3 = geoFact.CreatePoint(gviVertexAttribute.gviVertexAttributeZ);
                pointb3.SpatialCRS = crs;
                pointb3.SetCoords(pt2.X, pt2.Y, minZ, 0, 0);
                IPoint pointb4 = geoFact.CreatePoint(gviVertexAttribute.gviVertexAttributeZ);
                pointb1.SpatialCRS = crs;
                pointb4.SetCoords(pt1.X, pt1.Y, minZ, 0, 0);
                IPolygon polygonBottom = geoFact.CreateGeometry(gviGeometryType.gviGeometryPolygon, gviVertexAttribute.gviVertexAttributeZ) as IPolygon;
                polygonBottom.SpatialCRS = crs;
                polygonBottom.ExteriorRing.AppendPoint(pointb1);
                polygonBottom.ExteriorRing.AppendPoint(pointb2);
                polygonBottom.ExteriorRing.AppendPoint(pointb3);
                polygonBottom.ExteriorRing.AppendPoint(pointb4);

                IPoint pointt1 = geoFact.CreatePoint(gviVertexAttribute.gviVertexAttributeZ);
                pointt1.SpatialCRS = crs;
                pointt1.SetCoords(startPoint.X, startPoint.Y, maxZ, 0, 0);
                IPoint pointt2 = geoFact.CreatePoint(gviVertexAttribute.gviVertexAttributeZ);
                pointt2.SpatialCRS = crs;
                pointt2.SetCoords(endPoint.X, endPoint.Y, maxZ, 0, 0);
                IPoint pointt3 = geoFact.CreatePoint(gviVertexAttribute.gviVertexAttributeZ);
                pointt3.SpatialCRS = crs;
                pointt3.SetCoords(pt2.X, pt2.Y, maxZ, 0, 0);
                IPoint pointt4 = geoFact.CreatePoint(gviVertexAttribute.gviVertexAttributeZ);
                pointt4.SpatialCRS = crs;
                pointt4.SetCoords(pt1.X, pt1.Y, maxZ, 0, 0);
                IPolygon polygonTop = geoFact.CreateGeometry(gviGeometryType.gviGeometryPolygon, gviVertexAttribute.gviVertexAttributeZ) as IPolygon;
                polygonTop.SpatialCRS = crs;
                polygonTop.ExteriorRing.AppendPoint(pointt1);
                polygonTop.ExteriorRing.AppendPoint(pointt2);
                polygonTop.ExteriorRing.AppendPoint(pointt3);
                polygonTop.ExteriorRing.AppendPoint(pointt4);

                IPolygon polygon1 = geoFact.CreateGeometry(gviGeometryType.gviGeometryPolygon, gviVertexAttribute.gviVertexAttributeZ) as IPolygon;
                polygon1.SpatialCRS = crs;
                polygon1.ExteriorRing.AppendPoint(pointb1);
                polygon1.ExteriorRing.AppendPoint(pointb2);
                polygon1.ExteriorRing.AppendPoint(pointt2);
                polygon1.ExteriorRing.AppendPoint(pointt1);

                IPolygon polygon2 = geoFact.CreateGeometry(gviGeometryType.gviGeometryPolygon, gviVertexAttribute.gviVertexAttributeZ) as IPolygon;
                polygon2.SpatialCRS = crs;
                polygon2.ExteriorRing.AppendPoint(pointb1);
                polygon2.ExteriorRing.AppendPoint(pointb4);
                polygon2.ExteriorRing.AppendPoint(pointt4);
                polygon2.ExteriorRing.AppendPoint(pointt1);

                IPolygon polygon3 = geoFact.CreateGeometry(gviGeometryType.gviGeometryPolygon, gviVertexAttribute.gviVertexAttributeZ) as IPolygon;
                polygon3.SpatialCRS = crs;
                polygon3.ExteriorRing.AppendPoint(pointb2);
                polygon3.ExteriorRing.AppendPoint(pointb3);
                polygon3.ExteriorRing.AppendPoint(pointt3);
                polygon3.ExteriorRing.AppendPoint(pointt2);

                IPolygon polygon4 = geoFact.CreateGeometry(gviGeometryType.gviGeometryPolygon, gviVertexAttribute.gviVertexAttributeZ) as IPolygon;
                polygon4.SpatialCRS = crs;
                polygon4.ExteriorRing.AppendPoint(pointb3);
                polygon4.ExteriorRing.AppendPoint(pointb4);
                polygon4.ExteriorRing.AppendPoint(pointt4);
                polygon4.ExteriorRing.AppendPoint(pointt3);

                IMultiPolygon multiPolygon = geoFact.CreateGeometry(gviGeometryType.gviGeometryMultiPolygon, gviVertexAttribute.gviVertexAttributeZ) as IMultiPolygon;
                multiPolygon.SpatialCRS = crs;
                multiPolygon.AddPolygon(polygonBottom);
                multiPolygon.AddPolygon(polygonTop);
                //multiPolygon.AddPolygon(polygon1);
                multiPolygon.AddPolygon(polygon2);
                multiPolygon.AddPolygon(polygon3);
                multiPolygon.AddPolygon(polygon4);

                ISurfaceSymbol ss = new SurfaceSymbolClass();
                ss.Color = 0x550000AA;
                ICurveSymbol cs = new CurveSymbolClass();
                cs.Color            = 0xff0000AA;
                ss.BoundarySymbol   = cs;
                this._renderPolygon = app.Current3DMapControl.ObjectManager.CreateRenderPolygon(polygon1, ss, app.Current3DMapControl.ProjectTree.RootID);

                ISurfaceSymbol ss1 = new SurfaceSymbolClass();
                ss1.Color = 0x88FFFFFF;
                ICurveSymbol cs1 = new CurveSymbolClass();
                cs1.Color          = 0xffffffff;
                ss1.BoundarySymbol = cs1;
                this._renderBox    = app.Current3DMapControl.ObjectManager.CreateRenderMultiPolygon(multiPolygon, ss1, app.Current3DMapControl.ProjectTree.RootID);

                _env    = null;
                _ang    = null;
                _center = null;

                _env = new EnvelopeClass();
                double xdis = Math.Sqrt((pointb1.X - pointb2.X) * (pointb1.X - pointb2.X) + (pointb1.Y - pointb2.Y) * (pointb1.Y - pointb2.Y)) / 2;
                double ydis = Math.Sqrt((pointb1.X - pointb4.X) * (pointb1.X - pointb4.X) + (pointb1.Y - pointb4.Y) * (pointb1.Y - pointb4.Y)) / 2;
                _env.MinZ = -ydis;
                _env.MaxZ = ydis;
                _env.MinX = -xdis;
                _env.MaxX = xdis;
                _env.MinY = -(maxZ - minZ) / 2.0;
                _env.MaxY = (maxZ - minZ) / 2.0;

                _center            = geoFact.CreatePoint(gviVertexAttribute.gviVertexAttributeZ);
                _center.SpatialCRS = crs;
                _center.X          = polygonBottom.Centroid.X;
                _center.Y          = polygonBottom.Centroid.Y;
                _center.Z          = polygon1.Centroid.Z;

                _ang = new EulerAngleClass();
                _ang.Set(angcz.Heading, 0, 0);
            }
            catch (Exception ex)
            {
            }
        }
Exemplo n.º 3
0
        private void ShowFlowDirect(IFeatureLayerPickResult pr)
        {
            if (pr == null)
            {
                return;
            }
            IRowBuffer row    = null;
            IFdeCursor cursor = null;

            try
            {
                int fid = pr.FeatureId;
                DF3DFeatureClass dffc = DF3DFeatureClassManager.Instance.GetFeatureClassByID(pr.FeatureLayer.FeatureClassId.ToString());
                if (dffc == null)
                {
                    return;
                }
                IFeatureClass fc  = dffc.GetFeatureClass();
                FacilityClass fac = dffc.GetFacilityClass();
                if (fc == null || fac == null || fac.Name != "PipeLine")
                {
                    return;
                }
                DFDataConfig.Class.FieldInfo fi = fac.GetFieldInfoBySystemName("FlowDirect");
                if (fi == null)
                {
                    return;
                }
                IFieldInfoCollection fiCol = fc.GetFields();
                int index = fiCol.IndexOf(fi.Name);
                if (index == -1)
                {
                    return;
                }
                int indexShape = fiCol.IndexOf("Shape");

                IQueryFilter filter = new QueryFilter();
                filter.WhereClause = "oid=" + fid;
                cursor             = fc.Search(filter, false);
                row = cursor.NextRow();
                if (row == null)
                {
                    return;
                }

                IPolyline line = null;
                if (indexShape != -1 && !row.IsNull(indexShape))
                {
                    object obj = row.GetValue(indexShape);
                    if (obj != null && obj is IPolyline)
                    {
                        line = obj as IPolyline;
                    }
                }
                string flowDirectValue = "0";
                int    type            = 1;// 1表示具有流向字段;2表示从高到低
                if (!row.IsNull(index))
                {
                    flowDirectValue = row.GetValue(index).ToString();
                    if (flowDirectValue != "0" && flowDirectValue != "1")
                    {
                        flowDirectValue = "0";
                    }
                    type = 1;
                }
                else if (line != null)
                {
                    if (line.StartPoint.Z > line.EndPoint.Z)
                    {
                        flowDirectValue = "0";
                    }
                    else
                    {
                        flowDirectValue = "1";
                    }
                    type = 2;
                }
                if (line == null)
                {
                    return;
                }

                if (this._isAuth)
                {
                    #region 流向渲染1
                    FacClassReg reg = FacilityInfoService.GetFacClassRegByFeatureClassID(fc.Guid.ToString());
                    if (reg == null)
                    {
                        return;
                    }
                    TopoClass tc = FacilityInfoService.GetTopoClassByFacClassCode(reg.FacClassCode);
                    if (tc == null)
                    {
                        return;
                    }
                    FacStyleClass        style          = null;
                    List <FacStyleClass> facilityStyles = FacilityInfoService.GetFacStyleByFacClassCode(reg.FacClassCode);
                    if ((facilityStyles != null) && (facilityStyles.Count > 0))
                    {
                        style = facilityStyles[0];
                    }
                    PipeLineFac       plfac = new PipeLineFac(reg, style, row, tc);
                    IRenderModelPoint rmp   = null;
                    DrawGeometry.Ocx = DF3DApplication.Application.Current3DMapControl;
                    plfac.ShowFlowDirection(int.Parse(flowDirectValue), out rmp);
                    if (rmp != null)
                    {
                        this._listRender.Add(rmp.Guid);
                    }
                    #endregion
                }
                else
                {
                    #region 流向渲染2
                    IEulerAngle angle    = DF3DApplication.Application.Current3DMapControl.Camera.GetAimingAngles2(line.StartPoint, line.EndPoint);
                    double      dia      = 0.0;
                    string      diaField = fac.GetFieldInfoNameBySystemName("Diameter");
                    int         indexDia = fiCol.IndexOf(diaField);
                    if (indexDia != -1 && !row.IsNull(indexDia))
                    {
                        string diaStr    = row.GetValue(indexDia).ToString();
                        int    indexDia1 = diaStr.ToString().IndexOf('*');
                        if (indexDia1 != -1)
                        {
                            var dia1 = int.Parse(diaStr.ToString().Substring(0, indexDia1));
                            var dia2 = int.Parse(diaStr.ToString().Substring(indexDia1 + 1, diaStr.ToString().Length));
                            dia = ((dia1 > dia2) ? dia1 : dia2) * 0.001;
                        }
                        else
                        {
                            dia = int.Parse(diaStr) * 0.001;
                        }
                    }
                    List <IPoint> points = new List <IPoint>();
                    if (flowDirectValue == "0")
                    {
                        for (int i = 0; i < line.PointCount; i++)
                        {
                            IPoint pt = line.GetPoint(i);
                            pt.Z += dia / 2;
                            points.Add(pt);
                        }
                    }
                    else if (flowDirectValue == "1")
                    {
                        for (int i = line.PointCount - 1; i >= 0; i--)
                        {
                            IPoint pt = line.GetPoint(i);
                            pt.Z += dia / 2;
                            points.Add(pt);
                        }
                    }
                    for (int i = 0; i < points.Count - 1; i++)
                    {
                        IPoint pt1 = points[i];
                        var    pt2 = points[i + 1];

                        double delt = 0;
                        double _rate, _distance;
                        if (!(Math.Abs(dia) < 0.0000001))
                        {
                            delt = 2.0 * dia;
                            if (dia <= 0.5 && dia >= 0.3)
                            {
                                _rate     = 7 * dia;
                                _distance = 3 * dia / 0.4;
                            }
                            else if (dia < 0.3 && dia > 0.1)
                            {
                                _rate     = 12 * dia;
                                _distance = 6 * dia / 0.4;
                            }
                            else if (dia <= 0.1)
                            {
                                _rate     = 22 * dia;
                                _distance = 9 * dia / 0.4;
                            }
                            else
                            {
                                _rate     = 3.5 * dia;
                                _distance = 1.5 * dia / 0.4;
                            }
                        }
                        else
                        {
                            _rate     = 2.0;
                            _distance = 3.0;
                            //z = maxZ + 0.2;
                            delt = 0.2;
                        }
                        List <IPoint> list = DisPerseLine(pt1, pt2, _distance);
                        if (list.Count < 2)
                        {
                            return;
                        }
                        List <IPoint>    list1   = new List <IPoint>();
                        IGeometryFactory geoFact = new GeometryFactoryClass();
                        for (int j = 0; j < list.Count - 1; j++)
                        {
                            IPoint p = geoFact.CreatePoint(gviVertexAttribute.gviVertexAttributeZ);
                            p.X = (list[j].X + list[j + 1].X) / 2;
                            p.Y = (list[j].Y + list[j + 1].Y) / 2;
                            p.Z = (list[j].Z + list[j + 1].Z) / 2;
                            list1.Add(p);
                        }

                        for (var m = 0; m < list1.Count; m++)
                        {
                            IPosition pos = new PositionClass();
                            pos.X            = list1[m].X;
                            pos.Y            = list1[m].Y;
                            pos.Altitude     = list1[m].Z + delt;
                            pos.AltitudeType = gviAltitudeType.gviAltitudeTerrainAbsolute;
                            pos.Heading      = angle.Heading;
                            pos.Tilt         = angle.Tilt;
                            pos.Roll         = angle.Roll;
                            UInt32 color;
                            if (type == 1)
                            {
                                color = 0xFFFFFF00;
                            }
                            else
                            {
                                color = 0xFF00FFFF;
                            }
                            ITerrainArrow rArrow = DF3DApplication.Application.Current3DMapControl.ObjectManager.CreateArrow(pos, 0.8 * _rate, 3, color, color, DF3DApplication.Application.Current3DMapControl.ProjectTree.RootID);
                            this._listRender.Add(rArrow.Guid);
                        }
                    }
                    #endregion
                }
            }
            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;
                }
            }
        }
Exemplo n.º 4
0
        private void DrawControlRegion()
        {
            DF3DApplication app = DF3DApplication.Application;

            if (app == null || app.Current3DMapControl == null || !app.Current3DMapControl.Terrain.IsRegistered)
            {
                return;
            }
            if (this._renderBox != null)
            {
                app.Current3DMapControl.ObjectManager.DeleteObject(this._renderBox.Guid);
                this._renderBox = null;
            }

            IGeometry geo = this._drawTool.GetGeo();

            if (geo == null || geo.GeometryType != gviGeometryType.gviGeometryPolygon)
            {
                return;
            }
            IPolygon polygon       = geo as IPolygon;
            double   terrainHeight = 0.0;

            if (app.Current3DMapControl.Terrain.IsRegistered)
            {
                terrainHeight = app.Current3DMapControl.Terrain.GetElevation(polygon.Centroid.X, polygon.Centroid.Y, gviGetElevationType.gviGetElevationFromDatabase);
            }
            double height = double.Parse(this.seLimitHeight.Value.ToString()) + terrainHeight;

            IGeometryFactory geoFact = new GeometryFactoryClass();

            IMultiPolygon multiPolygon = geoFact.CreateGeometry(gviGeometryType.gviGeometryMultiPolygon, gviVertexAttribute.gviVertexAttributeZ) as IMultiPolygon;
            IPolygon      polygonZ     = geoFact.CreateGeometry(gviGeometryType.gviGeometryPolygon, gviVertexAttribute.gviVertexAttributeZ) as IPolygon;

            for (int i = 0; i < polygon.ExteriorRing.PointCount; i++)
            {
                IPoint ptTemp = geoFact.CreatePoint(gviVertexAttribute.gviVertexAttributeZ);
                IPoint pt1    = polygon.ExteriorRing.GetPoint(i);
                ptTemp.X = pt1.X;
                ptTemp.Y = pt1.Y;
                ptTemp.Z = height;
                polygonZ.ExteriorRing.AppendPoint(ptTemp);
            }
            multiPolygon.AddPolygon(polygonZ);
            for (int i = 0; i < polygon.ExteriorRing.PointCount - 1; i++)
            {
                IPoint   pt0      = polygon.ExteriorRing.GetPoint(i);
                IPoint   pt1      = polygon.ExteriorRing.GetPoint(i + 1);
                IPoint   pt00     = polygonZ.ExteriorRing.GetPoint(i);
                IPoint   pt11     = polygonZ.ExteriorRing.GetPoint(i + 1);
                IPolygon polygon1 = geoFact.CreateGeometry(gviGeometryType.gviGeometryPolygon, gviVertexAttribute.gviVertexAttributeZ) as IPolygon;
                polygon1.ExteriorRing.AppendPoint(pt0);
                polygon1.ExteriorRing.AppendPoint(pt1);
                polygon1.ExteriorRing.AppendPoint(pt11);
                polygon1.ExteriorRing.AppendPoint(pt00);
                multiPolygon.AddPolygon(polygon1);
            }
            IPoint   ptL0     = polygon.ExteriorRing.GetPoint(0);
            IPoint   ptL1     = polygon.ExteriorRing.GetPoint(polygon.ExteriorRing.PointCount - 1);
            IPoint   ptL00    = polygonZ.ExteriorRing.GetPoint(0);
            IPoint   ptL11    = polygonZ.ExteriorRing.GetPoint(polygon.ExteriorRing.PointCount - 1);
            IPolygon polygon2 = geoFact.CreateGeometry(gviGeometryType.gviGeometryPolygon, gviVertexAttribute.gviVertexAttributeZ) as IPolygon;

            polygon2.ExteriorRing.AppendPoint(ptL00);
            polygon2.ExteriorRing.AppendPoint(ptL11);
            polygon2.ExteriorRing.AppendPoint(ptL1);
            polygon2.ExteriorRing.AppendPoint(ptL0);
            multiPolygon.AddPolygon(polygon2);

            ISurfaceSymbol ss1 = new SurfaceSymbolClass();

            ss1.Color = 0x88FFFFFF;
            ICurveSymbol cs1 = new CurveSymbolClass();

            cs1.Color          = 0xffffffff;
            ss1.BoundarySymbol = cs1;
            this._renderBox    = app.Current3DMapControl.ObjectManager.CreateRenderMultiPolygon(multiPolygon, ss1, app.Current3DMapControl.ProjectTree.RootID);

            app.Current3DMapControl.HighlightHelper.Color = 0xAAFF0000;
            app.Current3DMapControl.HighlightHelper.SetRegion(geo);
            app.Current3DMapControl.HighlightHelper.MinZ        = height;
            app.Current3DMapControl.HighlightHelper.VisibleMask = 15;
        }