コード例 #1
0
        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");
            }
        }
コード例 #2
0
        public void Add_ThrowsExceptionIfTagAlreadyPresent()
        {
            TagsCollection target = new TagsCollection();
            target.Add(_tagsDuplicitKeys[0]);

            Assert.Throws<ArgumentException>(delegate { target.Add(_tagsDuplicitKeys[1]); });
        }
コード例 #3
0
        public void When_AddNewTag_Then_NewTagAdded()
        {
            tagsCollection.Add(TagName, TagValue);

            Assert.IsTrue(tagsCollection.ContainsKey(TagName));
            Assert.AreEqual(tagsCollection[TagName], TagValue);
        }
コード例 #4
0
        public void Add_ThrowsExceptionIfTagAlreadyPresent()
        {
            TagsCollection target = new TagsCollection();

            target.Add(_tagsDuplicitKeys[0]);

            Assert.Throws <ArgumentException>(delegate { target.Add(_tagsDuplicitKeys[1]); });
        }
コード例 #5
0
        /// <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);
        }
コード例 #6
0
        /// <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);
        }
コード例 #7
0
        public void Add_AddsTag()
        {
            TagsCollection target = new TagsCollection();
            target.Add(_tags[0]);

            Assert.Contains(_tags[0], target);
        }
コード例 #8
0
        /// <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);
        }
コード例 #9
0
        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()));
        }
コード例 #11
0
        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());
        }
コード例 #12
0
        /// <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);
        }
コード例 #13
0
        public void Add_AddsTag()
        {
            TagsCollection target = new TagsCollection();

            target.Add(_tags[0]);

            Assert.Contains(_tags[0], target);
        }
コード例 #14
0
        /// <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);
        }
コード例 #15
0
        public void MapCSSEvalTagTest()
        {
            string             function = "tag('width')";
            TagsCollectionBase tags     = new TagsCollection();

            tags.Add("width", "2");

            Assert.AreEqual(2, EvalInterpreter.Instance.InterpretDouble(function, tags));
        }
コード例 #16
0
        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");
            }
        }
コード例 #17
0
        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");
        }
コード例 #18
0
        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");
        }
コード例 #19
0
 internal static void AddRange(this TagsCollection tc, IEnumerable <string>?tagsToAdd)
 {
     if (tagsToAdd is null)
     {
         return;
     }
     foreach (string tag in tagsToAdd)
     {
         tc.Add(tag);
     }
 }
コード例 #20
0
        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"));
        }
コード例 #21
0
        /// <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);
        }
コード例 #22
0
        /// <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));
        }
コード例 #23
0
        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);
        }
コード例 #24
0
ファイル: Tags.cs プロジェクト: GrumpyTrev/DNLACore
        /// <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;
        }
コード例 #25
0
ファイル: Route.cs プロジェクト: teleavtomatika/routing
        /// <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);
        }
コード例 #26
0
        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);
        }
コード例 #27
0
        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);
            }
        }
コード例 #28
0
        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);
        }
コード例 #29
0
        /// <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();
        }
コード例 #30
0
        /// <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);
        }
コード例 #31
0
ファイル: Scene2DTests.cs プロジェクト: wthomson2001/OsmSharp
        /// <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);
        }
コード例 #32
0
ファイル: ArcAggregator.cs プロジェクト: yousoftvn/OsmSharp
        /// <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);
        }
コード例 #33
0
        /// <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;
        }
コード例 #34
0
        /// <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);
        }
コード例 #35
0
 /// <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;
 }