public void TestRandomBlockTagSerializatonNonBeginPositionLimitedStreamRegression() { SimpleTagsCollectionIndex tagsIndex = new SimpleTagsCollectionIndex(); SimpleTagsCollection tagsCollection = new SimpleTagsCollection(); for (int i = 0; i < 101; i++) { int tagCollectionSize = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(10) + 1; for (int idx = 0; idx < tagCollectionSize; idx++) { int tagValue = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(10); tagsCollection.Add( string.Format("key_{0}", tagValue), string.Format("value_{0}", tagValue)); } uint tagsId = tagsIndex.Add(tagsCollection); } ITagsCollectionIndexReadonly tagsIndexReadonly = this.SerializeDeserializeBlockLimitedStream(tagsIndex, 10, 123); Assert.AreEqual(tagsIndex.Max, tagsIndexReadonly.Max); for (uint idx = 0; idx < tagsIndex.Max; idx++) { this.CompareTagsCollections(tagsIndex.Get(idx), tagsIndexReadonly.Get(idx)); } }
/// <summary> /// Creates the tags in the given table. /// </summary> /// <param name="id"></param> /// <param name="new_tags"></param> /// <param name="table"></param> /// <param name="ref_column"></param> public void CreateTags(long id, TagsCollection new_tags, string table, string ref_column) { OracleCommand command; // copy the source tags dictionary. TagsCollection tagsToInsert; if (new_tags == null) { tagsToInsert = new SimpleTagsCollection(); } else { tagsToInsert = new SimpleTagsCollection(new_tags); } // insert tags. foreach (Tag pair in tagsToInsert) { command = this.CreateCommand(string.Format("insert into {0} ({1},key,value) values (:{1},:key,:value)", table, ref_column)); command.Parameters.Add(new OracleParameter("ref_column", id)); command.Parameters.Add(new OracleParameter("key", pair.Key)); command.Parameters.Add(new OracleParameter("value", pair.Value)); command.ExecuteNonQuery(); command.Dispose(); } }
/// <summary> /// Returns true if the point between the two arcs represents a significant step in the route. /// </summary> /// <param name="previous_arc"></param> /// <param name="next_arc"></param> /// <param name="vehicle"></param> /// <returns></returns> private bool IsSignificant(Vehicle vehicle, AggregatedArc previous_arc, AggregatedArc next_arc) { if (previous_arc.Next.Points != null && previous_arc.Next.Points.Count > 0) { // the point has at least one important point. return(true); } if (previous_arc.Next.ArcsNotTaken != null && previous_arc.Next.ArcsNotTaken.Count > 0) { // the point has at least one arc not taken. return(true); } // create tag interpreters for arcs to try and work out if the arcs are different for the given vehicle. TagsCollection previousTagsDic = new SimpleTagsCollection(); foreach (Tag pair in previous_arc.Tags) { previousTagsDic.Add(pair.Key, pair.Value); } var nextTagsDic = new SimpleTagsCollection(); foreach (Tag pair in next_arc.Tags) { nextTagsDic.Add(pair.Key, pair.Value); } if (!vehicle.IsEqualFor(previousTagsDic, nextTagsDic)) { // the previous and the next edge do not represent a change for the given vehicle. //RoadTagsInterpreterBase previous_interpreter = new RoadTagsInterpreterBase(previous_tags_dic); //RoadTagsInterpreterBase next_interpreter = new RoadTagsInterpreterBase(next_tags_dic); //if (!previous_interpreter.IsEqualForVehicle(vehicle, next_interpreter)) //{ return(true); } return(false); }
public void TestEdgeMatcher() { IEdgeMatcher matcher = new DefaultEdgeMatcher(); // create edge tags. var edgeTags = new SimpleTagsCollection(); //edge_tags["highway"] = "footway"; // create point tags. var pointTags = new SimpleTagsCollection(); //point_tags["highway"] = "footway"; // test with empty point tags. Assert.IsTrue(matcher.MatchWithEdge(Vehicle.Car, null, null)); Assert.IsTrue(matcher.MatchWithEdge(Vehicle.Car, pointTags, null)); // test with empty edge tags. pointTags["name"] = "Ben Abelshausen Boulevard"; Assert.IsFalse(matcher.MatchWithEdge(Vehicle.Car, pointTags, null)); Assert.IsFalse(matcher.MatchWithEdge(Vehicle.Car, pointTags, edgeTags)); // test with matching name. edgeTags["name"] = "Ben Abelshausen Boulevard"; Assert.IsTrue(matcher.MatchWithEdge(Vehicle.Car, pointTags, edgeTags)); // test with none-matching name. edgeTags["name"] = "Jorieke Vyncke Boulevard"; Assert.IsFalse(matcher.MatchWithEdge(Vehicle.Car, pointTags, edgeTags)); }
public void MapCSSEvalTagTest() { string function = "tag('width')"; TagsCollection tags = new SimpleTagsCollection(); tags.Add("width", "2"); Assert.AreEqual(2, EvalInterpreter.Instance.InterpretDouble(function, tags)); }
/// <summary> /// Tests an empty tags collection. /// </summary> protected void TestTagsCollectionSimple() { TagsCollection collection = new SimpleTagsCollection(); collection["simple"] = "yes"; Assert.IsTrue(collection.ContainsKey("simple")); Assert.IsTrue(collection.ContainsKeyValue("simple", "yes")); Assert.AreEqual("yes", collection["simple"]); Assert.AreEqual(1, collection.Count); }
public void TestBooleanParsing() { // test IsTrue. TagsCollection tags = new SimpleTagsCollection(); tags.Add("area", "yes"); Assert.IsTrue(tags.IsTrue("area")); tags = new SimpleTagsCollection(); tags.Add("area", "1"); Assert.IsTrue(tags.IsTrue("area")); tags = new SimpleTagsCollection(); tags.Add("area", "true"); Assert.IsTrue(tags.IsTrue("area")); tags = new SimpleTagsCollection(); tags.Add("area", "false"); Assert.IsFalse(tags.IsTrue("area")); tags = new SimpleTagsCollection(); tags.Add("area", "0"); Assert.IsFalse(tags.IsTrue("area")); tags = new SimpleTagsCollection(); tags.Add("area", "no"); Assert.IsFalse(tags.IsTrue("area")); // test IsFalse. tags = new SimpleTagsCollection(); tags.Add("area", "yes"); Assert.IsFalse(tags.IsFalse("area")); tags = new SimpleTagsCollection(); tags.Add("area", "1"); Assert.IsFalse(tags.IsFalse("area")); tags = new SimpleTagsCollection(); tags.Add("area", "true"); Assert.IsFalse(tags.IsFalse("area")); tags = new SimpleTagsCollection(); tags.Add("area", "false"); Assert.IsTrue(tags.IsFalse("area")); tags = new SimpleTagsCollection(); tags.Add("area", "0"); Assert.IsTrue(tags.IsFalse("area")); tags = new SimpleTagsCollection(); tags.Add("area", "no"); Assert.IsTrue(tags.IsFalse("area")); }
/// <summary> /// Tests the probable speed. /// </summary> /// <param name="vehicle"></param> /// <param name="speed"></param> /// <param name="tags"></param> protected void TextProbableSpeed(Vehicle vehicle, double speed, params string[] tags) { // build tags collection. SimpleTagsCollection tagsCollection = new SimpleTagsCollection(); for (int idx = 0; idx < tags.Length; idx = idx + 2) { tagsCollection.Add(tags[idx], tags[idx + 1]); } Assert.AreEqual(speed, vehicle.ProbableSpeed(tagsCollection).Value); }
/// <summary> /// Converts a RouteTags array to a list of KeyValuePairs. /// </summary> /// <param name="tags"></param> /// <returns></returns> public static TagsCollection ConvertToTagsCollection(this RouteTags[] tags) { var tagsList = new SimpleTagsCollection(); if (tags != null) { foreach (RouteTags pair in tags) { tagsList.Add(new Tag(pair.Key, pair.Value)); } } return(tagsList); }
private static TagsCollection ConvertToTags(Osm.Xml.v0_6.tag[] tag) { TagsCollection tags = null; if (tag != null && tag.Length > 0) { tags = new SimpleTagsCollection(); foreach (Osm.Xml.v0_6.tag t in tag) { tags.Add(t.k, t.v); } } return(tags); }
/// <summary> /// Deserializes a tags index from the given stream. /// </summary> /// <param name="stream"></param> /// <returns></returns> public static ITagsCollectionIndexReadonly Deserialize(Stream stream) { byte[] intBytes = new byte[4]; stream.Read(intBytes, 0, 4); int startOfTags = BitConverter.ToInt32(intBytes, 0); stream.Read(intBytes, 0, 4); int endOfFile = BitConverter.ToInt32(intBytes, 0); RuntimeTypeModel typeModel = TagIndexSerializer.CreateTypeModel(); byte[] stringTableBytes = new byte[startOfTags - 8]; stream.Read(stringTableBytes, 0, stringTableBytes.Length); MemoryStream memoryStream = new MemoryStream(stringTableBytes); List <string> strings = typeModel.Deserialize(memoryStream, null, typeof(List <string>)) as List <string>; memoryStream.Dispose(); byte[] tagsIndexBytes = new byte[endOfFile - startOfTags]; stream.Read(tagsIndexBytes, 0, tagsIndexBytes.Length); memoryStream = new MemoryStream(tagsIndexBytes); List <KeyValuePair <uint, List <KeyValuePair <uint, uint> > > > tagsIndexTableList = typeModel.Deserialize(memoryStream, null, typeof(List <KeyValuePair <uint, List <KeyValuePair <uint, uint> > > >)) as List <KeyValuePair <uint, List <KeyValuePair <uint, uint> > > >; memoryStream.Dispose(); Dictionary <uint, SimpleTagsCollection> tagsIndexList = new Dictionary <uint, SimpleTagsCollection>(); for (int idx = 0; idx < tagsIndexTableList.Count; idx++) { KeyValuePair <uint, List <KeyValuePair <uint, uint> > > serializedTagsCollection = tagsIndexTableList[idx]; SimpleTagsCollection tagsCollection = new SimpleTagsCollection(); if (serializedTagsCollection.Value != null) { foreach (KeyValuePair <uint, uint> pair in serializedTagsCollection.Value) { tagsCollection.Add( new Tag(strings[(int)pair.Key], strings[(int)pair.Value])); } } tagsIndexList.Add(serializedTagsCollection.Key, tagsCollection); } return(new TagsIndexReadonly(tagsIndexList)); }
public void TestSimpleTagSerializatonNonBeginPosition() { SimpleTagsCollectionIndex tagsIndex = new SimpleTagsCollectionIndex(); SimpleTagsCollection tagsCollection = new SimpleTagsCollection(); tagsCollection.Add("key1", "value1"); uint tagsId = tagsIndex.Add(tagsCollection); ITagsCollectionIndexReadonly tagsIndexReadonly = this.SerializeDeserialize(tagsIndex, 1201); Assert.AreEqual(tagsIndex.Max, tagsIndexReadonly.Max); for (uint idx = 0; idx < tagsIndex.Max; idx++) { this.CompareTagsCollections(tagsIndex.Get(idx), tagsIndexReadonly.Get(idx)); } }
/// <summary> /// Tests the can traverse functionality. /// </summary> protected void TestVehicleCanTranverse(Vehicle vehicle, bool result, params string[] tags) { // build tags collection. SimpleTagsCollection tagsCollection = new SimpleTagsCollection(); for (int idx = 0; idx < tags.Length; idx = idx + 2) { tagsCollection.Add(tags[idx], tags[idx + 1]); } if (result) { // assume the result is true. Assert.IsTrue(vehicle.CanTraverse(tagsCollection)); } else { // assume the result is false. Assert.IsFalse(vehicle.CanTraverse(tagsCollection)); } }
/// <summary> /// Deserializes a tags index from the given stream. /// </summary> /// <param name="stream"></param> /// <returns></returns> public static ITagsIndexReadonly Deserialize(Stream stream) { byte[] intBytes = new byte[4]; stream.Read(intBytes, 0, 4); int startOfTags = BitConverter.ToInt32(intBytes, 0); stream.Read(intBytes, 0, 4); int endOfFile = BitConverter.ToInt32(intBytes, 0); RuntimeTypeModel typeModel = TagIndexSerializer.CreateTypeModel(); byte[] stringTableBytes = new byte[startOfTags - 8]; stream.Read(stringTableBytes, 0, stringTableBytes.Length); MemoryStream memoryStream = new MemoryStream(stringTableBytes); List<string> strings = typeModel.Deserialize(memoryStream, null, typeof(List<string>)) as List<string>; memoryStream.Dispose(); byte[] tagsIndexBytes = new byte[endOfFile - startOfTags]; stream.Read(tagsIndexBytes, 0, tagsIndexBytes.Length); memoryStream = new MemoryStream(tagsIndexBytes); List<KeyValuePair<uint, List<KeyValuePair<uint, uint>>>> tagsIndexTableList = typeModel.Deserialize(memoryStream, null, typeof(List<KeyValuePair<uint, List<KeyValuePair<uint, uint>>>>)) as List<KeyValuePair<uint, List<KeyValuePair<uint, uint>>>>; memoryStream.Dispose(); Dictionary<uint, SimpleTagsCollection> tagsIndexList = new Dictionary<uint, SimpleTagsCollection>(); for(int idx = 0; idx < tagsIndexTableList.Count; idx++) { KeyValuePair<uint, List<KeyValuePair<uint, uint>>> serializedTagsCollection = tagsIndexTableList[idx]; SimpleTagsCollection tagsCollection = new SimpleTagsCollection(); if (serializedTagsCollection.Value != null) { foreach (KeyValuePair<uint, uint> pair in serializedTagsCollection.Value) { tagsCollection.Add( new Tag(strings[(int)pair.Key], strings[(int)pair.Value])); } } tagsIndexList.Add(serializedTagsCollection.Key, tagsCollection); } return new TagsIndexReadonly(tagsIndexList); }
/// <summary> /// Tests the given tags collection index. /// </summary> /// <param name="tagsCollectionIndex"></param> protected void TestTagsCollectionIndex(ITagsCollectionIndex tagsCollectionIndex) { Dictionary <uint, TagsCollection> addedTags = new Dictionary <uint, TagsCollection>(); for (int i = 0; i < 100; i++) { SimpleTagsCollection tagsCollection = new SimpleTagsCollection(); int tagCollectionSize = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(3) + 1; for (int idx = 0; idx < tagCollectionSize; idx++) { int tagValue = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(3); tagsCollection.Add( string.Format("key_{0}", tagValue), string.Format("value_{0}", tagValue)); } int addCount = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(2) + 1; for (int idx = 0; idx < addCount; idx++) { uint tagsId = tagsCollectionIndex.Add(tagsCollection); addedTags[tagsId] = tagsCollection; TagsCollection indexTags = tagsCollectionIndex.Get(tagsId); Assert.AreEqual(tagsCollection.Count, indexTags.Count); foreach (Tag tag in tagsCollection) { Assert.IsTrue(indexTags.ContainsKeyValue(tag.Key, tag.Value)); } } } // check the index. foreach (KeyValuePair <uint, TagsCollection> pair in addedTags) { TagsCollection indexTags = tagsCollectionIndex.Get(pair.Key); Assert.AreEqual(pair.Value.Count, indexTags.Count); foreach (Tag tag in pair.Value) { Assert.IsTrue(indexTags.ContainsKeyValue(tag.Key, tag.Value)); } } }
/// <summary> /// Converts the given tagscollection from a tags list. /// </summary> /// <param name="tags"></param> /// <returns></returns> public static TagsCollection ConvertFrom(List <RedisTag> tags) { TagsCollection redisTags = null; if (tags != null) { redisTags = new SimpleTagsCollection(); if (tags != null) { foreach (RedisTag redisTag in tags) { Tag tag = new Tag(); tag.Key = redisTag.Key; tag.Value = redisTag.Value; redisTags.Add(tag); } } } return(redisTags); }
/// <summary> /// Interprets an OSM-object and returns the corresponding geometry. /// </summary> /// <param name="osmObject"></param> /// <returns></returns> public override GeometryCollection Interpret(CompleteOsmGeo osmObject) { // DISCLAIMER: this is a very very very simple geometry interpreter and // contains hardcoded all relevant tags. GeometryCollection collection = new GeometryCollection(); TagsCollection tags; if (osmObject != null) { switch (osmObject.Type) { case CompleteOsmType.Node: SimpleTagsCollection newCollection = new SimpleTagsCollection( osmObject.Tags); newCollection.RemoveKey("FIXME"); newCollection.RemoveKey("node"); newCollection.RemoveKey("source"); if (newCollection.Count > 0) { // there is still some relevant information left. collection.Add(new Point((osmObject as CompleteNode).Coordinate)); } break; case CompleteOsmType.Way: tags = osmObject.Tags; bool isArea = false; if ((tags.ContainsKey("building") && !tags.IsFalse("building")) || (tags.ContainsKey("landuse") && !tags.IsFalse("landuse")) || (tags.ContainsKey("amenity") && !tags.IsFalse("amenity")) || (tags.ContainsKey("harbour") && !tags.IsFalse("harbour")) || (tags.ContainsKey("historic") && !tags.IsFalse("historic")) || (tags.ContainsKey("leisure") && !tags.IsFalse("leisure")) || (tags.ContainsKey("man_made") && !tags.IsFalse("man_made")) || (tags.ContainsKey("military") && !tags.IsFalse("military")) || (tags.ContainsKey("natural") && !tags.IsFalse("natural")) || (tags.ContainsKey("office") && !tags.IsFalse("office")) || (tags.ContainsKey("place") && !tags.IsFalse("place")) || (tags.ContainsKey("power") && !tags.IsFalse("power")) || (tags.ContainsKey("public_transport") && !tags.IsFalse("public_transport")) || (tags.ContainsKey("shop") && !tags.IsFalse("shop")) || (tags.ContainsKey("sport") && !tags.IsFalse("sport")) || (tags.ContainsKey("tourism") && !tags.IsFalse("tourism")) || (tags.ContainsKey("waterway") && !tags.IsFalse("waterway")) || (tags.ContainsKey("wetland") && !tags.IsFalse("wetland")) || (tags.ContainsKey("water") && !tags.IsFalse("water")) || (tags.ContainsKey("aeroway") && !tags.IsFalse("aeroway"))) { // these tags usually indicate an area. isArea = true; } if (tags.IsTrue("area")) { // explicitly indicated that this is an area. isArea = true; } else if (tags.IsFalse("area")) { // explicitly indicated that this is not an area. isArea = false; } if (isArea) { // area tags leads to simple polygon LineairRing lineairRing = new LineairRing((osmObject as CompleteWay).GetCoordinates().ToArray <GeoCoordinate>()); lineairRing.Attributes = new SimpleGeometryAttributeCollection(tags); collection.Add(lineairRing); } else { // no area tag leads to just a line. LineString lineString = new LineString((osmObject as CompleteWay).GetCoordinates().ToArray <GeoCoordinate>()); lineString.Attributes = new SimpleGeometryAttributeCollection(tags); collection.Add(lineString); } break; case CompleteOsmType.Relation: CompleteRelation relation = (osmObject as CompleteRelation); tags = relation.Tags; string typeValue; if (tags.TryGetValue("type", out typeValue)) { // there is a type in this relation. if (typeValue == "multipolygon") { // this relation is a multipolygon. Geometry geometry = this.InterpretMultipolygonRelation(relation); if (geometry != null) { // add the geometry. collection.Add(geometry); } } else if (typeValue == "boundary") { // this relation is a boundary. } } break; } } return(collection); }
/// <summary> /// Adds a given way. /// </summary> /// <param name="way"></param> public override void AddWay(Way way) { if (!_preIndexMode && _waysToCache != null && _waysToCache.Contains(way.Id.Value)) { // cache this way? _dataCache.AddWay(way); } // initialize the way interpreter. if (_interpreter.EdgeInterpreter.IsRoutable(way.Tags)) { // the way is a road. if (_preIndexMode) { // index only relevant nodes. if (way.Nodes != null) { foreach (long node in way.Nodes) { if (_preIndex.Contains(node)) { _usedTwiceOrMore.Add(node); } else { _preIndex.Add(node); // node is relevant. } } } } else { // add the forward edges. //if (!interpreter.IsOneWayReverse()) if (true) // add backward edges too! { // loop over all edges. if (way.Nodes != null && way.Nodes.Count > 1) { // way has at least two nodes. // keep the relevant tags. TagsCollection relevantTags = new SimpleTagsCollection(); foreach (var relevantTag in way.Tags) { if (_interpreter.IsRelevant(relevantTag.Key)) { relevantTags.Add(relevantTag); } } if (this.CalculateIsTraversable(_interpreter.EdgeInterpreter, _tagsIndex, relevantTags)) { // the edge is traversable, add the edges. uint?from = this.AddRoadNode(way.Nodes[0]); for (int idx = 1; idx < way.Nodes.Count; idx++) { // the to-node. uint?to = this.AddRoadNode(way.Nodes[idx]); // add the edge(s). if (from.HasValue && to.HasValue) { // add a road edge. if (!this.AddRoadEdge(relevantTags, true, from.Value, to.Value)) { // add the reverse too if it has been indicated that this was needed. this.AddRoadEdge(relevantTags, false, to.Value, from.Value); } } from = to; // the to node becomes the from. } } } } } } }
/// <summary> /// Tests the edge matcher in combination with dykstra routing. /// </summary> /// <param name="name"></param> /// <param name="highway"></param> /// <param name="vehicle"></param> /// <param name="matcher"></param> /// <param name="pointName"></param> /// <param name="notFound"></param> private void TestResolveOnEdgeSingle(string name, string highway, Vehicle vehicle, IEdgeMatcher matcher, string pointName, bool notFound) { var fromName = new GeoCoordinate(51.0003, 4.0007); var toName = new GeoCoordinate(51.0003, 4.0008); var fromNoname = new GeoCoordinate(51.0, 4.0007); var toNoname = new GeoCoordinate(51.0, 4.0008); TagsCollection pointTags = new SimpleTagsCollection(); pointTags["name"] = pointName; TagsCollection tags = new SimpleTagsCollection(); tags["highway"] = highway; //tags["name"] = name; var tagsIndex = new SimpleTagsIndex(); // do the data processing. var data = new DynamicGraphRouterDataSource <LiveEdge>(tagsIndex); uint vertexNoname1 = data.AddVertex((float)fromNoname.Latitude, (float)fromNoname.Longitude); uint vertexNoname2 = data.AddVertex((float)toNoname.Latitude, (float)toNoname.Longitude); data.AddArc(vertexNoname1, vertexNoname2, new LiveEdge() { Forward = true, Tags = tagsIndex.Add(tags) }, null); tags = new SimpleTagsCollection(); tags["highway"] = highway; tags["name"] = name; uint vertexName1 = data.AddVertex((float)fromName.Latitude, (float)fromName.Longitude); uint vertexName2 = data.AddVertex((float)toName.Latitude, (float)toName.Longitude); data.AddArc(vertexName1, vertexName2, new LiveEdge() { Forward = true, Tags = tagsIndex.Add(tags) }, null); IRoutingInterpreter interpreter = new OsmRoutingInterpreter(); // creates the data. IBasicRouter <LiveEdge> router = new DykstraRoutingLive( data.TagsIndex); var nonameLocation = new GeoCoordinate( (fromNoname.Latitude + toNoname.Latitude) / 2.0, (fromNoname.Longitude + toNoname.Longitude) / 2.0); var nameLocation = new GeoCoordinate( (fromName.Latitude + toName.Latitude) / 2.0, (fromName.Longitude + toName.Longitude) / 2.0); const float delta = 0.01f; SearchClosestResult result = router.SearchClosest(data, interpreter, vehicle, nonameLocation, delta, matcher, pointTags); if (result.Distance < double.MaxValue) { // there is a result. Assert.IsFalse(notFound, "A result was found but was supposed not to be found!"); if (name == pointName) { // the name location was supposed to be found! Assert.IsTrue(result.Vertex1 == vertexName1 || result.Vertex1 == vertexName2); Assert.IsTrue(result.Vertex2 == vertexName1 || result.Vertex2 == vertexName2); } else { // the noname location was supposed to be found! Assert.IsTrue(result.Vertex1 == vertexNoname1 || result.Vertex1 == vertexNoname2); Assert.IsTrue(result.Vertex2 == vertexNoname1 || result.Vertex2 == vertexNoname2); } return; } Assert.IsTrue(notFound, "A result was not found but was supposed to be found!"); }
/// <summary> /// Tests an empty tags collection. /// </summary> protected void TestTagsCollectionEmpty() { TagsCollection collection = new SimpleTagsCollection(); Assert.AreEqual(0, collection.Count); }
public void TestOsmRoutingInterpreterCanBeTraversedBy() { var interpreter = new OsmRoutingInterpreter(); TagsCollection tags = new SimpleTagsCollection(); tags["highway"] = "footway"; Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Pedestrian)); Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bicycle)); Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Moped)); Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.MotorCycle)); Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Car)); Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.SmallTruck)); Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.BigTruck)); Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bus)); tags["highway"] = "cycleway"; Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Pedestrian)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bicycle)); Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Moped)); Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.MotorCycle)); Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Car)); Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.SmallTruck)); Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.BigTruck)); Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bus)); tags["highway"] = "bridleway"; Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Pedestrian)); Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bicycle)); Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Moped)); Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.MotorCycle)); Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Car)); Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.SmallTruck)); Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.BigTruck)); Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bus)); tags["highway"] = "path"; Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Pedestrian)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bicycle)); Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Moped)); Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.MotorCycle)); Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Car)); Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.SmallTruck)); Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.BigTruck)); Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bus)); tags["highway"] = "pedestrian"; Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Pedestrian)); Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bicycle)); Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Moped)); Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.MotorCycle)); Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Car)); Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.SmallTruck)); Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.BigTruck)); Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bus)); tags["highway"] = "road"; Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Pedestrian)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bicycle)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Moped)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.MotorCycle)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Car)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.SmallTruck)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.BigTruck)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bus)); tags["highway"] = "living_street"; Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Pedestrian)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bicycle)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Moped)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.MotorCycle)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Car)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.SmallTruck)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.BigTruck)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bus)); tags["highway"] = "residential"; Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Pedestrian)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bicycle)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Moped)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.MotorCycle)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Car)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.SmallTruck)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.BigTruck)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bus)); tags["highway"] = "unclassified"; Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Pedestrian)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bicycle)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Moped)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.MotorCycle)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Car)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.SmallTruck)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.BigTruck)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bus)); tags["highway"] = "tertiary"; Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Pedestrian)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bicycle)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Moped)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.MotorCycle)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Car)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.SmallTruck)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.BigTruck)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bus)); tags["highway"] = "secondary"; Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Pedestrian)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bicycle)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Moped)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.MotorCycle)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Car)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.SmallTruck)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.BigTruck)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bus)); tags["highway"] = "primary"; Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Pedestrian)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bicycle)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Moped)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.MotorCycle)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Car)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.SmallTruck)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.BigTruck)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bus)); tags["highway"] = "trunk"; Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Pedestrian)); Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bicycle)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Moped)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.MotorCycle)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Car)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.SmallTruck)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.BigTruck)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bus)); tags["highway"] = "motorway"; Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Pedestrian)); Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bicycle)); Assert.IsFalse(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Moped)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.MotorCycle)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Car)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.SmallTruck)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.BigTruck)); Assert.IsTrue(interpreter.EdgeInterpreter.CanBeTraversedBy(tags, Vehicle.Bus)); }
private void ModifyTags(long id, TagsCollection neTags, string table, string refColumn) { OracleCommand command; TagsCollection tagsToInsert = null; if (neTags == null) { tagsToInsert = new SimpleTagsCollection(); } else { tagsToInsert = new SimpleTagsCollection(neTags); } // suppose there are no tags present yet. TagsCollection tags_to_update = new SimpleTagsCollection(); TagsCollection tags_to_delete = new SimpleTagsCollection(); // adjust the data based on the tags already present. command = this.CreateCommand(string.Format("select * from {0} where {1}=:{1}", table, refColumn)); command.Parameters.Add(refColumn, id); OracleDataReader reader = command.ExecuteReader(); while (reader.Read()) { string k = reader["key"].ToStringEmptyWhenNull(); string v = reader["value"].ToStringEmptyWhenNull(); if (tagsToInsert.ContainsKey(k)) { // there is at least an update or no insert. string new_value = tagsToInsert[k]; tagsToInsert.RemoveKeyValue(new Tag(k, v)); // see if there is an update needed. if (new_value != v) { // tags need to be updated. tags_to_update.Add(k, new_value); } } else { // tags are not found; delete them! tags_to_delete.Add(k, v); } } reader.Close(); // delete old tags. foreach (Tag tag in tags_to_delete) { command = this.CreateCommand(string.Format("delete from {0} where {1}=:{1} and key=:key", table, refColumn)); command.Parameters.Add(new OracleParameter(refColumn, id)); command.Parameters.Add(new OracleParameter("key", tag.Key)); command.ExecuteNonQuery(); command.Dispose(); } // update tags. foreach (Tag pair in tags_to_update) { command = this.CreateCommand(string.Format("update {0} set value=:value where {1}=:{1} and key=:key", table, refColumn)); command.Parameters.Add(new OracleParameter("value", pair.Value)); command.Parameters.Add(new OracleParameter(refColumn, id)); command.Parameters.Add(new OracleParameter("key", pair.Key)); command.ExecuteNonQuery(); command.Dispose(); } // insert tags. foreach (Tag pair in tagsToInsert) { command = this.CreateCommand(string.Format("insert into {0} ({1},key,value) values (:{1},:key,:value)", table, refColumn)); command.Parameters.Add(new OracleParameter(refColumn, id)); command.Parameters.Add(new OracleParameter("key", pair.Key)); command.Parameters.Add(new OracleParameter("value", pair.Value)); command.ExecuteNonQuery(); command.Dispose(); } }
/// <summary> /// Loads the missing tiles. /// </summary> /// <param name="tile"></param> internal void LoadMissingTile(Tile tile) { if (!_loadedTiles.Contains(tile)) { // the tile was not loaded yet. TileStreamPosition meta; if (_graphTileMetas.TryGetValue(tile, out meta)) { // the meta data is available. CHEdgeDataDataSourceSerializer.SerializableGraphTile tileData = _routingDataSourceSerializer.DeserializeTile(_stream, meta.Offset, meta.Length, _compressed); double top = tile.TopLeft.Latitude; double left = tile.TopLeft.Longitude; for (int vertexIdx = 0; vertexIdx < tileData.Ids.Length; vertexIdx++) { // resize. this.Resize(tileData.Ids[vertexIdx] + 1); // create the location and calculate lat/lon. var vertexLocation = new Location(); vertexLocation.Latitude = (float)(top - (((double)tileData.Latitude[vertexIdx] / (double)ushort.MaxValue) * tile.Box.DeltaLat)); vertexLocation.Longitude = (float)((((double)tileData.Longitude[vertexIdx] / (double)ushort.MaxValue) * tile.Box.DeltaLon) + left); _coordinates[(int)tileData.Ids[vertexIdx]] = vertexLocation; // convert the arcs. if (tileData.Arcs[vertexIdx] != null && tileData.Arcs[vertexIdx].DestinationId != null) { var arcs = new KeyValuePair <uint, CHEdgeData> [tileData.Arcs[vertexIdx].DestinationId.Length]; for (int idx = 0; idx < tileData.Arcs[vertexIdx].DestinationId.Length; idx++) { // create the tags collection. TagsCollection tagsCollection = new SimpleTagsCollection(); if (tileData.Arcs[vertexIdx].Tags[idx].Keys != null) { for (int tagsIdx = 0; tagsIdx < tileData.Arcs[vertexIdx].Tags[idx].Keys.Length; tagsIdx++) { string key = tileData.StringTable[tileData.Arcs[vertexIdx].Tags[idx].Keys[tagsIdx]]; string value = tileData.StringTable[tileData.Arcs[vertexIdx].Tags[idx].Values[tagsIdx]]; tagsCollection.Add(key, value); } } uint tags = _tagsIndex.Add(tagsCollection); // create the liveedge. var edge = new CHEdgeData(); edge.SetDirection(tileData.Arcs[vertexIdx].Forward[idx], tileData.Arcs[vertexIdx].Backward[idx], true); edge.Weight = tileData.Arcs[vertexIdx].Weight[idx]; edge.Tags = tags; // convert the arc. arcs[idx] = new KeyValuePair <uint, CHEdgeData>( tileData.Arcs[vertexIdx].DestinationId[idx], edge); // store the target tile. var targetTile = new Tile(tileData.Arcs[vertexIdx].TileX[idx], tileData.Arcs[vertexIdx].TileY[idx], _zoom); if (!targetTile.Equals(tile) && !_loadedTiles.Contains(targetTile)) { _tilesPerVertex[tileData.Arcs[vertexIdx].DestinationId[idx]] = targetTile; } } _vertices[(int)tileData.Ids[vertexIdx]] = new Vertex() { Arcs = arcs }; } _vertexIndex.Add(new GeoCoordinate(vertexLocation.Latitude, vertexLocation.Longitude), tileData.Ids[vertexIdx]); } } _loadedTiles.Add(tile); // tile is loaded. } }
public void TestRandomPartialTagSerializaton() { SimpleTagsCollectionIndex tagsIndex = new SimpleTagsCollectionIndex(); SimpleTagsCollection tagsCollection = new SimpleTagsCollection(); for (int i = 0; i < 100; i++) { int tagCollectionSize = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(10) + 1; for (int idx = 0; idx < tagCollectionSize; idx++) { int tagValue = OsmSharp.Math.Random.StaticRandomGenerator.Get().Generate(10); tagsCollection.Add( string.Format("key_{0}", tagValue), string.Format("value_{0}", tagValue)); } uint tagsId = tagsIndex.Add(tagsCollection); } uint from = 40; uint to = 50; ITagsCollectionIndexReadonly tagsIndexReadonly = this.SerializeDeserialize(tagsIndex, from, to); Assert.AreEqual(System.Math.Min(to, tagsIndex.Max), tagsIndexReadonly.Max); for (uint idx = 0; idx < tagsIndex.Max; idx++) { if (idx >= from && idx < to) { this.CompareTagsCollections(tagsIndex.Get(idx), tagsIndexReadonly.Get(idx)); } else { Assert.IsNull(tagsIndexReadonly.Get(idx)); } } from = 0; to = 100; tagsIndexReadonly = this.SerializeDeserialize(tagsIndex, from, to); Assert.AreEqual(System.Math.Min(to, tagsIndex.Max), tagsIndexReadonly.Max); for (uint idx = 0; idx < tagsIndex.Max; idx++) { if (idx >= from && idx < to) { this.CompareTagsCollections(tagsIndex.Get(idx), tagsIndexReadonly.Get(idx)); } else { Assert.IsNull(tagsIndexReadonly.Get(idx)); } } from = 10; to = 1000; tagsIndexReadonly = this.SerializeDeserialize(tagsIndex, from, to); Assert.AreEqual(System.Math.Min(to, tagsIndex.Max), tagsIndexReadonly.Max); for (uint idx = 0; idx < tagsIndex.Max; idx++) { if (idx >= from && idx < to) { this.CompareTagsCollections(tagsIndex.Get(idx), tagsIndexReadonly.Get(idx)); } else { Assert.IsNull(tagsIndexReadonly.Get(idx)); } } }