Exemplo n.º 1
0
        public Nullable <double> RotatePointByNetwork(IMap pMap, INetworkFeature pPointFeature, bool bArithmeticAngle, string strDiameterFld, string strLayerName)
        {
            //This routine is used by both RotateDuringCreateFeature and RotateSelectedFeature.
            //It contains all of logic for determining the rotation angle.
            double xyTol;

            const int         iAngleTol = 5;
            diameterMeterFeat diamPnt   = null;

            IPoint pPoint = default(IPoint);
            ISimpleJunctionFeature pSimpJunc = null;
            IEdgeFeature           pEdgeFeat = default(IEdgeFeature);

            List <string> pLstInt = new List <string>();

            List <diameterMeterFeat> diametersWithPoints = new List <diameterMeterFeat>();


            UID      pId       = new UID();
            IFeature pTempFeat = null;

            try
            {
                pPoint = (IPoint)((IFeature)pPointFeature).Shape;
                if (pPoint.IsEmpty)
                {
                    return(0);
                }
                //Create spatial filter to find intersecting features at this given point

                xyTol     = Globals.GetXYTolerance(pPoint);
                pSimpJunc = (ISimpleJunctionFeature)pPointFeature;


                for (int i = 0; i <= pSimpJunc.EdgeFeatureCount - 1; i++)
                {
                    pEdgeFeat = pSimpJunc.get_EdgeFeature(i);

                    if (pLstInt.Count > 0)
                    {
                        if (pLstInt.Contains(((IFeature)pEdgeFeat).Class.ObjectClassID + " " + ((IFeature)pEdgeFeat).OID))
                        {
                            continue;
                        }
                    }

                    pTempFeat = (IFeature)pEdgeFeat;

                    if (strLayerName == Globals.getClassName((IDataset)pTempFeat.Class) || strLayerName == "" || strLayerName == null)
                    {
                        string listInt;
                        diamPnt = null;
                        angleLogic(pPoint, pTempFeat, bArithmeticAngle, strDiameterFld, xyTol, out listInt, out diamPnt);
                        pLstInt.Add(listInt);

                        diametersWithPoints.Add(diamPnt);
                    }
                }
                return(getAngle(diametersWithPoints, iAngleTol));
            }
            catch
            {
                return(0);
            }
            finally
            {
                diamPnt   = null;
                pPoint    = null;
                pSimpJunc = null;
                pEdgeFeat = null;

                pLstInt.Clear();

                diametersWithPoints.Clear();
                pId       = null;
                pTempFeat = null;
            }
        }
Exemplo n.º 2
0
        private void angleLogic(IPoint pPoint, IFeature pFeat, bool bArithmeticAngle, string strDiameterFld, double xyTol, out string listInt, out diameterMeterFeat diamPnt)
        {
            double dblDiameter = 0;
            double dblAngle;
            int    iLineDiameterFieldPos = 0;

            listInt = pFeat.Class.ObjectClassID.ToString() + " " + pFeat.OID.ToString();

            dblAngle = Globals.GetAngleOfLineAtPoint((IPolyline)pFeat.ShapeCopy, pPoint, Globals.GetXYTolerance(pPoint));
            dblAngle = Globals.ConvertRadsToDegrees(dblAngle);


            //Convert to geographic degrees(zero north clockwise)
            if (!(bArithmeticAngle))
            {
                dblAngle = Globals.ConvertArithmeticToGeographic(dblAngle);
            }



            //Round angle
            dblAngle = Math.Round(dblAngle, 4);

            //Find diameter field, if it exists

            iLineDiameterFieldPos = pFeat.Fields.FindField(strDiameterFld);

            //Get diameter of line
            if (iLineDiameterFieldPos < 0)
            {
                dblDiameter = -9999;
            }
            else if (pFeat.get_Value(iLineDiameterFieldPos) == null)
            {
                dblDiameter = -9999;
            }
            else if (object.ReferenceEquals(pFeat.get_Value(iLineDiameterFieldPos), DBNull.Value))
            {
                dblDiameter = -9999;
            }
            else
            {
                double.TryParse(pFeat.get_Value(iLineDiameterFieldPos).ToString(), out dblDiameter);
            }



            diamPnt = new diameterMeterFeat();

            diamPnt.dblDiameter = dblDiameter;
            double distFrom = Globals.GetDistanceBetweenPoints(((IPolyline)pFeat.Shape).FromPoint, pPoint);
            double distTo   = Globals.GetDistanceBetweenPoints(((IPolyline)pFeat.Shape).ToPoint, pPoint);

            if (distFrom < xyTol * 2)
            {
                diamPnt.location = "From";
            }
            else if (distTo < xyTol * 2)
            {
                diamPnt.location = "To";
            }
            else
            {
                diamPnt.location = null;
            }
            diamPnt.pntStart = ((IPolyline)pFeat.Shape).FromPoint;
            diamPnt.pntEnd   = ((IPolyline)pFeat.Shape).ToPoint;
            diamPnt.angle    = dblAngle;
        }
Exemplo n.º 3
0
        public Nullable <double> RotatePoint(IMap pMap, double mapTol, IFeature pPointFeature, bool bArithmeticAngle, string strDiameterFld, string strLayerName)
        {
            IFeatureClass            pPointFC            = default(IFeatureClass);
            ISpatialFilter           pSFilter            = default(ISpatialFilter);
            IFeatureCursor           pLineCursor         = default(IFeatureCursor);
            IFeature                 pLineFeature        = default(IFeature);
            IPoint                   pPoint              = default(IPoint);
            IEnumLayer               pEnumLayer          = default(IEnumLayer);
            ILayer                   pLayer              = default(ILayer);
            IFeatureLayer            pFLayer             = default(IFeatureLayer);
            UID                      pId                 = new UID();
            UID                      pUID                = new UID();
            ITopologicalOperator     pTopo               = null;
            List <string>            pLstInt             = new List <string>();
            List <diameterMeterFeat> diametersWithPoints = new List <diameterMeterFeat>();
            double                   xyTol;

            try
            {
                //This routine is used by both RotateDuringCreateFeature and RotateSelectedFeature.
                //It contains all of logic for determining the rotation angle.

                const int iAngleTol = 5;
                //Used for Tees> a straight line is 180 + or - iAngleTol
                pPointFC = (IFeatureClass)pPointFeature.Class;
                pPoint   = (IPoint)pPointFeature.Shape;
                xyTol    = Globals.GetXYTolerance(pPoint);
                //Create spatial filter to find intersecting features at this given point
                pTopo = (ITopologicalOperator)pPoint;

                pSFilter          = new SpatialFilter();
                pSFilter.Geometry = pTopo.Buffer(mapTol);
                //pPoint
                pSFilter.GeometryField = pPointFC.ShapeFieldName;
                pSFilter.SpatialRel    = esriSpatialRelEnum.esriSpatialRelIntersects;

                //Step through each feature layer
                pUID.Value = "{E156D7E5-22AF-11D3-9F99-00C04F6BC78E}";
                //GeoFeatureLayer
                pEnumLayer = (IEnumLayer)pMap.get_Layers(pUID, true);
                pEnumLayer.Reset();
                pLayer = (ILayer)pEnumLayer.Next();

                diameterMeterFeat diamPnt = null;
                while ((pLayer != null))
                {
                    //Verify that this is a line layer
                    pFLayer = (IFeatureLayer)pLayer;

                    if (pFLayer.FeatureClass != null)
                    {
                        if (pFLayer.FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline && pFLayer.Visible && (strLayerName == "" || strLayerName == null || strLayerName == Globals.getClassName((IDataset)pFLayer.FeatureClass)))
                        {
                            //Apply the filter this line layer
                            pLineCursor = pFLayer.FeatureClass.Search(pSFilter, true);

                            //Loop through the found lines for this layer
                            pLineFeature = pLineCursor.NextFeature();
                            while ((pLineFeature != null))
                            {
                                if (pLstInt.Count > 0)
                                {
                                    if (pLstInt.Contains(pLineFeature.Class.ObjectClassID + " " + pLineFeature.OID))
                                    {
                                        pLineFeature = pLineCursor.NextFeature();
                                        continue;
                                    }
                                }
                                string listInt;
                                diamPnt = null;
                                angleLogic(pPoint, pLineFeature, bArithmeticAngle, strDiameterFld, xyTol, out listInt, out diamPnt);
                                pLstInt.Add(listInt);

                                diametersWithPoints.Add(diamPnt);
                                //Get next line
                                pLineFeature = pLineCursor.NextFeature();
                            }
                        }
                    }
                    //Get next line layer
                    pLayer = pEnumLayer.Next();
                }
                return(getAngle(diametersWithPoints, iAngleTol));
            }
            catch
            {
                return(0);
            }
            finally
            {
                pPointFC     = null;
                pSFilter     = null;
                pLineCursor  = null;
                pLineFeature = null;
                pPoint       = null;
                pEnumLayer   = null;
                pLayer       = null;
                pFLayer      = null;
                pId          = null;
                pUID         = null;
                pTopo        = null;


                pLstInt.Clear();
            }
        }
Exemplo n.º 4
0
        public double RotatePointByNetwork(IMap pMap, INetworkFeature pPointFeature, bool bArithmeticAngle, string strDiameterFld, string strLayerName)
        {
            //This routine is used by both RotateDuringCreateFeature and RotateSelectedFeature.
            //It contains all of logic for determining the rotation angle.

            const int         iAngleTol   = 5;
            double            dblAngle    = 0;
            double            dblDiameter = 0;
            double            ltest       = 0;
            diameterMeterFeat diamPnt     = null;
            int iLineDiameterFieldPos     = 0;

            IPoint pPoint = default(IPoint);
            ISimpleJunctionFeature pSimpJunc = null;
            IEdgeFeature           pEdgeFeat = default(IEdgeFeature);

            List <string>            pLstInt             = new List <string>();
            List <double>            cAngles             = new List <double>();
            List <diameterMeterFeat> diametersWithPoints = new List <diameterMeterFeat>();


            UID      pId       = new UID();
            IFeature pTempFeat = null;

            try
            {
                pPoint = (IPoint)((IFeature)pPointFeature).Shape;
                if (pPoint.IsEmpty)
                {
                    return(0);
                }
                //Create spatial filter to find intersecting features at this given point


                pSimpJunc = (ISimpleJunctionFeature)pPointFeature;


                for (int i = 0; i <= pSimpJunc.EdgeFeatureCount - 1; i++)
                {
                    pEdgeFeat = pSimpJunc.get_EdgeFeature(i);

                    if (pLstInt.Count > 0)
                    {
                        if (pLstInt.Contains(((IFeature)pEdgeFeat).Class.ObjectClassID + " " + ((IFeature)pEdgeFeat).OID))
                        {
                            continue;
                        }
                    }

                    pTempFeat = (IFeature)pEdgeFeat;

                    if (strLayerName == Globals.getClassName((IDataset)pTempFeat.Class) || strLayerName == "" || strLayerName == null)
                    {
                        pLstInt.Add(((IFeature)pEdgeFeat).Class.ObjectClassID.ToString() + " " + ((IFeature)pEdgeFeat).OID.ToString());

                        dblAngle = Globals.GetAngleOfLineAtPoint((IPolyline)pTempFeat.ShapeCopy, pPoint, Globals.GetXYTolerance(pPoint));
                        dblAngle = Globals.ConvertRadsToDegrees(dblAngle);


                        //Convert to geographic degrees(zero north clockwise)
                        if (!(bArithmeticAngle))
                        {
                            dblAngle = Globals.ConvertArithmeticToGeographic(dblAngle);
                        }



                        //Round angle
                        dblAngle = Math.Round(dblAngle, 4);

                        //Find diameter field, if it exists
                        iLineDiameterFieldPos = ((IFeature)pEdgeFeat).Fields.FindField(strDiameterFld);

                        //Get diameter of line
                        if (iLineDiameterFieldPos < 0)
                        {
                            dblDiameter = -9999;
                        }
                        else if (((IFeature)pEdgeFeat).get_Value(iLineDiameterFieldPos) == null)
                        {
                            dblDiameter = -9999;
                        }
                        else if (object.ReferenceEquals(((IFeature)pEdgeFeat).get_Value(iLineDiameterFieldPos), DBNull.Value))
                        {
                            dblDiameter = -9999;
                        }
                        else
                        {
                            double.TryParse(((IFeature)pEdgeFeat).get_Value(iLineDiameterFieldPos).ToString(), out dblDiameter);
                        }


                        //add this line (angle and diameter) to a collection of line info for this point
                        cAngles.Add(dblAngle);


                        diamPnt = new diameterMeterFeat();

                        diamPnt.dblDiameter = dblDiameter;
                        diamPnt.pntStart    = ((IPolyline)pTempFeat.Shape).FromPoint;
                        diamPnt.pntEnd      = ((IPolyline)pTempFeat.Shape).ToPoint;
                        diamPnt.angle       = dblAngle;
                        diametersWithPoints.Add(diamPnt);
                    }
                }

                //Read the collection of line segment angles and diameters
                //and use them to derive a symbol rotation angle for the point
                switch (cAngles.Count)
                {
                case 0:
                    //One line such as at valves

                    return(0.0);

                case 1:
                    //One line such as at valves
                    return(cAngles[0]);

                case 2:
                    //Two lines such as at reducers Or at tee fittings where line is not broken

                    if (diametersWithPoints.Count == 2)
                    {
                        //If cDiameters(0) Is Nothing Or cDiameters(1) Is Nothing Then
                        //    Return cAngles.Item(0)
                        //Else
                        if (diametersWithPoints[0].dblDiameter == -9999 && diametersWithPoints[1].dblDiameter == -9999)
                        {
                            return(diametersWithPoints[0].angle);
                        }
                        else if (diametersWithPoints[0].dblDiameter == -9999)
                        {
                            return(diametersWithPoints[1].angle);
                        }
                        else if (diametersWithPoints[1].dblDiameter == -9999)
                        {
                            return(diametersWithPoints[0].angle);
                        }

                        else if (diametersWithPoints[0].dblDiameter > diametersWithPoints[1].dblDiameter)
                        {
                            if (Globals.pointscoincident(diametersWithPoints[0].pntStart, diametersWithPoints[1].pntStart))
                            {
                                //Checked
                                return(diametersWithPoints[0].angle);
                            }
                            else if (Globals.pointscoincident(diametersWithPoints[0].pntEnd, diametersWithPoints[1].pntEnd))
                            {
                                //Checked
                                if (diametersWithPoints[0].angle >= 180)
                                {
                                    return(diametersWithPoints[0].angle - 180);
                                }
                                else
                                {
                                    return(diametersWithPoints[0].angle + 180);
                                }
                            }
                            else if (Globals.pointscoincident(diametersWithPoints[0].pntEnd, diametersWithPoints[1].pntStart))
                            {
                                //Checked
                                if (diametersWithPoints[0].angle >= 180)
                                {
                                    return(diametersWithPoints[0].angle - 180);
                                }
                                else
                                {
                                    return(diametersWithPoints[0].angle + 180);
                                }
                            }
                            else
                            {
                                //Checked
                                return(diametersWithPoints[0].angle);
                            }
                        }
                        else if (diametersWithPoints[0].dblDiameter < diametersWithPoints[1].dblDiameter)
                        {
                            if (Globals.pointscoincident(diametersWithPoints[0].pntStart, diametersWithPoints[1].pntStart))
                            {
                                //Checked
                                return(diametersWithPoints[1].angle);
                            }
                            else if (Globals.pointscoincident(diametersWithPoints[0].pntEnd, diametersWithPoints[1].pntEnd))
                            {
                                //Checked
                                if (diametersWithPoints[1].angle >= 180)
                                {
                                    return(diametersWithPoints[1].angle - 180);
                                }
                                else
                                {
                                    return(diametersWithPoints[1].angle + 180);
                                }
                            }
                            else if (Globals.pointscoincident(diametersWithPoints[0].pntEnd, diametersWithPoints[1].pntStart))
                            {
                                //Checked
                                return(diametersWithPoints[1].angle);
                            }
                            else
                            {
                                //Checked
                                if (diametersWithPoints[1].angle >= 180)
                                {
                                    return(diametersWithPoints[1].angle - 180);
                                }
                                else
                                {
                                    return(diametersWithPoints[1].angle + 180);
                                }
                            }
                        }
                        else
                        {
                            return(diametersWithPoints[0].angle);
                        }
                    }
                    else
                    {
                        return(cAngles[0]);
                    }

                    break;

                case 3:
                    //Three lines such as at tee fittings where line is broken
                    ltest = Math.Abs(cAngles[0] - cAngles[1]);
                    if (ltest >= 180 - iAngleTol & ltest <= 180 + iAngleTol)
                    {
                        return(cAngles[2]);
                    }
                    else
                    {
                        ltest = Math.Abs(cAngles[0] - cAngles[2]);
                        if (ltest >= 180 - iAngleTol & ltest <= 180 + iAngleTol)
                        {
                            return(cAngles[1]);
                        }
                        else
                        {
                            ltest = Math.Abs(cAngles[1] - cAngles[2]);
                            if (ltest >= 180 - iAngleTol & ltest <= 180 + iAngleTol)
                            {
                                return(cAngles[0]);
                            }
                            else
                            {
                                return(-360);
                            }
                        }
                    }
                    break;

                case 4:
                    //Four lines such as at crosses
                    //the angle of any of the four lines should work since the symbol should be symetrically
                    return(cAngles[0]);

                default:
                    return(0);
                }

                //Clear collections
            }
            catch
            {
                return(0);
            }
            finally
            {
                diamPnt   = null;
                pPoint    = null;
                pSimpJunc = null;
                pEdgeFeat = null;

                pLstInt.Clear();
                cAngles.Clear();
                diametersWithPoints.Clear();
                pId       = null;
                pTempFeat = null;
            }
        }