Esempio n. 1
0
        public void AddNodeFeature(int fcId, IFeature feature, bool isSwitch, bool switchState, NetworkNodeType nodeType)
        {
            if (feature == null || !(feature.Shape is IPoint))
            {
                return;
            }

            NetworkNode node = _nodes.Find((IPoint)feature.Shape, _tolerance);

            if (node == null)
            {
                int nodeIndex = _nodes.Add((IPoint)feature.Shape, _tolerance);
                node = _nodes[nodeIndex];
                // Edges splitten!!
                SplitToComplexEdges(node);
            }
            if (node == null)
            {
                return;
            }

            node.SwitchAble     = isSwitch;
            node.SwitchState    = switchState;
            node.FeatureclassId = fcId;
            node.FeatureId      = feature.OID;
            node.Type           = nodeType;
        }
Esempio n. 2
0
        public int Add(IPoint p, double tolerance)
        {
            if (p == null)
            {
                return(-1);
            }
            int index = IndexOf(p, tolerance);

            if (index != -1)
            {
                return(index);
            }

            long nid = _tree.InsertSINode(p.Envelope);

            if (!_NIDs.ContainsKey(nid))
            {
                _NIDs.Add(nid, new List <NetworkNode>());
            }
            List <NetworkNode> nodes = _NIDs[nid];
            NetworkNode        node  = new NetworkNode(++_nodeIdSequence, p);

            nodes.Add(node);
            return(node.Id);
        }
Esempio n. 3
0
        public int Add(IPoint p, double tolerance)
        {
            if (p == null)
            {
                return(-1);
            }
            int index = IndexOf(p, tolerance);

            if (index != -1)
            {
                return(index);
            }

            int gridIndex            = _grid.XYIndex(p);
            List <NetworkNode> nodes = _grid[gridIndex];

            if (nodes == null)
            {
                nodes            = new List <NetworkNode>();
                _grid[gridIndex] = nodes;
            }

            NetworkNode node = new NetworkNode(++_nodeIdSequence, p);

            nodes.Add(node);
            return(node.Id);
        }
Esempio n. 4
0
            public Task <IFeature> NextFeature()
            {
                if (_nodes == null || _pos >= _nodes.Count)
                {
                    return(Task.FromResult <IFeature>(null));
                }

                NetworkNode node = _nodes[_pos++];

                Feature feature = new Feature();

                feature.Shape = node.Point;
                //feature.Fields.Add(new FieldValue("NID", node.Id));
                //feature.Fields.Add(new FieldValue("G1", node.FirstGraphRow));
                //feature.Fields.Add(new FieldValue("G2", node.LastGraphRow));
                feature.Fields.Add(new FieldValue("SWITCH", node.SwitchAble));
                feature.Fields.Add(new FieldValue("STATE", node.SwitchState));
                feature.Fields.Add(new FieldValue("FCID", node.FeatureclassId));
                feature.Fields.Add(new FieldValue("OID", node.FeatureId));
                feature.Fields.Add(new FieldValue("NODETYPE", node.Type));

                return(Task.FromResult <IFeature>(feature));
            }
Esempio n. 5
0
        public bool SplitToComplexEdges(NetworkNode node)
        {
            if (node == null || node.Point == null)
            {
                return(false);
            }

            Envelope env = new Envelope(node.Point.X - _tolerance, node.Point.Y - _tolerance,
                                        node.Point.X + _tolerance, node.Point.Y + _tolerance);

            NetworkEdges edges = _edges.Collect(env);

            foreach (NetworkEdge edge in edges)
            {
                if (edge.FromNodeIndex == node.Id || edge.ToNodeIndex == node.Id)
                {
                    continue;
                }

                double dist, stat;

                IPoint snapped = SpatialAlgorithms.Algorithm.Point2PathDistance(edge.Path, node.Point, out dist, out stat);
                if (snapped != null)
                {
                    if (dist <= _tolerance)
                    {
                        Polyline pLine = new Polyline(edge.Path);
                        Polyline p1    = SpatialAlgorithms.Algorithm.PolylineSplit(pLine, 0, stat);
                        Polyline p2    = SpatialAlgorithms.Algorithm.PolylineSplit(pLine, stat, double.MaxValue);
                        if (p1.PathCount != 1 ||
                            p2.PathCount != 1)
                        {
                            continue;
                        }

                        // Edge bekommt neue Geometrie
                        edge.Path   = p1[0];
                        edge.Length = edge.GeoLength = p1[0].Length;
                        // Edge bekommt neuen Zielknoten
                        int toNodeIndex = edge.ToNodeIndex;
                        edge.ToNodeIndex = node.Id;

                        NetworkEdge edge2 = new NetworkEdge();
                        edge2.Path   = p2[0];
                        edge2.Length = edge2.GeoLength = p2[0].Length;

                        edge2.FeatureclassId     = edge.FeatureclassId;
                        edge2.FeatureId          = edge.FeatureId;
                        edge2.OneWay             = edge.OneWay;
                        edge2.Weights            = edge.Weights;
                        edge.UseWithComplexEdges = edge2.UseWithComplexEdges = true; // edge.Bounds neu berechnen
                        edge.IsComplex           = edge2.IsComplex = true;

                        // Edge2 NodeIds setzen
                        edge2.FromNodeIndex = node.Id;
                        edge2.ToNodeIndex   = toNodeIndex;

                        _edges.Add(edge2);
                    }
                }
            }

            return(false);
        }