Exemple #1
0
        /// <summary>
        /// Creates a new target.
        /// </summary>
        protected OsmStreamTarget()
        {
            _meta = new TagsCollection();

            _cancel_pull = false;
            _pull_progress = 0;
        }
Exemple #2
0
        public override TagsCollectionBase Evaluate(TagsCollectionBase tags, OsmGeoType type)
        {
            var a_result = _a.Evaluate(tags, type);
            var b_result = _b.Evaluate(tags, type);

            return a_result.Union(b_result);
        }
Exemple #3
0
 /// <summary>
 /// Returns true if the vehicle is allowed on the way represented by these tags
 /// </summary>
 /// <param name="tags"></param>
 /// <param name="highwayType"></param>
 /// <returns></returns>
 protected override bool IsVehicleAllowed(TagsCollectionBase tags, string highwayType)
 {
     // do the designated tags.
     if (tags.ContainsKey("bicycle"))
     {
         if (tags["bicycle"] == "designated")
         {
             return true; // designated bicycle
         }
         if (tags["bicycle"] == "yes")
         {
             return true; // yes for bicycle
         }
         if (tags["bicycle"] == "no")
         {
             return false; //  no for bicycle
         }
     }
     if (tags.ContainsKey("foot"))
     {
         if (tags["foot"] == "designated")
         {
             return false; // designated foot
         }
     }
     return AccessibleTags.ContainsKey(highwayType);
 }
 /// <summary>
 /// Compares two tags collections.
 /// </summary>
 public static void CompareTags(TagsCollectionBase expected, TagsCollectionBase actual)
 {
     if (expected == null)
     {
         Assert.IsNull(actual);
     }
     else
     {
         if (expected.Count == 0)
         {
             Assert.IsTrue(actual == null || actual.Count == 0);
         }
         else
         {
             Assert.IsNotNull(actual);
             Assert.AreEqual(expected.Count, actual.Count);
             foreach (Tag tag in expected)
             {
                 Assert.IsTrue(actual.ContainsKeyValue(tag.Key, tag.Value));
             }
             foreach (Tag tag in actual)
             {
                 Assert.IsTrue(expected.ContainsKeyValue(tag.Key, tag.Value));
             }
         }
     }
 }
Exemple #5
0
 /// <summary>
 /// Creates a new way.
 /// </summary>
 /// <param name="id"></param>
 /// <param name="nodes"></param>
 /// <param name="tags"></param>
 /// <returns></returns>
 public static Way Create(long id, TagsCollectionBase tags, params long[] nodes)
 {
     Way way = new Way();
     way.Id = id;
     way.Nodes = new List<long>(nodes);
     way.Tags = tags;
     return way;
 }
 /// <summary>
 /// Returns a label for different categories of highways.
 /// </summary>
 /// <param name="tags"></param>
 /// <returns></returns>
 public RoutingLabel GetLabelFor(TagsCollectionBase tags)
 {
     if (_edge_intepreter.IsOnlyLocalAccessible(tags))
     {
         return new RoutingLabel('L', "OnlyLocalAccessible"); // local
     }
     return new RoutingLabel('R', "GeneralAccessible"); // regular.
 }
Exemple #7
0
 /// <summary>
 ///     Returns true if the edge with the given tags is routable.
 /// </summary>
 /// <param name="tags"></param>
 /// <returns></returns>
 public bool IsRoutable(TagsCollectionBase tags)
 {
     if (tags != null && tags.Count > 0)
     {
         return tags.ContainsKey("highway");
     }
     return false;
 }
        /// <summary>
        /// Serializes a tags collection to a byte array and addes the size in the first 4 bytes.
        /// </summary>
        /// <param name="collection"></param>
        /// <param name="stream"></param>
        /// <returns></returns>
        public void SerializeWithSize(TagsCollectionBase collection, Stream stream)
        {
            RuntimeTypeModel typeModel = TypeModel.Create();
            typeModel.Add(typeof(Tag), true);

            var tagsList = new List<Tag>(collection);
            typeModel.SerializeWithSize(stream, tagsList);
        }
Exemple #9
0
 /// <summary>
 /// Creates a new relation.
 /// </summary>
 /// <param name="id"></param>
 /// <param name="tags"></param>
 /// <param name="members"></param>
 /// <returns></returns>
 public static Relation Create(long id, TagsCollectionBase tags, params RelationMember[] members)
 {
     Relation relation = new Relation();
     relation.Id = id;
     relation.Members = new List<RelationMember>(members);
     relation.Tags = tags;
     return relation;
 }
Exemple #10
0
 /// <summary>
 ///     Returns the name of a given way.
 /// </summary>
 /// <param name="tags"></param>
 /// <returns></returns>
 public string GetName(TagsCollectionBase tags)
 {
     var name = string.Empty;
     if (tags.ContainsKey("name"))
     {
         name = tags["name"];
     }
     return name;
 }
Exemple #11
0
        public override TagsCollectionBase Evaluate(TagsCollectionBase tags, OsmGeoType type)
        {
            if (tags == null)
            {
                throw new ArgumentNullException("tags");
            }

            return tags;
        }
 private IAttributesTable ConvertTags(TagsCollectionBase tags, long id)
 {
     var properties = tags.ToStringObjectDictionary();
     properties.Add("osm_id", id);
     var table = new AttributesTable();
     foreach (var key in properties.Keys)
     {
         table.AddAttribute(key, properties[key]);
     }
     return table;
 }
Exemple #13
0
 /// <summary>
 /// Returns true if the vehicle is allowed on the way represented by these tags
 /// </summary>
 /// <param name="tags"></param>
 /// <param name="highwayType"></param>
 /// <returns></returns>
 protected override bool IsVehicleAllowed(TagsCollectionBase tags, string highwayType)
 {
     if (tags.ContainsKey("motor_vehicle"))
     {
         if (tags["motor_vehicle"] == "no")
         {
             return false;
         }
     }
     return AccessibleTags.ContainsKey(highwayType);
 }
 /// <summary>
 /// Generates an instruction for a direct turn.
 /// </summary>
 /// <param name="countBefore"></param>
 /// <param name="street"></param>
 /// <param name="direction"></param>
 /// <param name="pois"></param>
 /// <returns></returns>
 protected override string GenerateDirectTurn(int countBefore, TagsCollectionBase street, RelativeDirection direction, List<PointPoi> pois)
 {
     countBefore++;
     if (countBefore == 1)
     {
         return string.Format("Neem de 1ste afslag {0}, de {1} op.", TurnDirection(direction), this.GetName("nl", street));
     }
     else
     {
         return string.Format("Neem de {0}de afslag {1}, de {2} op.", countBefore, TurnDirection(direction), this.GetName("nl", street));
     }
 }
 /// <summary>
 /// Generates an instruction for a direct turn.
 /// </summary>
 /// <param name="countBefore"></param>
 /// <param name="street"></param>
 /// <param name="direction"></param>
 /// <param name="pois"></param>
 /// <returns></returns>
 protected override string GenerateDirectTurn(int countBefore, TagsCollectionBase street, RelativeDirection direction, List<PointPoi> pois)
 {
     countBefore++;
     if (countBefore == 1)
     {
         return string.Format("Take the first turn {0}, on {1}.", TurnDirection(direction), this.GetName("en", street));
     }
     else
     {
         return string.Format("Take the {0}th turn {1}, on {2}.", countBefore, TurnDirection(direction), this.GetName("en", street));
     }
 }
 /// <summary>
 /// Generates an instruction for a direct turn.
 /// </summary>
 /// <param name="countBefore"></param>
 /// <param name="street"></param>
 /// <param name="direction"></param>
 /// <param name="pois"></param>
 /// <returns></returns>
 protected override string GenerateDirectTurn(int countBefore, TagsCollectionBase street, RelativeDirection direction, List<PointPoi> pois)
 {
     countBefore++;
     if (countBefore == 1)
     {
         return string.Format("Nimm die erste Abzweigung {0}, auf die {1}", TurnDirection(direction), this.GetName("de", street));
     }
     else
     {
         return string.Format("Nimm die {0}te Abzweigung {1}, auf die {2}.", countBefore, TurnDirection(direction), this.GetName("de", street));
     }
 }
Exemple #17
0
        public override TagsCollectionBase Evaluate(TagsCollectionBase tags, OsmGeoType type)
        {
            if (tags == null)
            {
                throw new ArgumentNullException("tags");
            }

            var result = tags;

            if (type == _type)
            {
                result = TagsCollectionBase.Empty;
            }

            return result;
        }
Exemple #18
0
 /// <summary>
 ///     Returns all the names in all languages and alternatives.
 /// </summary>
 /// <param name="tags"></param>
 /// <returns></returns>
 public Dictionary<string, string> GetNamesInAllLanguages(TagsCollectionBase tags)
 {
     var names = new Dictionary<string, string>();
     //if (tags != null)
     //{
     //    foreach (var pair in tags)
     //    {
     //        var m = Regex.Match(pair.Key, "name:[a-zA-Z]");
     //        if (m.Success)
     //        {
     //            //throw new NotImplementedException();
     //        }
     //    }
     //}
     return names;
 }
        /// <summary>
        /// Direct turn instruction.
        /// </summary>
        /// <param name="instruction"></param>
        /// <param name="streetCountBeforeTurn"></param>
        /// <param name="streetTo"></param>
        /// <param name="direction"></param>
        /// <param name="list"></param>
        /// <returns></returns>
        public Instruction GenerateDirectTurn(Instruction instruction,
            int streetCountBeforeTurn,
            TagsCollectionBase streetTo,
            RelativeDirectionEnum direction,
            List<PointPoi> list)
        {
            instruction.Text = string.Format("GenerateDirectTurn:{0}_{1}_{2}",
                                             streetCountBeforeTurn, direction.ToString(), list.Count);

            instruction.Extras = new Dictionary<string, object>();
            instruction.Extras.Add("streetCountBeforeTurn", streetCountBeforeTurn);
            instruction.Extras.Add("streetTo", streetTo);
            instruction.Extras.Add("direction", direction);
            instruction.Extras.Add("list", list);

            return instruction;
        }
Exemple #20
0
 /// <summary>
 ///     Returns true if the edge with the given tags is only accessible locally.
 /// </summary>
 /// <param name="tags"></param>
 /// <returns></returns>
 public bool IsOnlyLocalAccessible(TagsCollectionBase tags)
 {
     string tag;
     if (tags.TryGetValue("highway", out tag))
     {
         if (tag == "service")
         {
             return true;
         }
     }
     if (tags.TryGetValue("access", out tag))
     {
         if (tag == "private" || tag == "official")
         {
             return true;
         }
     }
     return false;
 }
 /// <summary>
 /// Generates an instruction for an immidiate turn.
 /// </summary>
 /// <param name="countBefore"></param>
 /// <param name="firstStreet"></param>
 /// <param name="firstDirection"></param>
 /// <param name="secondStreet"></param>
 /// <param name="secondDirection"></param>
 /// <param name="pois"></param>
 /// <returns></returns>
 protected override string GenerateImmidiateTurn(int countBefore, TagsCollectionBase firstStreet, RelativeDirection firstDirection, TagsCollectionBase secondStreet, RelativeDirection secondDirection, List<PointPoi> pois)
 {
     countBefore++;
     if (countBefore == 1)
     {
         return string.Format("Nimm die erste Abzweigung {0}, auf die {1}, und fahre sofort {2} auf die {3}.",
             TurnDirection(firstDirection),
             this.GetName("de", firstStreet),
             TurnDirection(secondDirection),
             this.GetName("de", secondStreet));
     }
     else
     {
         return string.Format("Nimm die {4}te Abzweigung {0}, auf die {1}, und fahre sofort {2} auf die {3}.",
             TurnDirection(firstDirection),
             this.GetName("de", firstStreet),
             TurnDirection(secondDirection),
             this.GetName("de", secondStreet),
             countBefore);
     }
 }
Exemple #22
0
        /// <summary>
        /// Returns true if the edge is a suitable candidate as a target for a point to be resolved on.
        /// </summary>
        /// <param name="vehicle"></param>
        /// <param name="pointTags"></param>
        /// <param name="edgeTags"></param>
        /// <returns></returns>
        public bool MatchWithEdge(Vehicle vehicle,
            TagsCollectionBase pointTags, TagsCollectionBase edgeTags)
        {
            if (pointTags == null || pointTags.Count == 0)
            { // when the point has no tags it has no requirements.
                return true;
            }

            if (edgeTags == null || edgeTags.Count == 0)
            { // when the edge has no tags, no way to verify.
                return false;
            }

            string pointName, edgeName;
            if (pointTags.TryGetValue("name", out pointName) &&
                edgeTags.TryGetValue("name", out edgeName))
            { // both have names.
                return (pointName == edgeName);
            }
            return false;
        }
 /// <summary>
 /// Generates an instruction for an immidiate turn.
 /// </summary>
 /// <param name="countBefore"></param>
 /// <param name="firstStreet"></param>
 /// <param name="firstDirection"></param>
 /// <param name="secondStreet"></param>
 /// <param name="secondDirection"></param>
 /// <param name="pois"></param>
 /// <returns></returns>
 protected override string GenerateImmidiateTurn(int countBefore, TagsCollectionBase firstStreet, RelativeDirection firstDirection, TagsCollectionBase secondStreet, RelativeDirection secondDirection, List<PointPoi> pois)
 {
     countBefore++;
     if (countBefore == 1)
     {
         return string.Format("Neem de eerste afslag {0}, op de {1}, en draai onmiddellijk {2} op de {3}.",
             TurnDirection(firstDirection),
             this.GetName("nl", firstStreet),
             TurnDirection(secondDirection),
             this.GetName("nl", secondStreet));
     }
     else
     {
         return string.Format("Neem de {4}de afslag {0}, op de {1}, en draai onmiddellijk {2} op de {3}.",
             TurnDirection(firstDirection),
             this.GetName("nl", firstStreet),
             TurnDirection(secondDirection),
             this.GetName("nl", secondStreet),
             countBefore);
     }
 }
        /// <summary>
        /// Generates an instruction for a direct turn.
        /// </summary>
        /// <param name="instruction"></param>
        /// <param name="street_count_before_turn"></param>
        /// <param name="street_to"></param>
        /// <param name="direction"></param>
        /// <param name="list"></param>
        /// <returns></returns>
        public Instruction GenerateDirectTurn(Instruction instruction, int street_count_before_turn,
            TagsCollectionBase street_to, RelativeDirectionEnum direction, List<PointPoi> list)
        {
            //            if (street_count_before_turn == 1)
            //            {
            //                instruction.Text = string.Format("Neem de 1ste afslag {0}, de {1} op.",
            //                    TurnDirection(direction),
            //                    this.GetName("nl", street_to));
            //            }
            //            else
            //            {
            //                instruction.Text = string.Format("Neem de {0}de afslag {1}, de {2} op.",
            //                    street_count_before_turn,
            //                    TurnDirection(direction),
            //                    this.GetName("nl", street_to));
            //            }
            instruction.Text = string.Format ("Draai {0}", TurnDirection (direction));

            // returns the instruction with text.
            return instruction;
        }
 /// <summary>
 /// Generates an instruction for an immidiate turn.
 /// </summary>
 /// <param name="countBefore"></param>
 /// <param name="firstStreet"></param>
 /// <param name="firstDirection"></param>
 /// <param name="secondStreet"></param>
 /// <param name="secondDirection"></param>
 /// <param name="pois"></param>
 /// <returns></returns>
 protected override string GenerateImmidiateTurn(int countBefore, TagsCollectionBase firstStreet, RelativeDirection firstDirection, TagsCollectionBase secondStreet, RelativeDirection secondDirection, List<PointPoi> pois)
 {
     countBefore++;
     if (countBefore == 1)
     {
         return string.Format("Take the first turn {0}, on the {1}, and turn immidiately {2} on the {3}.",
             TurnDirection(firstDirection),
             this.GetName("en", firstStreet),
             TurnDirection(secondDirection),
             this.GetName("en", secondStreet));
     }
     else
     {
         return string.Format("Take the {4}d turn {0}, on the {1}, and turn immidiately {2} on the {3}.",
             TurnDirection(firstDirection),
             this.GetName("en", firstStreet),
             TurnDirection(secondDirection),
             this.GetName("en", secondStreet),
             countBefore);
     }
 }
        /// <summary>
        /// Generates an instruction for a direct turn.
        /// </summary>
        /// <param name="instruction"></param>
        /// <param name="streetCountBeforeTurn"></param>
        /// <param name="streetTo"></param>
        /// <param name="direction"></param>
        /// <param name="list"></param>
        /// <returns></returns>
        public Instruction GenerateDirectTurn(Instruction instruction, int streetCountBeforeTurn,
            TagsCollectionBase streetTo, RelativeDirectionEnum direction, List<PointPoi> list)
        {
            streetCountBeforeTurn++;
            if (streetCountBeforeTurn == 1)
            {
                instruction.Text = string.Format("Take the first turn {0}, on {1}.",
                    TurnDirection(direction),
                    this.GetName("en",streetTo));
            }
            else
            {
                instruction.Text = string.Format("Take the {0}th turn {1}, on {2}.",
                    streetCountBeforeTurn,
                    TurnDirection(direction),
                    this.GetName("en",streetTo));
            }

            // returns the instruction with text.
            return instruction;
        }
        /// <summary>
        /// Generates an instruction for a turn followed by another turn.
        /// </summary>
        /// <param name="instruction"></param>
        /// <param name="streetCountBeforeTurn"></param>
        /// <param name="street_to"></param>
        /// <param name="direction"></param>
        /// <param name="list"></param>
        /// <returns></returns>
        public Instruction GenerateDirectFollowTurn(Instruction instruction, 
            int streetCountBeforeTurn, TagsCollectionBase street_to, 
            RelativeDirectionEnum direction, List<PointPoi> list)
        {
            streetCountBeforeTurn++;
            if (streetCountBeforeTurn == 1)
            {
                instruction.Text = string.Format("Turn {1} to stay on {0}.",
                    this.GetName("en",street_to),
                    TurnDirection(direction));
            }
            else
            {
                instruction.Text = string.Format("Turn {1}d street {2} to stay on {0}.",
                    this.GetName("en",street_to),
                    streetCountBeforeTurn,
                    TurnDirection(direction));
            }

            // returns the instruction with text.
            return instruction;
        }
        /// <summary>
        /// Generates an instruction for a turn followed by another turn.
        /// </summary>
        /// <param name="instruction"></param>
        /// <param name="street_count_before_turn"></param>
        /// <param name="street_to"></param>
        /// <param name="direction"></param>
        /// <param name="list"></param>
        /// <returns></returns>
        public Instruction GenerateDirectFollowTurn(Instruction instruction, int street_count_before_turn,
            TagsCollectionBase street_to, 
            RelativeDirectionEnum direction, List<PointPoi> list)
        {
            //            if (street_count_before_turn == 1)
            //            {
            //                instruction.Text = string.Format("Sla {1}af om op {0} te blijven.",
            //                    this.GetName("nl", street_to),
            //                    TurnDirection(direction));
            //            }
            //            else
            //            {
            //                instruction.Text = string.Format("Neem de {1}de straat {2} om op {0} te blijven.",
            //                    this.GetName("nl", street_to),
            //                    street_count_before_turn,
            //                    TurnDirection(direction));
            //            }
            instruction.Text = string.Format ("Draai {0}", TurnDirection (direction));

            // returns the instruction with text.
            return instruction;
        }
        /// <summary>
        /// Serializes a tags collection to a byte array.
        /// </summary>
        /// <param name="collection"></param>
        /// <returns></returns>
        public byte[] Serialize(TagsCollectionBase collection)
        {
            if (collection.Count > 0)
            {
                RuntimeTypeModel typeModel = TypeModel.Create();
                typeModel.Add(typeof(List<KeyValuePair<string, string>>), true);

                List<KeyValuePair<string, string>> tagsList = new List<KeyValuePair<string, string>>();
                foreach (var tag in collection)
                {
                    tagsList.Add(new KeyValuePair<string, string>(tag.Key, tag.Value));
                }

                byte[] tagsBytes = null;
                using (MemoryStream stream = new MemoryStream())
                {
                    typeModel.Serialize(stream, tagsList);
                    tagsBytes = stream.ToArray();
                }
                return tagsBytes;
            }
            return new byte[0];
        }
Exemple #30
0
 public override void AddTags(Way w, TagsCollectionBase t)
 {
     w.Tags.AddOrReplace(t);
     Assert.AreEqual(1, w.Id.Value);
 }
Exemple #31
0
 /// <summary>
 /// Writes the meta-data to the stream starting at the given position.
 /// </summary>
 /// <param name="stream"></param>
 /// <param name="metaTags"></param>
 private void WriteMeta(Stream stream, TagsCollectionBase metaTags)
 {
     byte[] tagsBytes = (new TagsCollectionSerializer()).Serialize(metaTags);
     stream.Write(BitConverter.GetBytes(tagsBytes.Length), 0, 4);
     stream.Write(tagsBytes, 0, tagsBytes.Length);
 }
 /// <summary>
 /// Generates an instruction for a roundabout.
 /// </summary>
 /// <param name="count"></param>
 /// <param name="street"></param>
 /// <returns></returns>
 protected abstract string GenerateRoundabout(int count, TagsCollectionBase street);
Exemple #33
0
 /// <summary>
 /// Generates an instruction for an immidiate turn.
 /// </summary>
 /// <param name="countBefore"></param>
 /// <param name="firstStreet"></param>
 /// <param name="firstDirection"></param>
 /// <param name="secondStreet"></param>
 /// <param name="secondDirection"></param>
 /// <param name="pois"></param>
 /// <returns></returns>
 protected override string GenerateImmidiateTurn(int countBefore, TagsCollectionBase firstStreet, RelativeDirection firstDirection, TagsCollectionBase secondStreet, RelativeDirection secondDirection, List <PointPoi> pois)
 {
     countBefore++;
     if (countBefore == 1)
     {
         return(string.Format("Nimm die erste Abzweigung {0}, auf die {1}, und fahre sofort {2} auf die {3}.",
                              TurnDirection(firstDirection),
                              this.GetName("de", firstStreet),
                              TurnDirection(secondDirection),
                              this.GetName("de", secondStreet)));
     }
     else
     {
         return(string.Format("Nimm die {4}te Abzweigung {0}, auf die {1}, und fahre sofort {2} auf die {3}.",
                              TurnDirection(firstDirection),
                              this.GetName("de", firstStreet),
                              TurnDirection(secondDirection),
                              this.GetName("de", secondStreet),
                              countBefore));
     }
 }
        /// <summary>
        /// Generates a roudabout instruction.
        /// </summary>
        /// <param name="entryIdx"></param>
        /// <param name="box"></param>
        /// <param name="count"></param>
        /// <param name="next_street"></param>
        internal void GenerateRoundabout(int entryIdx, GeoCoordinateBox box, int count, TagsCollectionBase next_street)
        {
            // create a new instruction first.
            Instruction instruction = new Instruction(entryIdx, box);

            // pass the instruction to the language generator.
            instruction = _generator.GenerateRoundabout(instruction, count, next_street);

            // add the instruction to the instructions list.
            _instructions.Add(instruction);
        }
 /// <summary>
 /// Generates an instruction for an indirect turn.
 /// </summary>
 /// <param name="instruction"></param>
 /// <param name="streetCountTurn"></param>
 /// <param name="streetCountBeforeTurn"></param>
 /// <param name="street_to"></param>
 /// <param name="direction"></param>
 /// <param name="list"></param>
 /// <returns></returns>
 protected abstract string GenerateIndirectFollowTurn(int countBefore, TagsCollectionBase street, RelativeDirection direction, List <PointPoi> list);
Exemple #36
0
 /// <summary>
 /// Trys to return the highwaytype from the tags
 /// </summary>
 /// <param name="tags"></param>
 /// <param name="highwayType"></param>
 /// <returns></returns>
 protected bool TryGetHighwayType(TagsCollectionBase tags, out string highwayType)
 {
     return(tags.TryGetValue("highway", out highwayType));
 }
Exemple #37
0
 /// <summary>
 /// Returns true if the edge can be traversed.
 /// </summary>
 /// <param name="edgeInterpreter"></param>
 /// <param name="tagsIndex"></param>
 /// <param name="tags"></param>
 /// <returns></returns>
 protected abstract bool CalculateIsTraversable(IEdgeInterpreter edgeInterpreter, ITagsCollectionIndex tagsIndex,
                                                TagsCollectionBase tags);
Exemple #38
0
 protected OsmStreamTarget()
 {
     this._meta = (TagsCollectionBase) new TagsCollection();
 }
 /// <summary>
 /// Returns true if the given object can be a routing restriction.
 /// </summary>
 /// <param name="type"></param>
 /// <param name="tags"></param>
 /// <returns></returns>
 public bool IsRestriction(OsmGeoType type, TagsCollectionBase tags)
 { // at least there need to be some tags.
     return(type == OsmGeoType.Node && tags != null && tags.Count > 0);
 }
Exemple #40
0
        /// <summary>
        /// Does the v1 serialization.
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="graph"></param>
        /// <returns></returns>
        protected override void DoSerialize(LimitedStream stream,
                                            DynamicGraphRouterDataSource <LiveEdge> graph)
        {
            // create an index per tile.
            var dataPerTile = new Dictionary <Tile, UnserializedTileData>();

            for (uint vertex = 1; vertex < graph.VertexCount + 1; vertex++)
            { // loop over all vertices and serialize all into the correct tile.
                float latitude, longitude;
                if (graph.GetVertex(vertex, out latitude, out longitude))
                { // the vertex was found.
                    // build the correct tile.
                    Tile tile = Tile.CreateAroundLocation(new GeoCoordinate(latitude, longitude), Zoom);
                    UnserializedTileData serializableGraphTile;
                    if (!dataPerTile.TryGetValue(tile, out serializableGraphTile))
                    { // create the new tile.
                        serializableGraphTile             = new UnserializedTileData();
                        serializableGraphTile.Ids         = new List <uint>();
                        serializableGraphTile.Latitude    = new List <ushort>();
                        serializableGraphTile.Longitude   = new List <ushort>();
                        serializableGraphTile.StringTable = new Dictionary <string, int>();
                        serializableGraphTile.Arcs        = new List <SerializableGraphArcs>();

                        dataPerTile.Add(tile, serializableGraphTile);
                    }

                    // create short latitude/longitude.
                    serializableGraphTile.Ids.Add(vertex);
                    serializableGraphTile.Latitude.Add((ushort)(((tile.TopLeft.Latitude - latitude)
                                                                 / tile.Box.DeltaLat) * ushort.MaxValue));
                    serializableGraphTile.Longitude.Add((ushort)(((longitude - tile.TopLeft.Longitude)
                                                                  / tile.Box.DeltaLon) * ushort.MaxValue));

                    // get the arcs.
                    KeyValuePair <uint, LiveEdge>[] arcs = graph.GetArcs(vertex);

                    // serialize the arcs.
                    if (arcs != null && arcs.Length > 0)
                    {
                        var serializableGraphArcs = new SerializableGraphArcs();
                        serializableGraphArcs.DestinationId = new uint[arcs.Length];
                        serializableGraphArcs.Forward       = new bool[arcs.Length];
                        serializableGraphArcs.TileX         = new int[arcs.Length];
                        serializableGraphArcs.TileY         = new int[arcs.Length];
                        serializableGraphArcs.Tags          = new SerializableTags[arcs.Length];

                        for (int idx = 0; idx < arcs.Length; idx++)
                        {
                            KeyValuePair <uint, LiveEdge> arc = arcs[idx];
                            // get destination tile.
                            if (graph.GetVertex(arc.Key, out latitude, out longitude))
                            { // the destionation was found.
                                Tile destinationTile = Tile.CreateAroundLocation(
                                    new GeoCoordinate(latitude, longitude), Zoom);
                                serializableGraphArcs.DestinationId[idx] = arc.Key;
                                serializableGraphArcs.TileX[idx]         = destinationTile.X;
                                serializableGraphArcs.TileY[idx]         = destinationTile.Y;
                                serializableGraphArcs.Forward[idx]       = arc.Value.Forward;

                                // get the tags.
                                TagsCollectionBase tagsCollection =
                                    graph.TagsIndex.Get(arc.Value.Tags);
                                if (tagsCollection != null)
                                {
                                    serializableGraphArcs.Tags[idx]        = new SerializableTags();
                                    serializableGraphArcs.Tags[idx].Keys   = new int[tagsCollection.Count];
                                    serializableGraphArcs.Tags[idx].Values = new int[tagsCollection.Count];
                                    int tagsIndex = 0;
                                    foreach (var tag in tagsCollection)
                                    {
                                        int key;
                                        if (!serializableGraphTile.StringTable.TryGetValue(
                                                tag.Key, out key))
                                        { // string not yet in string table.
                                            key = serializableGraphTile.StringTable.Count;
                                            serializableGraphTile.StringTable.Add(tag.Key,
                                                                                  key);
                                        }
                                        int value;
                                        if (!serializableGraphTile.StringTable.TryGetValue(
                                                tag.Value, out value))
                                        { // string not yet in string table.
                                            value = serializableGraphTile.StringTable.Count;
                                            serializableGraphTile.StringTable.Add(tag.Value,
                                                                                  value);
                                        }
                                        serializableGraphArcs.Tags[idx].Keys[tagsIndex]   = key;
                                        serializableGraphArcs.Tags[idx].Values[tagsIndex] = value;
                                        tagsIndex++;
                                    }
                                }
                            }
                        }

                        serializableGraphTile.Arcs.Add(serializableGraphArcs);
                    }
                }
            }

            // LAYOUT OF V2: {HEADER}{compressionflag(1byte)}{#tiles(4byte)}{tilesMetaEnd(8byte)}{tiles-meta-data-xxxxxxx}{tiles-data}
            // {HEADER} : already written before this method.
            // {#tiles(4byte)} : the number of tiles in this file (calculate the offset of the {tiles-data}
            //                   section using (TileMetaSize * dataPerTile.Count + 4 + 8)
            // {tilesMetaEnd(8byte)} : the end of the meta tiles.
            // {tiles-meta-data-xxxxxxx} : the serialized tile metadata.
            // {tiles-data} : the actual tile data.

            // calculate the space needed for the tile offset.
            const long tileMetaOffset = 1 + 4 + 8;
            long       tileOffset     = TileMetaSize * dataPerTile.Count +
                                        tileMetaOffset; // all tile metadata + a tile count + tags offset.

            // build the tile metadata while writing the tile data.
            stream.Seek(tileOffset, SeekOrigin.Begin);
            var metas = new SerializableGraphTileMetas();

            metas.Length = new int[dataPerTile.Count];
            metas.Offset = new long[dataPerTile.Count];
            metas.TileX  = new int[dataPerTile.Count];
            metas.TileY  = new int[dataPerTile.Count];
            int metasIndex = 0;

            foreach (var unserializedTileData in dataPerTile)
            {
                // create the tile meta.
                metas.TileX[metasIndex]  = unserializedTileData.Key.X;
                metas.TileY[metasIndex]  = unserializedTileData.Key.Y;
                metas.Offset[metasIndex] = stream.Position;

                // create the tile.
                var serializableGraphTile = new SerializableGraphTile();
                serializableGraphTile.Arcs        = unserializedTileData.Value.Arcs.ToArray();
                serializableGraphTile.Ids         = unserializedTileData.Value.Ids.ToArray();
                serializableGraphTile.Latitude    = unserializedTileData.Value.Latitude.ToArray();
                serializableGraphTile.Longitude   = unserializedTileData.Value.Longitude.ToArray();
                serializableGraphTile.StringTable = new string[unserializedTileData.Value.StringTable.Count];
                foreach (var stringEntry in unserializedTileData.Value.StringTable)
                {
                    serializableGraphTile.StringTable[stringEntry.Value] =
                        stringEntry.Key;
                }

                // serialize the tile.
                if (!_compress)
                { // compresses the file.
                    _runtimeTypeModel.Serialize(stream, serializableGraphTile);
                }
                else
                { // first compress the data, then write.
                    var uncompressed = new MemoryStream();
                    _runtimeTypeModel.Serialize(uncompressed, serializableGraphTile);
                    var uncompressedBuffer = uncompressed.ToArray();

                    byte[] compressed = GZipStream.CompressBuffer(uncompressedBuffer);
                    stream.Write(compressed, 0, compressed.Length);
                }

                // calculate the length of the data that was just serialized.
                metas.Length[metasIndex] = (int)(stream.Position - metas.Offset[metasIndex]);

                metasIndex++;
            }

            // serialize all tile meta data.
            stream.Seek(tileMetaOffset, SeekOrigin.Begin);
            _runtimeTypeModel.Serialize(stream, metas);
            long tileMetaEnd = stream.Position; // save the meta and.

            // save all the offsets.
            stream.Seek(0, SeekOrigin.Begin);
            byte[] compressionFlag = new[] { (byte)(_compress ? 1 : 0) };
            stream.Write(compressionFlag, 0, 1);
            byte[] tileCountBytes = BitConverter.GetBytes(metas.TileX.Length);
            stream.Write(tileCountBytes, 0, tileCountBytes.Length);     // 4 bytes
            byte[] tileMetaEndBytes = BitConverter.GetBytes(tileMetaEnd);
            stream.Write(tileMetaEndBytes, 0, tileMetaEndBytes.Length); // 8 bytes

            stream.Flush();
        }
Exemple #41
0
 /// <summary>
 /// Returns true if the edge with given tags can be traversed by the given vehicle.
 /// </summary>
 /// <param name="tags"></param>
 /// <param name="vehicle"></param>
 /// <returns></returns>
 public bool CanBeTraversedBy(TagsCollectionBase tags, Vehicle vehicle)
 {
     return(vehicle.CanTraverse(tags));
 }
Exemple #42
0
        /// <summary>
        ///     Returns true if the edge with the given properties represents a roundabout.
        /// </summary>
        /// <param name="tags"></param>
        /// <returns></returns>
        public bool IsRoundabout(TagsCollectionBase tags)
        {
            string junction;

            return(tags != null && tags.TryGetValue("junction", out junction) && junction == "roundabout");
        }
        /// <summary>
        /// Adds an edge.
        /// </summary>
        /// <param name="forward"></param>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <param name="tags"></param>
        /// <param name="intermediates"></param>
        protected virtual void AddRoadEdge(TagsCollectionBase tags, uint from, uint to, List <GeoCoordinateSimple> intermediates)
        {
            float         latitude;
            float         longitude;
            GeoCoordinate fromCoordinate = null;

            if (_graph.GetVertex(from, out latitude, out longitude))
            { //
                fromCoordinate = new GeoCoordinate(latitude, longitude);
            }
            GeoCoordinate toCoordinate = null;

            if (_graph.GetVertex(to, out latitude, out longitude))
            { //
                toCoordinate = new GeoCoordinate(latitude, longitude);
            }

            if (fromCoordinate != null && toCoordinate != null)
            { // calculate the edge data.
                TEdgeData             existingData;
                ICoordinateCollection forwardShape;
                if (this.GetEdge(_graph, from, to, out existingData, out forwardShape))
                {     // oeps, an edge already exists!
                    if (intermediates != null && intermediates.Count > 0)
                    { // add one of the intermediates as new vertex.
                        uint newVertex;
                        if (forwardShape != null && forwardShape.Count > 0)
                        { // the other edge also has a shape, make sure to also split it.
                            var existingIntermediates = new List <GeoCoordinateSimple>(forwardShape.ToSimpleArray());
                            newVertex = _graph.AddVertex(existingIntermediates[0].Latitude, existingIntermediates[0].Longitude);

                            // add edge before.
                            var beforeEdgeData = this.CalculateEdgeData(_interpreter.EdgeInterpreter, _tagsIndex, tags, true,
                                                                        fromCoordinate, new GeoCoordinate(existingIntermediates[0].Latitude, existingIntermediates[0].Longitude), null);
                            _graph.AddEdge(from, newVertex, beforeEdgeData, null);
                            if (_graph.IsDirected)
                            { // also the need to add the reverse edge.
                                beforeEdgeData = (TEdgeData)beforeEdgeData.Reverse();
                                _graph.AddEdge(newVertex, from, beforeEdgeData, null);
                            }

                            // add edge after.
                            var afterIntermediates = existingIntermediates.GetRange(1, existingIntermediates.Count - 1);
                            var afterEdgeData      = this.CalculateEdgeData(_interpreter.EdgeInterpreter, _tagsIndex, tags, true,
                                                                            new GeoCoordinate(existingIntermediates[0].Latitude, existingIntermediates[0].Longitude), toCoordinate, afterIntermediates);
                            _graph.AddEdge(newVertex, to, afterEdgeData, new CoordinateArrayCollection <GeoCoordinateSimple>(afterIntermediates.ToArray()));
                            if (_graph.IsDirected)
                            { // also the need to add the reverse edge.
                                afterIntermediates.Reverse();
                                afterEdgeData = (TEdgeData)afterEdgeData.Reverse();
                                _graph.AddEdge(to, newVertex, afterEdgeData, new CoordinateArrayCollection <GeoCoordinateSimple>(afterIntermediates.ToArray()));
                            }

                            // remove original edge.
                            _graph.RemoveEdge(from, to, existingData);
                            if (_graph.IsDirected && _graph.CanHaveDuplicates)
                            { // also remove opposite edges.
                                _graph.RemoveEdge(to, from, (TEdgeData)existingData.Reverse());
                            }
                        }

                        newVertex = _graph.AddVertex(intermediates[0].Latitude, intermediates[0].Longitude);
                        var newEdgeData = this.CalculateEdgeData(_interpreter.EdgeInterpreter, _tagsIndex, tags, true,
                                                                 fromCoordinate, new GeoCoordinate(intermediates[0].Latitude, intermediates[0].Longitude), null);
                        _graph.AddEdge(from, newVertex, newEdgeData, null);
                        if (_graph.IsDirected)
                        { // also the need to add the reverse edge.
                            newEdgeData = (TEdgeData)newEdgeData.Reverse();
                            _graph.AddEdge(newVertex, from, newEdgeData, null);
                        }

                        from           = newVertex;
                        fromCoordinate = new GeoCoordinate(intermediates[0].Latitude, intermediates[0].Longitude);
                        intermediates  = intermediates.GetRange(1, intermediates.Count - 1);
                    }
                    else
                    {     // hmm, no intermediates, the other edge should have them.
                        if (forwardShape != null && forwardShape.Count > 0)
                        { // there is a shape, add one of the intermediates as a new vertex.
                            var existingIntermediates = new List <GeoCoordinateSimple>(forwardShape.ToSimpleArray());
                            var newVertex             = _graph.AddVertex(existingIntermediates[0].Latitude, existingIntermediates[0].Longitude);

                            // add edge before.
                            var beforeEdgeData = this.CalculateEdgeData(_interpreter.EdgeInterpreter, _tagsIndex, tags, true,
                                                                        fromCoordinate, new GeoCoordinate(existingIntermediates[0].Latitude, existingIntermediates[0].Longitude), null);
                            _graph.AddEdge(from, newVertex, beforeEdgeData, null);
                            if (_graph.IsDirected)
                            { // also the need to add the reverse edge.
                                beforeEdgeData = (TEdgeData)beforeEdgeData.Reverse();
                                _graph.AddEdge(newVertex, from, beforeEdgeData, null);
                            }

                            // add edge after.
                            var afterIntermediates = existingIntermediates.GetRange(1, existingIntermediates.Count - 1);
                            var afterEdgeData      = this.CalculateEdgeData(_interpreter.EdgeInterpreter, _tagsIndex, tags, true,
                                                                            new GeoCoordinate(existingIntermediates[0].Latitude, existingIntermediates[0].Longitude), toCoordinate, afterIntermediates);
                            _graph.AddEdge(newVertex, to, afterEdgeData, new CoordinateArrayCollection <GeoCoordinateSimple>(afterIntermediates.ToArray()));
                            if (_graph.IsDirected)
                            { // also the need to add the reverse edge.
                                afterIntermediates.Reverse();
                                afterEdgeData = (TEdgeData)afterEdgeData.Reverse();
                                _graph.AddEdge(to, newVertex, afterEdgeData, new CoordinateArrayCollection <GeoCoordinateSimple>(afterIntermediates.ToArray()));
                            }

                            if (_graph.CanHaveDuplicates)
                            { // make sure to remove the existing edge if graph allows duplicates.
                                _graph.RemoveEdge(from, to);
                                if (_graph.IsDirected)
                                { // also remove the reverse.
                                    _graph.RemoveEdge(to, from);
                                }
                            }
                        }
                        else
                        {
                            // do nothing just overwrite what is there, probably a bug in OSM, two overlapping ways, sharing nodes.
                        }
                    }

                    // edge was there already but was removed,split or needs to be replaced.
                    var edgeData = this.CalculateEdgeData(_interpreter.EdgeInterpreter, _tagsIndex, tags, true,
                                                          fromCoordinate, toCoordinate, intermediates);
                    _graph.AddEdge(from, to, edgeData, new CoordinateArrayCollection <GeoCoordinateSimple>(intermediates.ToArray()));
                    if (_graph.IsDirected)
                    { // also the need to add the reverse edge.
                        intermediates.Reverse();
                        edgeData = (TEdgeData)edgeData.Reverse();
                        _graph.AddEdge(to, from, edgeData, new CoordinateArrayCollection <GeoCoordinateSimple>(intermediates.ToArray()));
                    }
                }
                else
                { // edge is not there yet, just add it.
                    ICoordinateCollection intermediatesCollection = null;
                    if (intermediates != null)
                    {
                        intermediatesCollection = new CoordinateArrayCollection <GeoCoordinateSimple>(intermediates.ToArray());
                    }

                    // add new edge.
                    var edgeData = this.CalculateEdgeData(_interpreter.EdgeInterpreter, _tagsIndex, tags, true,
                                                          fromCoordinate, toCoordinate, intermediates);
                    _graph.AddEdge(from, to, edgeData, intermediatesCollection);
                    if (_graph.IsDirected)
                    { // also the need to add the reverse edge.
                        if (intermediates != null)
                        {
                            intermediates.Reverse();
                            intermediatesCollection = new CoordinateArrayCollection <GeoCoordinateSimple>(intermediates.ToArray());
                        }
                        edgeData = (TEdgeData)edgeData.Reverse();
                        _graph.AddEdge(to, from, edgeData, intermediatesCollection);
                    }
                }
            }
        }
Exemple #44
0
        /// <summary>
        /// Returns the weight between two points on an edge with the given tags for the vehicle.
        /// </summary>
        /// <param name="tags"></param>
        /// <param name="from"></param>
        /// <param name="to"></param>
        /// <returns></returns>
        public virtual float Weight(TagsCollectionBase tags, GeoCoordinate from, GeoCoordinate to)
        {
            var distance = from.DistanceEstimate(to).Value;

            return((float)(distance / (this.ProbableSpeed(tags).Value) * 3.6));
        }
Exemple #45
0
 /// <summary>
 /// Calculates the edge data.
 /// </summary>
 /// <returns></returns>
 protected abstract TEdgeData CalculateEdgeData(IEdgeInterpreter edgeInterpreter, ITagsCollectionIndex tagsIndex, TagsCollectionBase tags,
                                                bool directionForward, GeoCoordinate from, GeoCoordinate to);
 /// <summary>
 /// Calculates the edge data.
 /// </summary>
 /// <returns></returns>
 protected abstract TEdgeData CalculateEdgeData(IEdgeInterpreter edgeInterpreter, ITagsIndex tagsIndex, TagsCollectionBase tags,
                                                bool tagsForward, GeoCoordinate from, GeoCoordinate to, List <GeoCoordinateSimple> intermediates);
        /// <summary>
        /// Generates an immidiate turn instruction.
        /// </summary>
        /// <param name="entryIdx"></param>
        /// <param name="box"></param>
        /// <param name="before_name"></param>
        /// <param name="first_direction"></param>
        /// <param name="first_street_count_to"></param>
        /// <param name="second_direction"></param>
        /// <param name="first_street_to"></param>
        /// <param name="second_street_to"></param>
        /// <param name="list"></param>
        internal void GenerateImmidiateTurn(int entryIdx, GeoCoordinateBox box,
                                            TagsCollectionBase before_name, RelativeDirection first_direction, int first_street_count_to,
                                            RelativeDirection second_direction, TagsCollectionBase first_street_to, TagsCollectionBase second_street_to, List <PointPoi> list)
        {
            // create a new instruction first.
            Instruction instruction = new Instruction(entryIdx, box);

            // pass the instruction to the language generator.
            instruction = _generator.GenerateImmidiateTurn(
                instruction, first_street_count_to, first_street_to, first_direction, second_street_to, second_direction);

            // add the instruction to the instructions list.
            _instructions.Add(instruction);
        }
Exemple #48
0
 /// <summary>
 /// Creates a new target.
 /// </summary>
 protected OsmStreamTarget()
 {
     _meta = new TagsCollection();
 }
Exemple #49
0
 /// <summary>
 /// Evaluates the filter against the tags collection
 /// </summary>
 public abstract TagsCollectionBase Evaluate(TagsCollectionBase tags, OsmGeoType type);
Exemple #50
0
 public virtual bool CanStopOn(TagsCollectionBase attributes)
 {
     return(this._canStop(attributes));
 }
 /// <summary>
 /// Generates an instruction for an immidiate turn.
 /// </summary>
 /// <param name="countBefore"></param>
 /// <param name="firstStreet"></param>
 /// <param name="firstDirection"></param>
 /// <param name="secondStreet"></param>
 /// <param name="secondDirection"></param>
 /// <param name="pois"></param>
 /// <returns></returns>
 protected abstract string GenerateImmidiateTurn(int countBefore, TagsCollectionBase firstStreet, RelativeDirection firstDirection, TagsCollectionBase secondStreet, RelativeDirection secondDirection, List <PointPoi> pois);
Exemple #52
0
 public virtual Speed Speed(TagsCollectionBase attributes)
 {
     return(this._getSpeed(attributes));
 }
Exemple #53
0
 /// <summary>
 /// Generates an instruction for an indirect turn.
 /// </summary>
 /// <param name="countBefore"></param>
 /// <param name="street"></param>
 /// <param name="direction"></param>
 /// <param name="pois"></param>
 /// <returns></returns>
 protected override string GenerateIndirectTurn(int countBefore, TagsCollectionBase street, RelativeDirection direction, List <PointPoi> pois)
 {
     return(string.Format("Fahre {1}.", countBefore, TurnDirection(direction), this.GetName("de", street)));
 }
Exemple #54
0
 public virtual bool Equals(TagsCollectionBase edge1, TagsCollectionBase edge2)
 {
     return(this._equals(edge1, edge2));
 }
 /// <summary>
 /// Creates a tag attribute collection.
 /// </summary>
 public TagAttributeCollection(TagsCollectionBase tagsCollection)
 {
     _tagCollection = tagsCollection;
 }
Exemple #56
0
 /// <summary>
 /// Adds relation tags to the given way.
 /// </summary>
 public abstract void AddTags(Way way, TagsCollectionBase attributes);
Exemple #57
0
 /// <summary>
 /// Returns true if the vehicle is allowed on the way represented by these tags
 /// </summary>
 /// <param name="tags"></param>
 /// <param name="highwayType"></param>
 /// <returns></returns>
 protected abstract bool IsVehicleAllowed(TagsCollectionBase tags, string highwayType);
Exemple #58
0
        /// <summary>
        /// Serializes the given graph and tags index to the given stream.
        /// </summary>
        /// <param name="stream"></param>
        /// <param name="graph"></param>
        /// <param name="metaTags"></param>
        public void Serialize(Stream stream, DynamicGraphRouterDataSource <TEdgeData> graph, TagsCollectionBase metaTags)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }
            if (graph == null)
            {
                throw new ArgumentNullException("graph");
            }

            // write the header.
            this.WriteVersionHeader(stream);

            // write the vehicles.
            this.WriteVehicleProfiles(stream, graph.GetSupportedProfiles());

            // write the meta-data.
            this.WriteMeta(stream, metaTags);

            // wrap the stream.
            var routingSerializerStream = new LimitedStream(stream);

            // do the version-specific serialization.
            this.DoSerialize(routingSerializerStream, graph);
        }
Exemple #59
0
 /// <summary>
 ///     Returns true if the edge with the given properties represents a roundabout.
 /// </summary>
 /// <param name="tags"></param>
 /// <returns></returns>
 public bool IsRoundabout(TagsCollectionBase tags)
 {
     string junction;
     return (tags != null && tags.TryGetValue("junction", out junction) && junction == "roundabout");
 }
Exemple #60
0
 /// <summary>
 /// Returns true if the edge is one way forward, false if backward, null if bidirectional.
 /// </summary>
 /// <param name="tags"></param>
 /// <returns></returns>
 public override bool?IsOneWay(TagsCollectionBase tags)
 {
     return(null);
 }