public static void NormalizeAccess(this TagsCollection tags, TagsCollection profileTags, bool defaultAccess, params string[] accessTags) { bool?nullable1 = tags.InterpretAccessValue("access"); for (int index = 0; index < accessTags.Length; ++index) { bool?nullable2 = tags.InterpretAccessValue(accessTags[index]); if (nullable2.HasValue) { nullable1 = nullable2; } } if (!nullable1.HasValue || nullable1.Value == defaultAccess) { return; } if (nullable1.Value) { profileTags.Add(accessTags[accessTags.Length - 1], "yes"); } else { profileTags.Add(accessTags[accessTags.Length - 1], "no"); } }
public void Add_ThrowsExceptionIfTagAlreadyPresent() { TagsCollection target = new TagsCollection(); target.Add(_tagsDuplicitKeys[0]); Assert.Throws<ArgumentException>(delegate { target.Add(_tagsDuplicitKeys[1]); }); }
public void When_AddNewTag_Then_NewTagAdded() { tagsCollection.Add(TagName, TagValue); Assert.IsTrue(tagsCollection.ContainsKey(TagName)); Assert.AreEqual(tagsCollection[TagName], TagValue); }
public void Add_ThrowsExceptionIfTagAlreadyPresent() { TagsCollection target = new TagsCollection(); target.Add(_tagsDuplicitKeys[0]); Assert.Throws <ArgumentException>(delegate { target.Add(_tagsDuplicitKeys[1]); }); }
/// <summary> /// Builds a dummy route (as the crow flies) for segments of a route not found. /// </summary> /// <returns></returns> public virtual Route BuildDummyRoute(Vehicle vehicle, GeoCoordinate coordinate1, GeoCoordinate coordinate2) { var route = new Route(); route.Vehicle = vehicle.UniqueName; var segments = new RouteSegment[2]; segments[0] = new RouteSegment(); segments[0].Distance = 0; segments[0].Time = 0; segments[0].Type = RouteSegmentType.Start; segments[0].Vehicle = vehicle.UniqueName; segments[0].Latitude = (float)coordinate1.Latitude; segments[0].Longitude = (float)coordinate1.Longitude; var distance = coordinate1.DistanceReal(coordinate2).Value; var timeEstimage = distance / (vehicle.MaxSpeed().Value) * 3.6; var tags = new TagsCollection(); tags.Add("route", "not_found"); segments[1] = new RouteSegment(); segments[1].Distance = distance; segments[1].Time = timeEstimage; segments[1].Type = RouteSegmentType.Stop; segments[1].Vehicle = vehicle.UniqueName; segments[1].Latitude = (float)coordinate2.Latitude; segments[1].Longitude = (float)coordinate2.Longitude; segments[1].Tags = RouteTagsExtensions.ConvertFrom(tags); route.Segments = segments; return(route); }
/// <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. TagsCollectionBase previousTagsDic = new TagsCollection(); foreach (Tag pair in previous_arc.Tags) { previousTagsDic.Add(pair.Key, pair.Value); } var nextTagsDic = new TagsCollection(); 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 Add_AddsTag() { TagsCollection target = new TagsCollection(); target.Add(_tags[0]); Assert.Contains(_tags[0], target); }
/// <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> protected virtual 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. var previousTagsDic = new TagsCollection(); if (previous_arc.Tags != null) { foreach (Tag pair in previous_arc.Tags) { previousTagsDic.Add(pair.Key, pair.Value); } } var nextTagsDic = new TagsCollection(); if (next_arc.Tags != null) { 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. return(true); } return(false); }
public void TestRandomBlockTagSerializatonNonBeginPositionLimitedStreamRegression() { TagsTableCollectionIndex tagsIndex = new TagsTableCollectionIndex(); TagsCollection tagsCollection = new TagsCollection(); 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++) { ComparisonHelpers.CompareTags(tagsIndex.Get(idx), tagsIndexReadonly.Get(idx)); } }
/// <summary> /// Creates a router. /// </summary> /// <param name="interpreter"></param> /// <param name="manifestResourceName"></param> /// <returns></returns> protected override Router CreateRouter(IOsmRoutingInterpreter interpreter, string manifestResourceName) { var tagsIndex = new TagsTableCollectionIndex(); // do the data processing. var source = new XmlOsmStreamSource( Assembly.GetExecutingAssembly().GetManifestResourceStream(manifestResourceName)); var data = CHEdgeGraphOsmStreamTarget.Preprocess( source, new OsmRoutingInterpreter(), Vehicle.Car); // serialize. var memoryStream = new MemoryStream(); TagsCollectionBase metaData = new TagsCollection(); metaData.Add("some_key", "some_value"); var routingSerializer = new CHEdgeDataDataSourceSerializer(); routingSerializer.Serialize(memoryStream, data, metaData); memoryStream.Seek(0, SeekOrigin.Begin); var deserialized = routingSerializer.Deserialize(memoryStream); return(Router.CreateCHFrom(deserialized, new CHRouter(), new OsmRoutingInterpreter())); }
public static Stream TestSerialization(string name, string pbfFile, DynamicGraphRouterDataSource <CHEdgeData> data) { var testOutputFile = new FileInfo(@"test.routing"); testOutputFile.Delete(); var writeStream = testOutputFile.OpenWrite(); var performanceInfo = new PerformanceInfoConsumer("CHSerializer"); performanceInfo.Start(); performanceInfo.Report("Writing to {0}...", testOutputFile.Name); TagsCollectionBase metaData = new TagsCollection(); metaData.Add("some_key", "some_value"); var routingSerializer = new CHEdgeDataDataSourceSerializer(); routingSerializer.Serialize(writeStream, data, metaData); writeStream.Dispose(); OsmSharp.Logging.Log.TraceEvent("CHSerializer", OsmSharp.Logging.TraceEventType.Information, string.Format("Serialized file: {0}KB", testOutputFile.Length / 1024)); performanceInfo.Stop(); return(testOutputFile.OpenRead()); }
/// <summary> /// Does the actual testing. /// </summary> /// <param name="embeddedString"></param> private void DoRoutingSerializationV2CHRoutingV2ComparisonTest(string embeddedString) { // creates a new interpreter. var interpreter = new OsmRoutingInterpreter(); // do the data processing. var original = CHEdgeGraphOsmStreamTarget.Preprocess(new XmlOsmStreamSource( Assembly.GetExecutingAssembly().GetManifestResourceStream(embeddedString)), interpreter, Vehicle.Car); // create serializer. var routingSerializer = new OsmSharp.Routing.CH.Serialization.Sorted.CHEdgeDataDataSourceSerializer(); // serialize/deserialize. TagsCollectionBase metaData = new TagsCollection(); metaData.Add("some_key", "some_value"); byte[] byteArray; using (var stream = new MemoryStream()) { try { routingSerializer.Serialize(stream, original, metaData); byteArray = stream.ToArray(); } catch (Exception) { if (Debugger.IsAttached) { Debugger.Break(); } throw; } } IBasicRouterDataSource <CHEdgeData> deserializedVersion = routingSerializer.Deserialize(new MemoryStream(byteArray), out metaData); Assert.AreEqual(original.TagsIndex.Get(0), deserializedVersion.TagsIndex.Get(0)); Assert.IsTrue(deserializedVersion.SupportsProfile(Vehicle.Car)); Assert.IsFalse(deserializedVersion.SupportsProfile(Vehicle.Bicycle)); // create reference router. original = CHEdgeGraphOsmStreamTarget.Preprocess(new XmlOsmStreamSource( Assembly.GetExecutingAssembly() .GetManifestResourceStream(embeddedString)), interpreter, Vehicle.Car); var basicRouterOriginal = new CHRouter(); Router referenceRouter = Router.CreateCHFrom( original, basicRouterOriginal, interpreter); // try to do some routing on the deserialized version. var basicRouter = new CHRouter(); Router router = Router.CreateCHFrom( deserializedVersion, basicRouter, interpreter); this.TestCompareAll(original, referenceRouter, router); }
public void Add_AddsTag() { TagsCollection target = new TagsCollection(); target.Add(_tags[0]); Assert.Contains(_tags[0], target); }
/// <summary> /// Tests preprocessing data from a PBF file. /// </summary> /// <param name="name"></param> /// <param name="pbfFile"></param> public static RouterDataSource <CHEdgeData> TestSerialization(string name, string pbfFile) { var testFilePath = Path.Combine( Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "TestFiles", pbfFile); //var testFilePath = @"/Users/xivk/work/OSM/bin/africa-latest.osm.pbf"; var testFile = new FileInfo(testFilePath); var stream = testFile.OpenRead(); var source = new OsmSharp.Osm.Streams.Filters.OsmStreamFilterProgress(); source.RegisterSource(new PBFOsmStreamSource(stream)); var testOutputFile = new FileInfo(@"test.routing"); testOutputFile.Delete(); Stream writeStream = testOutputFile.Open(FileMode.CreateNew, FileAccess.ReadWrite); var performanceInfo = new PerformanceInfoConsumer("CHSerializerFlatFile.Serialize"); performanceInfo.Start(); performanceInfo.Report("Pulling from {0}...", testFile.Name); var data = CHEdgeGraphOsmStreamTarget.Preprocess( source, new TagsIndex(new MemoryMappedStream(new MemoryStream())), new OsmRoutingInterpreter(), Vehicle.Car); (data.Graph as DirectedGraph <CHEdgeData>).Compress(true); //var graphCopy = new DirectedGraph<CHEdgeData>(); //graphCopy.CopyFrom(data); //data = new RouterDataSource<CHEdgeData>(graphCopy, data.TagsIndex); var metaData = new TagsCollection(); metaData.Add("some_key", "some_value"); var routingSerializer = new CHEdgeSerializer(); routingSerializer.Serialize(writeStream, data, metaData); stream.Dispose(); writeStream.Dispose(); OsmSharp.Logging.Log.TraceEvent("CHSerializerFlatFile", OsmSharp.Logging.TraceEventType.Information, string.Format("Serialized file: {0}KB", testOutputFile.Length / 1024)); performanceInfo.Stop(); performanceInfo = new PerformanceInfoConsumer("CHSerializerFlatFile.Deserialize"); performanceInfo.Start(); performanceInfo.Report("Deserializing again..."); // open file again and read. writeStream = testOutputFile.OpenRead(); var deserializedGraph = routingSerializer.Deserialize(writeStream, false); performanceInfo.Stop(); return(data); }
public void MapCSSEvalTagTest() { string function = "tag('width')"; TagsCollectionBase tags = new TagsCollection(); tags.Add("width", "2"); Assert.AreEqual(2, EvalInterpreter.Instance.InterpretDouble(function, tags)); }
public static void NormalizeOneway(this TagsCollection tags, TagsCollection profileTags, TagsCollection metaTags) { string key; bool flag; if (!tags.TryGetValue("oneway", out key) || !OsmRoutingTagNormalizer.OnewayValues.TryGetValue(key, out flag)) { return; } if (flag) { profileTags.Add("oneway", "yes"); } else { profileTags.Add("oneway", "-1"); } }
public static void NormalizeJunction(this TagsCollection tags, TagsCollection profileTags, TagsCollection metaTags) { string str; if (!tags.TryGetValue("junction", out str) || !(str == "roundabout")) { return; } profileTags.Add("junction", "roundabout"); }
public static void NormalizeOnewayBicycle(this TagsCollection tags, TagsCollection profileTags, TagsCollection metaTags) { string str; if (!tags.TryGetValue("oneway:bicycle", out str) || !(str == "no")) { return; } profileTags.Add("oneway:bicycle", "no"); }
internal static void AddRange(this TagsCollection tc, IEnumerable <string>?tagsToAdd) { if (tagsToAdd is null) { return; } foreach (string tag in tagsToAdd) { tc.Add(tag); } }
public void TestBooleanParsing() { // test IsTrue. TagsCollectionBase tags = new TagsCollection(); tags.Add("area", "yes"); Assert.IsTrue(tags.IsTrue("area")); tags = new TagsCollection(); tags.Add("area", "1"); Assert.IsTrue(tags.IsTrue("area")); tags = new TagsCollection(); tags.Add("area", "true"); Assert.IsTrue(tags.IsTrue("area")); tags = new TagsCollection(); tags.Add("area", "false"); Assert.IsFalse(tags.IsTrue("area")); tags = new TagsCollection(); tags.Add("area", "0"); Assert.IsFalse(tags.IsTrue("area")); tags = new TagsCollection(); tags.Add("area", "no"); Assert.IsFalse(tags.IsTrue("area")); // test IsFalse. tags = new TagsCollection(); tags.Add("area", "yes"); Assert.IsFalse(tags.IsFalse("area")); tags = new TagsCollection(); tags.Add("area", "1"); Assert.IsFalse(tags.IsFalse("area")); tags = new TagsCollection(); tags.Add("area", "true"); Assert.IsFalse(tags.IsFalse("area")); tags = new TagsCollection(); tags.Add("area", "false"); Assert.IsTrue(tags.IsFalse("area")); tags = new TagsCollection(); tags.Add("area", "0"); Assert.IsTrue(tags.IsFalse("area")); tags = new TagsCollection(); 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. TagsCollection tagsCollection = new TagsCollection(); 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> /// Deserializes a tags index from the given stream. /// </summary> /// <param name="stream"></param> /// <returns></returns> public static ITagsCollectionIndexReadonly Deserialize(Stream stream) { var tagsIndexList = new Dictionary <uint, TagsCollection>(); var intBytes = new byte[4]; stream.Read(intBytes, 0, 4); var startOfTags = BitConverter.ToInt32(intBytes, 0); stream.Read(intBytes, 0, 4); var endOfFile = BitConverter.ToInt32(intBytes, 0); var typeModel = TagIndexSerializer.CreateTypeModel(); var stringTableBytes = new byte[startOfTags - 8]; stream.Read(stringTableBytes, 0, stringTableBytes.Length); var memoryStream = new MemoryStream(stringTableBytes); var strings = typeModel.Deserialize(memoryStream, null, typeof(List <string>)) as List <string>; memoryStream.Dispose(); var tagsIndexBytes = new byte[endOfFile - startOfTags]; stream.Read(tagsIndexBytes, 0, tagsIndexBytes.Length); memoryStream = new MemoryStream(tagsIndexBytes); var tagsIndexTableList = typeModel.Deserialize(memoryStream, null, typeof(List <KeyValuePair <uint, List <KeyValuePair <uint, uint> > > >)) as List <KeyValuePair <uint, List <KeyValuePair <uint, uint> > > >; memoryStream.Dispose(); for (int idx = 0; idx < tagsIndexTableList.Count; idx++) { var serializedTagsCollection = tagsIndexTableList[idx]; TagsCollection tagsCollection = null; if (serializedTagsCollection.Value != null) { tagsCollection = new TagsCollection(serializedTagsCollection.Value.Count); foreach (var pair in serializedTagsCollection.Value) { tagsCollection.Add( new Tag(strings[(int)pair.Key], strings[(int)pair.Value])); } } else { tagsCollection = new TagsCollection(); } tagsIndexList.Add(serializedTagsCollection.Key, tagsCollection); } return(new TagsIndexReadonly(tagsIndexList)); }
public static TagsCollectionBase ConvertToTagsCollection(this RouteTags[] tags) { TagsCollection tagsCollection = new TagsCollection(); if (tags != null) { foreach (RouteTags tag in tags) { tagsCollection.Add(new Tag(tag.Key, tag.Value)); } } return((TagsCollectionBase)tagsCollection); }
/// <summary> /// Add a new tag to the storage and the local collections /// </summary> /// <param name="albumToAdd"></param> public static async void AddTagAsync(Tag tagToAdd) { TagsCollection.Add(tagToAdd); if (tagToAdd.PersistTag == true) { // We need to wait for this in case the caller want to use the Tag Id await DbAccess.InsertAsync(tagToAdd); } NameLookup[tagToAdd.Name] = tagToAdd; ShortNameLookup[tagToAdd.ShortName] = tagToAdd; }
/// <summary> /// Converts a RouteTags array to a list of KeyValuePairs. /// </summary> /// <param name="tags"></param> /// <returns></returns> public static TagsCollectionBase ConvertToTagsCollection(this RouteTags[] tags) { var tagsList = new TagsCollection(); if (tags != null) { foreach (var pair in tags) { tagsList.Add(new Tag(pair.Key, pair.Value)); } } return(tagsList); }
private static TagsCollectionBase ConvertToTags(Osm.Xml.v0_6.tag[] tag) { TagsCollectionBase tags = null; if (tag != null && tag.Length > 0) { tags = new TagsCollection(); foreach (Osm.Xml.v0_6.tag t in tag) { tags.Add(t.k, t.v); } } return(tags); }
public static void NormalizeMaxspeed(this TagsCollection tags, TagsCollection profileTags, TagsCollection metaTags) { string s; if (!tags.TryGetValue("maxspeed", out s)) { return; } int result; if (int.TryParse(s, out result) && result > 0 && result <= 200) { profileTags.Add("maxspeed", s); } else { if (!s.EndsWith("mph") || !int.TryParse(s.Substring(0, s.Length - 4), out result) || (result <= 0 || result > 150)) { return; } profileTags.Add("maxspeed", s); } }
public static TagsCollection Parse(List <string> keys, List <Tile.Value> values, List <uint> tags) { var result = new TagsCollection(); var odds = tags.GetOdds().ToList(); var evens = tags.GetEvens().ToList(); for (var i = 0; i < evens.Count; i++) { var key = keys[(int)evens[i]]; var val = values[(int)odds[i]]; var valObject = GetAttr(val); result.Add(key, new JValue(valObject)); } return(result); }
/// <summary> /// Tests preprocessing data from a PBF file. /// </summary> /// <param name="name"></param> /// <param name="pbfFile"></param> public static void TestSerialization(string name, string pbfFile) { var testFile = new FileInfo(string.Format(@".\TestFiles\{0}", pbfFile)); var stream = testFile.OpenRead(); var source = new PBFOsmStreamSource(stream); var testOutputFile = new FileInfo(@"test.routing"); testOutputFile.Delete(); Stream writeStream = testOutputFile.OpenWrite(); var tagsIndex = new TagsTableCollectionIndex(); var interpreter = new OsmRoutingInterpreter(); var graph = new DynamicGraphRouterDataSource <CHEdgeData>(tagsIndex); var performanceInfo = new PerformanceInfoConsumer("CHSerializerFlatFile.Serialize"); performanceInfo.Start(); performanceInfo.Report("Pulling from {0}...", testFile.Name); var data = CHEdgeGraphOsmStreamTarget.Preprocess( source, new OsmRoutingInterpreter(), Vehicle.Car); var metaData = new TagsCollection(); metaData.Add("some_key", "some_value"); var routingSerializer = new CHEdgeFlatfileSerializer(); routingSerializer.Serialize(writeStream, data, metaData); stream.Dispose(); writeStream.Dispose(); OsmSharp.Logging.Log.TraceEvent("CHSerializerFlatFile", OsmSharp.Logging.TraceEventType.Information, string.Format("Serialized file: {0}KB", testOutputFile.Length / 1024)); performanceInfo.Stop(); performanceInfo = new PerformanceInfoConsumer("CHSerializerFlatFile.Deserialize"); performanceInfo.Start(); performanceInfo.Report("Deserializing again..."); // open file again and read. writeStream = testOutputFile.OpenRead(); var deserializedGraph = routingSerializer.Deserialize(writeStream); performanceInfo.Stop(); }
/// <summary> /// Returns the tags with the given id. /// </summary> /// <param name="tagsId"></param> /// <returns></returns> public TagsCollectionBase Get(uint tagsId) { OsmTags osmTags = _tagsCollectionTable.Get(tagsId); if (osmTags != null) { TagsCollection collection = new TagsCollection(); for (int idx = 0; idx < osmTags.Tags.Length; idx++) { collection.Add( _tagsTable.Get(osmTags.Tags[idx])); } return(collection); } return(null); }
/// <summary> /// Tests serializing a stream. /// </summary> /// <param name="name"></param> /// <param name="stream"></param> /// <param name="scene"></param> /// <param name="compress"></param> public static void TestSerialize(string name, Stream stream, Scene2D scene, bool compress) { PerformanceInfoConsumer performanceInfo = new PerformanceInfoConsumer(string.Format("{0}.Serialize", name)); performanceInfo.Start(); performanceInfo.Report("Serializing stream..."); TagsCollectionBase metaTags = new TagsCollection(); metaTags.Add("generated_by", "performance_test"); scene.Serialize(stream, compress, metaTags); performanceInfo.Stop(); Console.Write("", scene.BackColor); }
/// <summary> /// Returns true if the point between the two arcs represents a significant step in the route. /// </summary> /// <param name="previousArc"></param> /// <param name="nextArc"></param> /// <returns></returns> protected virtual bool IsSignificant(AggregatedArc previousArc, AggregatedArc nextArc) { if (previousArc.Next.Points != null && previousArc.Next.Points.Count > 0) { // the point has at least one important point. return(true); } if (previousArc.Next.ArcsNotTaken != null && previousArc.Next.ArcsNotTaken.Count > 0) { // the point has at least one arc not taken. return(true); } // a vehicle change is also always significant. if (previousArc.Vehicle != nextArc.Vehicle) { // there is a vehicle change. return(true); } // create tag interpreters for arcs to try and work out if the arcs are different for the given vehicle. var previousTagsDic = new TagsCollection(); if (previousArc.Tags != null) { foreach (var pair in previousArc.Tags) { previousTagsDic.Add(pair.Key, pair.Value); } } var nextTagsDic = new TagsCollection(); if (nextArc.Tags != null) { foreach (var pair in nextArc.Tags) { nextTagsDic.Add(pair.Key, pair.Value); } } if (!string.IsNullOrWhiteSpace(previousArc.Vehicle)) { // there is a vehicle set on the previous arc. var vehicle = Vehicle.GetByUniqueName(previousArc.Vehicle); if (!vehicle.IsEqualFor(previousTagsDic, nextTagsDic)) { // the previous and the next edge do not represent a change for the given vehicle. return(true); } } return(false); }
/// <summary> /// Deserializes a tags collection from a byte array. /// </summary> /// <param name="tagsBytes"></param> /// <returns></returns> public TagsCollectionBase Deserialize(byte[] tagsBytes) { RuntimeTypeModel typeModel = TypeModel.Create(); typeModel.Add(typeof(List<KeyValuePair<string, string>>), true); List<KeyValuePair<string, string>> tagsList = null; using (MemoryStream stream = new MemoryStream(tagsBytes)) { tagsList = typeModel.Deserialize(stream, null, typeof(List<KeyValuePair<string, string>>)) as List<KeyValuePair<string, string>>; } TagsCollection tagsCollection = new TagsCollection(); foreach(KeyValuePair<string, string> tag in tagsList) { tagsCollection.Add(tag.Key, tag.Value); } return tagsCollection; }
/// <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, TagsCollection> tagsIndexList = new Dictionary<uint, TagsCollection>(); for(int idx = 0; idx < tagsIndexTableList.Count; idx++) { KeyValuePair<uint, List<KeyValuePair<uint, uint>>> serializedTagsCollection = tagsIndexTableList[idx]; TagsCollection tagsCollection = new TagsCollection(); 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> /// Returns the tags with the given id. /// </summary> /// <param name="tagsId"></param> /// <returns></returns> public TagsCollectionBase Get(uint tagsId) { OsmTags osmTags = _tagsCollectionTable.Get(tagsId); if (osmTags != null) { TagsCollection collection = new TagsCollection(); for (int idx = 0; idx < osmTags.Tags.Length; idx++) { collection.Add( _tagsTable.Get(osmTags.Tags[idx])); } return collection; } return null; }