Esempio n. 1
0
        public static void SetSideStreets(this RouteSegment segment, RouterDb routerDb, uint vertex, uint previousEdge, uint nextVertex)
        {
            List <RouteSegmentBranch> routeSegmentBranchList = new List <RouteSegmentBranch>();

            RoutingNetwork.EdgeEnumerator edgeEnumerator = routerDb.Network.GetEdgeEnumerator(vertex);
            while (edgeEnumerator.MoveNext())
            {
                if ((int)edgeEnumerator.Id != (int)previousEdge && (int)edgeEnumerator.To != (int)nextVertex)
                {
                    RoutingEdge current = edgeEnumerator.Current;
                    RouterDb    db      = routerDb;
                    EdgeData    data    = current.Data;
                    int         profile = (int)data.Profile;
                    data = current.Data;
                    int metaId = (int)data.MetaId;
                    TagsCollectionBase profileAndMeta = db.GetProfileAndMeta((uint)profile, (uint)metaId);
                    ICoordinate        firstPoint     = routerDb.Network.GetFirstPoint(current, edgeEnumerator.From);
                    routeSegmentBranchList.Add(new RouteSegmentBranch()
                    {
                        Latitude  = firstPoint.Latitude,
                        Longitude = firstPoint.Longitude,
                        Tags      = profileAndMeta.ConvertFrom()
                    });
                }
            }
            if (routeSegmentBranchList.Count <= 0)
            {
                return;
            }
            segment.SideStreets = routeSegmentBranchList.ToArray();
        }
Esempio n. 2
0
        public static FeatureCollection GetFeaturesIn(this RouterDb db, float minLatitude, float minLongitude, float maxLatitude, float maxLongitude)
        {
            RoutingNetwork    network           = db.Network;
            FeatureCollection featureCollection = new FeatureCollection();
            HashSet <uint>    uintSet1          = network.GeometricGraph.Search(minLatitude, minLongitude, maxLatitude, maxLongitude);
            HashSet <long>    longSet           = new HashSet <long>();

            RoutingNetwork.EdgeEnumerator edgeEnumerator = network.GetEdgeEnumerator();
            HashSet <uint> uintSet2 = new HashSet <uint>();

            foreach (uint vertex1 in uintSet1)
            {
                GeoCoordinateSimple vertex2 = network.GeometricGraph.GetVertex(vertex1);
                featureCollection.Add(new Feature((Geometry) new Point(new GeoCoordinate((double)vertex2.Latitude, (double)vertex2.Longitude)), (GeometryAttributeCollection) new SimpleGeometryAttributeCollection((IEnumerable <Tag>) new Tag[1]
                {
                    Tag.Create("id", vertex1.ToInvariantString())
                })));
                edgeEnumerator.MoveTo(vertex1);
                edgeEnumerator.Reset();
                while (edgeEnumerator.MoveNext())
                {
                    if (!longSet.Contains((long)edgeEnumerator.Id))
                    {
                        longSet.Add((long)edgeEnumerator.Id);
                        List <ICoordinate>   shape             = network.GetShape(edgeEnumerator.Current);
                        List <GeoCoordinate> geoCoordinateList = new List <GeoCoordinate>();
                        foreach (ICoordinate coordinate in shape)
                        {
                            geoCoordinateList.Add(new GeoCoordinate((double)coordinate.Latitude, (double)coordinate.Longitude));
                        }
                        LineString lineString = new LineString((IEnumerable <GeoCoordinate>)geoCoordinateList);
                        RouterDb   db1        = db;
                        EdgeData   data       = edgeEnumerator.Data;
                        int        profile    = (int)data.Profile;
                        data = edgeEnumerator.Data;
                        int metaId = (int)data.MetaId;
                        TagsCollectionBase profileAndMeta = db1.GetProfileAndMeta((uint)profile, (uint)metaId);
                        profileAndMeta.AddOrReplace(Tag.Create("id", edgeEnumerator.Id.ToInvariantString()));
                        featureCollection.Add(new Feature((Geometry)lineString, (GeometryAttributeCollection) new SimpleGeometryAttributeCollection((IEnumerable <Tag>)profileAndMeta)));
                        if (!uintSet1.Contains(edgeEnumerator.To))
                        {
                            uintSet2.Add(edgeEnumerator.To);
                        }
                    }
                }
            }
            foreach (uint vertex1 in uintSet2)
            {
                GeoCoordinateSimple vertex2 = network.GeometricGraph.GetVertex(vertex1);
                featureCollection.Add(new Feature((Geometry) new Point(new GeoCoordinate((double)vertex2.Latitude, (double)vertex2.Longitude)), (GeometryAttributeCollection) new SimpleGeometryAttributeCollection((IEnumerable <Tag>) new Tag[1]
                {
                    Tag.Create("id", vertex1.ToInvariantString())
                })));
            }
            return(featureCollection);
        }
Esempio n. 3
0
 protected override void DoRun()
 {
     RoutingNetwork.EdgeEnumerator edgeEnumerator = this._network.GetEdgeEnumerator();
     for (uint vertex = 0; vertex < this._network.VertexCount; ++vertex)
     {
         edgeEnumerator.MoveTo(vertex);
         while (edgeEnumerator.MoveNext())
         {
             EdgeData data = edgeEnumerator.Data;
             if ((double)data.Distance == 0.0 && this._canRemove(data))
             {
                 uint from = edgeEnumerator.From;
                 uint to   = edgeEnumerator.To;
                 this._network.RemoveEdge(edgeEnumerator.Id);
                 this._network.MergeVertices(from, to);
                 --vertex;
                 break;
             }
         }
     }
 }
Esempio n. 4
0
        public static FeatureCollection GetFeatures(this RouterDb db)
        {
            RoutingNetwork    network           = db.Network;
            FeatureCollection featureCollection = new FeatureCollection();
            HashSet <long>    longSet           = new HashSet <long>();

            RoutingNetwork.EdgeEnumerator edgeEnumerator = network.GetEdgeEnumerator();
            for (uint vertex1 = 0; vertex1 < network.VertexCount; ++vertex1)
            {
                GeoCoordinateSimple vertex2 = network.GeometricGraph.GetVertex(vertex1);
                featureCollection.Add(new Feature((Geometry) new Point(new GeoCoordinate((double)vertex2.Latitude, (double)vertex2.Longitude)), (GeometryAttributeCollection) new SimpleGeometryAttributeCollection((IEnumerable <Tag>) new Tag[1]
                {
                    Tag.Create("id", vertex1.ToInvariantString())
                })));
                edgeEnumerator.MoveTo(vertex1);
                edgeEnumerator.Reset();
                while (edgeEnumerator.MoveNext())
                {
                    if (!longSet.Contains((long)edgeEnumerator.Id))
                    {
                        longSet.Add((long)edgeEnumerator.Id);
                        List <ICoordinate>   shape             = network.GetShape(edgeEnumerator.Current);
                        List <GeoCoordinate> geoCoordinateList = new List <GeoCoordinate>();
                        foreach (ICoordinate coordinate in shape)
                        {
                            geoCoordinateList.Add(new GeoCoordinate((double)coordinate.Latitude, (double)coordinate.Longitude));
                        }
                        LineString         lineString     = new LineString((IEnumerable <GeoCoordinate>)geoCoordinateList);
                        TagsCollectionBase profileAndMeta = db.GetProfileAndMeta((uint)edgeEnumerator.Data.Profile, edgeEnumerator.Data.MetaId);
                        profileAndMeta.AddOrReplace(Tag.Create("id", edgeEnumerator.Id.ToInvariantString()));
                        featureCollection.Add(new Feature((Geometry)lineString, (GeometryAttributeCollection) new SimpleGeometryAttributeCollection((IEnumerable <Tag>)profileAndMeta)));
                    }
                }
            }
            return(featureCollection);
        }