示例#1
0
        /// <summary>
        /// Tests a simple relation read/write operation.
        /// </summary>
        /// <param name="cache"></param>
        public void DoOsmDataCacheTestRelation(OsmDataCache cache)
        {
            Relation relation = Relation.Create(1, new TagsCollection(
                                                    Tag.Create("relation", "yes")), RelationMember.Create(1, "something", OsmGeoType.Node));

            // test invalid stuff.
            Assert.Throws <ArgumentNullException>(() => cache.AddRelation(null));
            Assert.Throws <Exception>(() => cache.AddRelation(new Relation()));
            Assert.IsNull(cache.GetRelation(relation.Id.Value));

            cache.AddRelation(relation);

            Assert.IsTrue(cache.ContainsRelation(relation.Id.Value));
            Relation readRelation = cache.GetRelation(relation.Id.Value);

            Assert.IsNotNull(readRelation);
            Assert.AreEqual(1, readRelation.Id.Value);
            Assert.IsNotNull(relation.Tags);
            Assert.AreEqual(1, relation.Tags.Count);
            Assert.AreEqual("yes", relation.Tags["relation"]);

            Assert.IsTrue(cache.TryGetRelation(relation.Id.Value, out readRelation));
            Assert.IsNotNull(readRelation);
            Assert.AreEqual(1, readRelation.Id.Value);
            Assert.IsNotNull(relation.Tags);
            Assert.AreEqual(1, relation.Tags.Count);
            Assert.AreEqual("yes", relation.Tags["relation"]);

            Assert.IsTrue(cache.RemoveRelation(relation.Id.Value));
            Assert.IsFalse(cache.ContainsRelation(relation.Id.Value));
            Assert.IsFalse(cache.RemoveRelation(relation.Id.Value));
        }
示例#2
0
        /// <summary>
        /// Tests a simple way read/write operation.
        /// </summary>
        /// <param name="cache"></param>
        public void DoOsmDataCacheTestWay(OsmDataCache cache)
        {
            Way way = Way.Create(1, new TagsCollection(
                                     Tag.Create("way", "yes")), 1, 2);

            // test invalid stuff.
            Assert.Throws <ArgumentNullException>(() => cache.AddWay(null));
            Assert.Throws <Exception>(() => cache.AddWay(new Way()));
            Assert.IsNull(cache.GetWay(way.Id.Value));

            cache.AddWay(way);

            Assert.IsTrue(cache.ContainsWay(way.Id.Value));
            Way readWay = cache.GetWay(way.Id.Value);

            Assert.IsNotNull(readWay);
            Assert.AreEqual(1, readWay.Id.Value);
            Assert.IsNotNull(way.Tags);
            Assert.AreEqual(1, way.Tags.Count);
            Assert.AreEqual("yes", way.Tags["way"]);

            Assert.IsTrue(cache.TryGetWay(way.Id.Value, out readWay));
            Assert.IsNotNull(readWay);
            Assert.AreEqual(1, readWay.Id.Value);
            Assert.IsNotNull(way.Tags);
            Assert.AreEqual(1, way.Tags.Count);
            Assert.AreEqual("yes", way.Tags["way"]);

            Assert.IsTrue(cache.RemoveWay(way.Id.Value));
            Assert.IsFalse(cache.ContainsWay(way.Id.Value));
            Assert.IsFalse(cache.RemoveWay(way.Id.Value));
        }
示例#3
0
 public OsmStreamFilterBase(OsmStreamSource source, OsmDataCache cache)
 {
     this._dataCache                = cache;
     this._nodesToInclude           = new HashSet <long>();
     this._nodesUsedTwiceOrMore     = new Dictionary <long, int>();
     this._waysToInclude            = new HashSet <long>();
     this._waysUsedTwiceOrMore      = new Dictionary <long, int>();
     this._relationsToInclude       = new HashSet <long>();
     this._relationsUsedTwiceOrMore = new Dictionary <long, int>();
 }
示例#4
0
 public OsmSimpleCompleteStreamSource(OsmStreamSource source)
 {
     this._dataCache                = (OsmDataCache) new OsmDataCacheMemory();
     this._simpleSource             = source;
     this._nodesToInclude           = new HashSet <long>();
     this._nodesUsedTwiceOrMore     = new Dictionary <long, int>();
     this._waysToInclude            = new HashSet <long>();
     this._waysUsedTwiceOrMore      = new Dictionary <long, int>();
     this._relationsToInclude       = new HashSet <long>();
     this._relationsUsedTwiceOrMore = new Dictionary <long, int>();
 }
        /// <summary>
        /// Creates a new osm simple complete stream.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="cache"></param>
        public OsmSimpleCompleteStreamSource(OsmStreamSource source, OsmDataCache cache)
        {
            _dataCache    = cache;
            _simpleSource = source;

            _nodesToInclude           = new HashSet <long>();
            _nodesUsedTwiceOrMore     = new Dictionary <long, int>();
            _waysToInclude            = new HashSet <long>();
            _waysUsedTwiceOrMore      = new Dictionary <long, int>();
            _relationsToInclude       = new HashSet <long>();
            _relationsUsedTwiceOrMore = new Dictionary <long, int>();
        }
        /// <summary>
        /// Creates a new osm simple complete stream.
        /// </summary>
        /// <param name="cache"></param>
        public OsmStreamFilterBase(OsmDataCache cache)
        {
            // create an in-memory cache by default.
            _dataCache = cache;

            _nodesToInclude           = new HashSet <long>();
            _nodesUsedTwiceOrMore     = new Dictionary <long, int>();
            _waysToInclude            = new HashSet <long>();
            _waysUsedTwiceOrMore      = new Dictionary <long, int>();
            _relationsToInclude       = new HashSet <long>();
            _relationsUsedTwiceOrMore = new Dictionary <long, int>();
        }
        /// <summary>
        /// Creates a new osm simple complete stream.
        /// </summary>
        /// <param name="source"></param>
        public OsmSimpleCompleteStreamSource(OsmStreamSource source)
        {
            // create an in-memory cache by default.
            _dataCache    = new OsmDataCacheMemory();
            _simpleSource = source;

            _nodesToInclude           = new HashSet <long>();
            _nodesUsedTwiceOrMore     = new Dictionary <long, int>();
            _waysToInclude            = new HashSet <long>();
            _waysUsedTwiceOrMore      = new Dictionary <long, int>();
            _relationsToInclude       = new HashSet <long>();
            _relationsUsedTwiceOrMore = new Dictionary <long, int>();
        }
示例#8
0
        private bool IsChild(OsmGeo currentSimple)
        {
            switch (currentSimple.Type)
            {
            case OsmGeoType.Node:
                HashSet <long> nodesToInclude = this._nodesToInclude;
                long?          id1            = currentSimple.Id;
                long           num1           = id1.Value;
                if (nodesToInclude.Contains(num1))
                {
                    return(true);
                }
                OsmDataCache dataCache1 = this._dataCache;
                id1 = currentSimple.Id;
                long id2 = id1.Value;
                return(dataCache1.ContainsNode(id2));

            case OsmGeoType.Way:
                HashSet <long> waysToInclude = this._waysToInclude;
                long?          id3           = currentSimple.Id;
                long           num2          = id3.Value;
                if (waysToInclude.Contains(num2))
                {
                    return(true);
                }
                OsmDataCache dataCache2 = this._dataCache;
                id3 = currentSimple.Id;
                long id4 = id3.Value;
                return(dataCache2.ContainsWay(id4));

            case OsmGeoType.Relation:
                HashSet <long> relationsToInclude = this._relationsToInclude;
                long?          id5  = currentSimple.Id;
                long           num3 = id5.Value;
                if (relationsToInclude.Contains(num3))
                {
                    return(true);
                }
                OsmDataCache dataCache3 = this._dataCache;
                id5 = currentSimple.Id;
                long id6 = id5.Value;
                return(dataCache3.ContainsRelation(id6));

            default:
                return(false);
            }
        }
示例#9
0
        /// <summary>
        /// Creates a new processor target.
        /// </summary>
        /// <param name="dynamicGraph">The graph that will be filled.</param>
        /// <param name="interpreter">The interpreter to generate the edge data.</param>
        /// <param name="edgeComparer"></param>
        /// <param name="tagsIndex"></param>
        /// <param name="idTransformations"></param>
        /// <param name="collectIntermediates"></param>
        protected DynamicGraphOsmStreamWriter(
            IDynamicGraphRouterDataSource <TEdgeData> dynamicGraph, IOsmRoutingInterpreter interpreter, IDynamicGraphEdgeComparer <TEdgeData> edgeComparer,
            ITagsCollectionIndex tagsIndex, HugeDictionary <long, uint> idTransformations, bool collectIntermediates)
        {
            _dynamicGraph = dynamicGraph;
            _interpreter  = interpreter;
            _edgeComparer = edgeComparer;

            _tagsIndex         = tagsIndex;
            _idTransformations = idTransformations;
            _preIndexMode      = true;
            _preIndex          = new OsmSharp.Collections.LongIndex.LongIndex.LongIndex();
            _relevantNodes     = new OsmSharp.Collections.LongIndex.LongIndex.LongIndex();

            _collectIntermediates = collectIntermediates;
            _dataCache            = new OsmDataCacheMemory();
        }
示例#10
0
        /// <summary>
        /// Creates a new processor target.
        /// </summary>
        /// <param name="dynamicGraph">The graph that will be filled.</param>
        /// <param name="interpreter">The interpreter to generate the edge data.</param>
        /// <param name="edgeComparer"></param>
        /// <param name="tagsIndex"></param>
        /// <param name="idTransformations"></param>
        /// <param name="box"></param>
        protected DynamicGraphOsmStreamWriter(
            IDynamicGraphRouterDataSource <TEdgeData> dynamicGraph, IOsmRoutingInterpreter interpreter, IDynamicGraphEdgeComparer <TEdgeData> edgeComparer,
            ITagsCollectionIndex tagsIndex, IDictionary <long, uint> idTransformations,
            GeoCoordinateBox box)
        {
            _dynamicGraph = dynamicGraph;
            _interpreter  = interpreter;
            _edgeComparer = edgeComparer;
            _box          = box;

            _tagsIndex         = tagsIndex;
            _idTransformations = idTransformations;
            _preIndexMode      = true;
            _preIndex          = new OsmSharp.Collections.HugeHashSet <long>();
            _usedTwiceOrMore   = new OsmSharp.Collections.HugeHashSet <long>();

            _dataCache = new OsmDataCacheMemory();
        }
        /// <summary>
        /// Creates a new processor target.
        /// </summary>
        /// <param name="graph">The graph that will be filled.</param>
        /// <param name="interpreter">The interpreter to generate the edge data.</param>
        /// <param name="tagsIndex"></param>
        /// <param name="idTransformations"></param>
        /// <param name="collectIntermediates"></param>
        /// <param name="coordinates"></param>
        protected GraphOsmStreamTargetBase(
            RouterDataSourceBase <TEdgeData> graph, IOsmRoutingInterpreter interpreter,
            ITagsIndex tagsIndex, HugeDictionary <long, uint> idTransformations, bool collectIntermediates, ICoordinateIndex coordinates)
        {
            _graph       = graph;
            _interpreter = interpreter;

            _tagsIndex         = tagsIndex;
            _idTransformations = idTransformations;
            _preIndexMode      = true;
            _preIndex          = new OsmSharp.Collections.LongIndex.LongIndex.LongIndex();
            _relevantNodes     = new OsmSharp.Collections.LongIndex.LongIndex.LongIndex();
            _restricedWays     = new HashSet <long>();
            _collapsedNodes    = new Dictionary <long, KeyValuePair <KeyValuePair <long, uint>, KeyValuePair <long, uint> > >();

            _collectIntermediates = collectIntermediates;
            _dataCache            = new OsmDataCacheMemory();
            _coordinates          = coordinates;
        }
示例#12
0
        /// <summary>
        /// Tests the clear functionality on the datacache.
        /// </summary>
        /// <param name="cache"></param>
        public void DoOsmDataCacheTestClear(OsmDataCache cache)
        {
            Node node = Node.Create(1, new TagsCollection(
                                        Tag.Create("node", "yes")), 1, 2);
            Way way = Way.Create(1, new TagsCollection(
                                     Tag.Create("way", "yes")), 1, 2);
            Relation relation = Relation.Create(1, new TagsCollection(
                                                    Tag.Create("relation", "yes")), RelationMember.Create(1, "something", OsmGeoType.Node));

            cache.AddNode(node);
            cache.AddWay(way);
            cache.AddRelation(relation);

            Assert.IsTrue(cache.ContainsNode(node.Id.Value));
            Assert.IsTrue(cache.ContainsWay(way.Id.Value));
            Assert.IsTrue(cache.ContainsRelation(relation.Id.Value));

            cache.Clear();

            Assert.IsFalse(cache.ContainsNode(node.Id.Value));
            Assert.IsFalse(cache.ContainsWay(way.Id.Value));
            Assert.IsFalse(cache.ContainsRelation(relation.Id.Value));
        }
示例#13
0
        /// <summary>
        /// Tests a simple node read/write operation.
        /// </summary>
        /// <param name="cache"></param>
        public void DoOsmDataCacheTestNode(OsmDataCache cache)
        {
            Node node = Node.Create(1, new TagsCollection(
                                        Tag.Create("node", "yes")), 1, 2);

            // test invalid stuff.
            Assert.Throws <ArgumentNullException>(() => cache.AddNode(null));
            Assert.Throws <Exception>(() => cache.AddNode(new Node()));
            Assert.IsNull(cache.GetNode(node.Id.Value));

            cache.AddNode(node);

            Assert.IsTrue(cache.ContainsNode(node.Id.Value));
            Node readNode = cache.GetNode(node.Id.Value);

            Assert.IsNotNull(readNode);
            Assert.AreEqual(1, readNode.Id.Value);
            Assert.AreEqual(1, readNode.Latitude.Value);
            Assert.AreEqual(2, readNode.Longitude.Value);
            Assert.IsNotNull(node.Tags);
            Assert.AreEqual(1, node.Tags.Count);
            Assert.AreEqual("yes", node.Tags["node"]);

            Assert.IsTrue(cache.TryGetNode(node.Id.Value, out readNode));
            Assert.IsNotNull(readNode);
            Assert.AreEqual(1, readNode.Id.Value);
            Assert.AreEqual(1, readNode.Latitude.Value);
            Assert.AreEqual(2, readNode.Longitude.Value);
            Assert.IsNotNull(node.Tags);
            Assert.AreEqual(1, node.Tags.Count);
            Assert.AreEqual("yes", node.Tags["node"]);

            Assert.IsTrue(cache.RemoveNode(node.Id.Value));
            Assert.IsFalse(cache.ContainsNode(node.Id.Value));
            Assert.IsFalse(cache.RemoveNode(node.Id.Value));
        }
示例#14
0
 /// <summary>
 /// Registers a simple source on this target with a given cache.
 /// </summary>
 /// <param name="source"></param>
 /// <param name="cache"></param>
 public void RegisterSource(OsmStreamSource source, OsmDataCache cache)
 {
     _source = new OsmSimpleCompleteStreamSource(source, cache);
 }