//public static FiberDeviceConnectionHelper Instance(HookHelperExt hookHelper, ESRI.ArcGIS.Editor.IEditor editor)
        //{
        //    if(_instance != null)
        //    {
        //        return _instance;
        //    }
        //    else
        //    {
        //        _instance = new FiberDeviceConnectionHelper(hookHelper, editor);
        //        return _instance;
        //    }
        //}


        /// <summary>
        /// Returns cables which have an endpoint coincident with the device point
        /// </summary>
        /// <param name="deviceWrapper">Device to check</param>
        /// <returns>List of ConnectableCableWrapper</returns>
        public List <ConnectableCableWrapper> GetCoincidentCables(DeviceWrapper deviceWrapper)
        {
            List <ConnectableCableWrapper> result = new List <ConnectableCableWrapper>();

            if (null == deviceWrapper)
            {
                throw new ArgumentNullException("deviceWrapper");
            }

            ESRI.ArcGIS.Geometry.IPoint devicePoint = deviceWrapper.Feature.Shape as ESRI.ArcGIS.Geometry.IPoint;

            ESRI.ArcGIS.Carto.IFeatureLayer       cableLayer   = _hookHelper.FindFeatureLayer(ConfigUtil.FiberCableFtClassName);
            ESRI.ArcGIS.Geodatabase.IFeatureClass cableFtClass = cableLayer.FeatureClass;
            int displayIdx = cableFtClass.FindField(cableLayer.DisplayField);

            double buffer = _hookHelper.ConvertPixelsToMapUnits(1);
            List <ESRI.ArcGIS.Geodatabase.IFeature> coincidentCables = GdbUtils.GetLinearsWithCoincidentEndpoints(devicePoint, cableFtClass, buffer);

            for (int i = 0; i < coincidentCables.Count; i++)
            {
                ESRI.ArcGIS.Geodatabase.IFeature         ft          = coincidentCables[i];
                ESRI.ArcGIS.Geometry.IPolyline           line        = ft.Shape as ESRI.ArcGIS.Geometry.IPolyline;
                ESRI.ArcGIS.Geometry.IRelationalOperator lineToPoint = line.ToPoint as ESRI.ArcGIS.Geometry.IRelationalOperator;

                bool isFromEnd = true;
                if (lineToPoint.Equals(devicePoint))
                {
                    isFromEnd = false;
                }

                result.Add(new ConnectableCableWrapper(ft, isFromEnd, displayIdx));
            }

            return(result);
        }
예제 #2
0
        /// <summary>
        /// Constructs a new SpliceableCableWrapper, determining which ends to use by comparing to the other cable
        /// </summary>
        /// <param name="thisFeature">IFeature to wrap</param>
        /// <param name="otherFeature">IFeature with which to compare endpoints</param>
        public SpliceableCableWrapper(ESRI.ArcGIS.Geodatabase.IFeature thisFeature, ESRI.ArcGIS.Geodatabase.IFeature otherFeature)
            : base(thisFeature, true)
        {
            #region Validation
            // We already know thisFeature is not null from the base validation
            if (null == otherFeature)
            {
                throw new ArgumentNullException("otherFeature");
            }
            else if (null == otherFeature.Class)
            {
                throw new ArgumentException("otherFeature.Class cannot be null.");
            }

            ESRI.ArcGIS.Geometry.IPolyline thisPolyline = thisFeature.Shape as ESRI.ArcGIS.Geometry.IPolyline;
            if (null == thisPolyline)
            {
                throw new ArgumentException("thisFeature.Shape must be IPolyline.");
            }

            ESRI.ArcGIS.Geometry.IPolyline otherPolyline = otherFeature.Shape as ESRI.ArcGIS.Geometry.IPolyline;
            if (null == otherPolyline)
            {
                throw new ArgumentException("otherPolyline.Shape must be IPolyline.");
            }
            #endregion

            ESRI.ArcGIS.Geometry.IRelationalOperator thisFrom = thisPolyline.FromPoint as ESRI.ArcGIS.Geometry.IRelationalOperator;
            ESRI.ArcGIS.Geometry.IRelationalOperator thisTo   = thisPolyline.ToPoint as ESRI.ArcGIS.Geometry.IRelationalOperator;
            ESRI.ArcGIS.Geometry.IPoint otherFrom             = otherPolyline.FromPoint;
            ESRI.ArcGIS.Geometry.IPoint otherTo = otherPolyline.ToPoint;

            // Assume it will be the from end of thisFeature and the to end of otherFeature
            base._isThisFromEnd = true;
            _isOtherFromEnd     = false;

            if (thisTo.Equals(otherFrom))
            {
                base._isThisFromEnd = false;
                _isOtherFromEnd     = true;
            }
            else if (thisFrom.Equals(otherFrom))
            {
                _isOtherFromEnd = true;
            }
            else if (thisTo.Equals(otherTo))
            {
                base._isThisFromEnd = false;
            }
        }
예제 #3
0
        //public static FiberSpliceConnectionHelper Instance(object hook, ESRI.ArcGIS.Editor.IEditor editor)
        //{
        //    if (_instance != null)
        //    {
        //        return _instance;
        //    }
        //    else
        //    {
        //        _instance = new FiberSpliceConnectionHelper(hook, editor);
        //        return _instance;
        //    }
        //}


        /// <summary>
        /// Gets a list of cable features that are connected to the splice closure in the geometric network
        /// </summary>
        /// <param name="spliceClosure">Splice to check</param>
        /// <returns>List of IFeature</returns>
        public List <ESRI.ArcGIS.Geodatabase.IFeature> GetConnectedCables(SpliceClosureWrapper spliceClosure)
        {
            // At the time of this comment, splicable means they are connected in the
            // geometric network and the splice closure "touches" one of the ends of the cable
            List <ESRI.ArcGIS.Geodatabase.IFeature> result = new List <ESRI.ArcGIS.Geodatabase.IFeature>();

            if (null == spliceClosure)
            {
                throw new ArgumentNullException("spliceClosure");
            }

            ESRI.ArcGIS.Geometry.IRelationalOperator relOp = spliceClosure.Feature.Shape as ESRI.ArcGIS.Geometry.IRelationalOperator;
            if (relOp == null)
            {
                throw new ArgumentNullException("spliceClosure");
            }

            ESRI.ArcGIS.Geodatabase.ISimpleJunctionFeature junction = spliceClosure.Feature as ESRI.ArcGIS.Geodatabase.ISimpleJunctionFeature;
            if (null != junction)
            {
                for (int i = 0; i < junction.EdgeFeatureCount; i++)
                {
                    ESRI.ArcGIS.Geodatabase.IFeature connectedEdge = junction.get_EdgeFeature(i) as ESRI.ArcGIS.Geodatabase.IFeature;
                    ESRI.ArcGIS.Geodatabase.IDataset dataset       = connectedEdge.Class as ESRI.ArcGIS.Geodatabase.IDataset;
                    string ftClassName = GdbUtils.ParseTableName(dataset);

                    if (0 == string.Compare(ftClassName, ConfigUtil.FiberCableFtClassName, true))
                    {
                        // Test feature edge is coincident with splice closure. Cables are
                        // complex features so splice might lie half way along some cables
                        // but will not be providing any splice connectivity to them.
                        if (relOp.Touches(connectedEdge.Shape)) // only true if point at either end of a line
                        {
                            result.Add(connectedEdge);
                        }
                    }
                }
            }

            return(result);
        }
예제 #4
0
        /// <summary>
        /// Returns all features from a given feature class that have a vertex or endpoint coincident with a given point
        /// </summary>
        /// <param name="point">IPoint to use as the spatial filter</param>
        /// <param name="searchFtClass">IFeatureClass to search in</param>
        /// <param name="linearEndpointsOnly">Flag to use only the endpoints of a line instead of all vertices</param>
        /// <param name="buffer">Search geometry buffer in map units</param>
        /// <returns>List of IFeature</returns>
        public static List <ESRI.ArcGIS.Geodatabase.IFeature> GetFeaturesWithCoincidentVertices(ESRI.ArcGIS.Geometry.IPoint point, ESRI.ArcGIS.Geodatabase.IFeatureClass searchFtClass, bool linearEndpointsOnly, double buffer)
        {
            List <ESRI.ArcGIS.Geodatabase.IFeature> result = new List <ESRI.ArcGIS.Geodatabase.IFeature>();

            using (ESRI.ArcGIS.ADF.ComReleaser releaser = new ESRI.ArcGIS.ADF.ComReleaser())
            {
                ESRI.ArcGIS.Geodatabase.ISpatialFilter filter = new ESRI.ArcGIS.Geodatabase.SpatialFilterClass();
                releaser.ManageLifetime(filter);

                ESRI.ArcGIS.Geometry.IEnvelope filterGeometry = point.Envelope;
                if (0 < buffer)
                {
                    filterGeometry.Expand(buffer, buffer, false);
                }

                filter.SpatialRel = ESRI.ArcGIS.Geodatabase.esriSpatialRelEnum.esriSpatialRelIntersects;
                filter.Geometry   = filterGeometry;

                ESRI.ArcGIS.Geodatabase.IFeatureCursor fts = searchFtClass.Search(filter, false);
                releaser.ManageLifetime(fts);

                ESRI.ArcGIS.Geodatabase.IFeature ft = fts.NextFeature();
                while (null != ft)
                {
                    if (searchFtClass.ShapeType == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint)
                    {
                        result.Add(ft);
                    }
                    else if (searchFtClass.ShapeType == ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline && linearEndpointsOnly)
                    {
                        ESRI.ArcGIS.Geometry.IPolyline           polyline  = (ESRI.ArcGIS.Geometry.IPolyline)ft.Shape;
                        ESRI.ArcGIS.Geometry.IRelationalOperator fromPoint = polyline.FromPoint as ESRI.ArcGIS.Geometry.IRelationalOperator;
                        ESRI.ArcGIS.Geometry.IRelationalOperator toPoint   = polyline.ToPoint as ESRI.ArcGIS.Geometry.IRelationalOperator;

                        if (fromPoint.Equals(point) || toPoint.Equals(point))
                        {
                            result.Add(ft);
                        }
                    }
                    else
                    {
                        ESRI.ArcGIS.Geometry.IPointCollection pointCollection = ft.Shape as ESRI.ArcGIS.Geometry.IPointCollection;
                        if (null != pointCollection)
                        {
                            for (int i = 0; i < pointCollection.PointCount; i++)
                            {
                                ESRI.ArcGIS.Geometry.IRelationalOperator testPoint = pointCollection.get_Point(i) as ESRI.ArcGIS.Geometry.IRelationalOperator;
                                if (testPoint.Equals(point))
                                {
                                    result.Add(ft);
                                    break;
                                }
                            }
                        }
                    }

                    ft = fts.NextFeature();
                }
            }

            return(result);
        }
        public override void OnMouseDown(int Button, int Shift, int X, int Y)
        {
            // TODO:  Add PolygonsDifference.OnMouseDown implementation
            if (Button != (int)Keys.LButton)
            {
                return;
            }
            ILayer layer = m_engineEditor.TargetLayer;

            if (layer == null)
            {
                return;
            }
            m_activeView = m_hookHelper.ActiveView;
            m_map        = m_hookHelper.FocusMap;
            ESRI.ArcGIS.Geometry.IPoint pPoint = m_activeView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);
            ISelectionEnvironment       pSelectionEnvironment = new SelectionEnvironmentClass(); pSelectionEnvironment.PointSelectionMethod = ESRI.ArcGIS.Geodatabase.esriSpatialRelEnum.esriSpatialRelWithin;

            m_map.SelectByShape(pPoint as ESRI.ArcGIS.Geometry.IGeometry, pSelectionEnvironment, false);
            //if (m_map.SelectionCount != 2)
            //{
            //    MessageBox.Show("选择的多边形个数应该为2!!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //    return;
            //}
            m_activeView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, m_activeView.Extent);
            ESRI.ArcGIS.Geodatabase.IEnumFeature pEnumFeature  = m_map.FeatureSelection as ESRI.ArcGIS.Geodatabase.IEnumFeature;
            ESRI.ArcGIS.Geodatabase.IFeature     firstFeature  = pEnumFeature.Next();
            ESRI.ArcGIS.Geodatabase.IFeature     secondFeature = pEnumFeature.Next();
            bool firstPolygonIsLarge = false;

            ESRI.ArcGIS.Geometry.IGeometry            pGeometry            = null;
            ESRI.ArcGIS.Geometry.IRelationalOperator  pRelOp1              = firstFeature.Shape as ESRI.ArcGIS.Geometry.IRelationalOperator;
            ESRI.ArcGIS.Geometry.IRelationalOperator  pRelOp2              = secondFeature.Shape as ESRI.ArcGIS.Geometry.IRelationalOperator;
            ESRI.ArcGIS.Geometry.ITopologicalOperator pTopologicalOperator = null;
            if (pRelOp1.Contains(secondFeature.Shape))
            {
                pTopologicalOperator = firstFeature.Shape as ESRI.ArcGIS.Geometry.ITopologicalOperator;
                pGeometry            = pTopologicalOperator.Difference(secondFeature.Shape);
                firstPolygonIsLarge  = true;
            }
            else if (pRelOp2.Contains(firstFeature.Shape))
            {
                pTopologicalOperator = secondFeature.Shape as ESRI.ArcGIS.Geometry.ITopologicalOperator;
                pGeometry            = pTopologicalOperator.Difference(firstFeature.Shape);
                firstPolygonIsLarge  = false;
            }
            else
            {
                return;
            }
            bool         deleteInteriorPolygon = false;
            DialogResult pDialogResult         = MessageBox.Show("是否要删除内多边形?", "操作提示", MessageBoxButtons.YesNo);

            if (pDialogResult == DialogResult.Yes)
            {
                deleteInteriorPolygon = true;
            }
            ESRI.ArcGIS.Geodatabase.IFeatureClass  featureClass  = firstFeature.Class as ESRI.ArcGIS.Geodatabase.IFeatureClass;
            ESRI.ArcGIS.Geodatabase.IDataset       dataset       = featureClass as ESRI.ArcGIS.Geodatabase.IDataset;
            ESRI.ArcGIS.Geodatabase.IWorkspaceEdit workspaceEdit = dataset.Workspace as ESRI.ArcGIS.Geodatabase.IWorkspaceEdit;
            if (!(workspaceEdit.IsBeingEdited()))
            {
                return;
            }
            workspaceEdit.StartEditOperation();
            if (firstPolygonIsLarge)
            {
                firstFeature.Shape = pGeometry;
                firstFeature.Store();
                if (deleteInteriorPolygon)
                {
                    secondFeature.Delete();
                }
            }
            else
            {
                secondFeature.Shape = pGeometry;
                secondFeature.Store();
                if (deleteInteriorPolygon)
                {
                    firstFeature.Delete();
                }
            }
            workspaceEdit.StopEditOperation();
            m_map.ClearSelection();
            m_activeView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, m_activeView.Extent);
            m_Mapcontrol.CurrentTool = null;
        }