Esempio n. 1
0
        /// <summary>
        /// This Constructor Doesnt do anything special. It just treats the layer as a graph.
        /// </summary>
        /// <param name="theLayer">The Layer</param>
        public GraphFactory(VectorLayer theLayer)
        {
            _geomFactory = GeoAPI.GeometryServiceProvider.Instance.CreateGeometryFactory(theLayer.SRID);
            
            var featureCount = theLayer.DataSource.GetFeatureCount();
            System.Diagnostics.Debug.WriteLine("Feature Count: = " + featureCount);

            theLayer.DataSource.Open();
            var featureIds = theLayer.DataSource.GetObjectIDsInView(theLayer.Envelope);
            _edgeCost = new Dictionary<Edge<Coordinate>, double>();
            
            _listOfEndPoints = new List<LineEndPoints>();

            foreach (uint featureID  in featureIds)
            {
                var feature = theLayer.DataSource.GetGeometryByID(featureID);
                
                // We need this  incase the lines are multistring.
                if (feature.OgcGeometryType == OgcGeometryType.LineString)
                {
                    var ls = (ILineString)feature;
                    //var numberOfPoints = ls.NumPoints;


                    // We need a copy of the feature so we can display it. Or perhaps we dont who knows.
                    _theLineStrings.Add(featureIds[(int)featureID], (ILineString)feature);

                    var pp = new LineEndPoints(ls.StartPoint.Coordinate, ls.EndPoint.Coordinate, ls.Length);
                    _listOfEndPoints.Add(pp);

                        if (!_graph.ContainsVertex(ls.StartPoint.Coordinate))
                            _graph.AddVertex(ls.StartPoint.Coordinate);

                        if (!_graph.ContainsVertex(ls.EndPoint.Coordinate))
                            _graph.AddVertex(ls.EndPoint.Coordinate);

                        var theEdge = new Edge<Coordinate>(ls.StartPoint.Coordinate, ls.EndPoint.Coordinate);
                        _graph.AddEdge(theEdge);
                        _edgeCost.Add(theEdge,ls.Length);

                        var theReverseEdge = new Edge<Coordinate>(ls.EndPoint.Coordinate, ls.StartPoint.Coordinate);
                        _graph.AddEdge(theReverseEdge);
                        _edgeCost.Add(theReverseEdge, ls.Length);
                }
                else if (feature.OgcGeometryType == OgcGeometryType.MultiLineString)
                {
                    var mls = (IMultiLineString)feature;

                    for(var i = 0; i < mls.NumGeometries; i++)
                    {
                        var ls = (ILineString) mls.GetGeometryN(i);
                        // We need a copy of the feature so we can display it. Or perhaps we dont who knows.
                        _theLineStrings.Add(featureIds[(int)featureID], (ILineString)feature);

                        var pp = new LineEndPoints(ls.StartPoint.Coordinate, ls.EndPoint.Coordinate, ls.Length);
                        _listOfEndPoints.Add(pp);
                        
                            if (!_graph.ContainsVertex(ls.StartPoint.Coordinate))
                                _graph.AddVertex(ls.StartPoint.Coordinate);

                            if (!_graph.ContainsVertex(ls.EndPoint.Coordinate))
                                _graph.AddVertex(ls.EndPoint.Coordinate);

                            var theEdge = new Edge<Coordinate>(ls.StartPoint.Coordinate, ls.EndPoint.Coordinate);
                            _graph.AddEdge(theEdge);
                            _edgeCost.Add(theEdge, ls.Length);

                            var theReverseEdge = new Edge<Coordinate>(ls.EndPoint.Coordinate, ls.StartPoint.Coordinate);
                            _graph.AddEdge(theReverseEdge);
                            _edgeCost.Add(theReverseEdge, ls.Length);
                        
                    }
                }
            }

            System.Diagnostics.Debug.WriteLine("Graph Stats:" + _graph.EdgeCount + " , " + _graph.VertexCount);

        }
Esempio n. 2
0
        /// <summary>
        /// This Constructor Doesnt do anything special. It just treats the layer as a graph.
        /// </summary>
        /// <param name="theLayer">The Layer</param>
        public GraphFactory(VectorLayer theLayer)
        {
            _geomFactory = GeoAPI.GeometryServiceProvider.Instance.CreateGeometryFactory(theLayer.SRID);

            var featureCount = theLayer.DataSource.GetFeatureCount();

            System.Diagnostics.Debug.WriteLine("Feature Count: = " + featureCount);

            theLayer.DataSource.Open();
            var featureIds = theLayer.DataSource.GetObjectIDsInView(theLayer.Envelope);

            _edgeCost = new Dictionary <Edge <Coordinate>, double>();

            _listOfEndPoints = new List <LineEndPoints>();

            foreach (uint featureID  in featureIds)
            {
                var feature = theLayer.DataSource.GetGeometryByID(featureID);

                // We need this  incase the lines are multistring.
                if (feature.OgcGeometryType == OgcGeometryType.LineString)
                {
                    var ls = (ILineString)feature;
                    //var numberOfPoints = ls.NumPoints;


                    // We need a copy of the feature so we can display it. Or perhaps we dont who knows.
                    _theLineStrings.Add(featureIds[(int)featureID], (ILineString)feature);

                    var pp = new LineEndPoints(ls.StartPoint.Coordinate, ls.EndPoint.Coordinate, ls.Length);
                    _listOfEndPoints.Add(pp);

                    if (!_graph.ContainsVertex(ls.StartPoint.Coordinate))
                    {
                        _graph.AddVertex(ls.StartPoint.Coordinate);
                    }

                    if (!_graph.ContainsVertex(ls.EndPoint.Coordinate))
                    {
                        _graph.AddVertex(ls.EndPoint.Coordinate);
                    }

                    var theEdge = new Edge <Coordinate>(ls.StartPoint.Coordinate, ls.EndPoint.Coordinate);
                    _graph.AddEdge(theEdge);
                    _edgeCost.Add(theEdge, ls.Length);

                    var theReverseEdge = new Edge <Coordinate>(ls.EndPoint.Coordinate, ls.StartPoint.Coordinate);
                    _graph.AddEdge(theReverseEdge);
                    _edgeCost.Add(theReverseEdge, ls.Length);
                }
                else if (feature.OgcGeometryType == OgcGeometryType.MultiLineString)
                {
                    var mls = (IMultiLineString)feature;

                    for (var i = 0; i < mls.NumGeometries; i++)
                    {
                        var ls = (ILineString)mls.GetGeometryN(i);
                        // We need a copy of the feature so we can display it. Or perhaps we dont who knows.
                        _theLineStrings.Add(featureIds[(int)featureID], (ILineString)feature);

                        var pp = new LineEndPoints(ls.StartPoint.Coordinate, ls.EndPoint.Coordinate, ls.Length);
                        _listOfEndPoints.Add(pp);

                        if (!_graph.ContainsVertex(ls.StartPoint.Coordinate))
                        {
                            _graph.AddVertex(ls.StartPoint.Coordinate);
                        }

                        if (!_graph.ContainsVertex(ls.EndPoint.Coordinate))
                        {
                            _graph.AddVertex(ls.EndPoint.Coordinate);
                        }

                        var theEdge = new Edge <Coordinate>(ls.StartPoint.Coordinate, ls.EndPoint.Coordinate);
                        _graph.AddEdge(theEdge);
                        _edgeCost.Add(theEdge, ls.Length);

                        var theReverseEdge = new Edge <Coordinate>(ls.EndPoint.Coordinate, ls.StartPoint.Coordinate);
                        _graph.AddEdge(theReverseEdge);
                        _edgeCost.Add(theReverseEdge, ls.Length);
                    }
                }
            }

            System.Diagnostics.Debug.WriteLine("Graph Stats:" + _graph.EdgeCount + " , " + _graph.VertexCount);
        }