Пример #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();
        }
Пример #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);
        }
Пример #3
0
        /// <summary>
        /// Writes a linestring-geometry for the edge currently in the enumerator.
        /// </summary>
        private static void WriteEdge(this RouterDb db, JsonWriter jsonWriter, RoutingNetwork.EdgeEnumerator edgeEnumerator)
        {
            var edgeAttributes = new Itinero.Attributes.AttributeCollection(db.EdgeMeta.Get(edgeEnumerator.Data.MetaId));

            edgeAttributes.AddOrReplace(db.EdgeProfiles.Get(edgeEnumerator.Data.Profile));

            var shape = db.Network.GetShape(edgeEnumerator.Current);

            jsonWriter.WriteOpen();
            jsonWriter.WriteProperty("type", "Feature", true, false);
            jsonWriter.WritePropertyName("geometry", false);

            jsonWriter.WriteOpen();
            jsonWriter.WriteProperty("type", "LineString", true, false);
            jsonWriter.WritePropertyName("coordinates", false);
            jsonWriter.WriteArrayOpen();

            foreach (var coordinate in shape)
            {
                jsonWriter.WriteArrayOpen();
                jsonWriter.WriteArrayValue(coordinate.Longitude.ToInvariantString());
                jsonWriter.WriteArrayValue(coordinate.Latitude.ToInvariantString());
                jsonWriter.WriteArrayClose();
            }

            jsonWriter.WriteArrayClose();
            jsonWriter.WriteClose();

            jsonWriter.WritePropertyName("properties");
            jsonWriter.WriteOpen();
            if (edgeAttributes != null)
            {
                foreach (var attribute in edgeAttributes)
                {
                    jsonWriter.WriteProperty(attribute.Key, attribute.Value, true, true);
                }
            }
            jsonWriter.WriteProperty("edgeid", edgeEnumerator.Id.ToInvariantString());
            jsonWriter.WriteProperty("vertex1", edgeEnumerator.From.ToInvariantString());
            jsonWriter.WriteProperty("vertex2", edgeEnumerator.To.ToInvariantString());
            jsonWriter.WriteClose();

            jsonWriter.WriteClose();
        }
Пример #4
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;
             }
         }
     }
 }
Пример #5
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);
        }