/// <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));
        }
        /// <summary>
        /// Tests a simple way read/write operation.
        /// </summary>
        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));
        }
        /// <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));
        }
        /// <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));
        }
Exemplo n.º 5
0
        /// <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>();
        }
Exemplo n.º 6
0
        /// <summary>
        /// Creates a new osm simple complete stream.
        /// </summary>
        /// <param name="source"></param>
        /// <param name="cache"></param>
        public OsmStreamFilterBase(OsmStreamSource source, OsmDataCache cache)
        {
            _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>();
        }
Exemplo n.º 7
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);
 }
        /// <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>();
        }
        /// <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>();
        }
Exemplo n.º 10
0
        private SQLiteDataSource(string connection_string, OsmDataCache geo_cache,
            ConcurrentTagsCollectionCache tags_cache)
        {
            _connection_string = connection_string;
            _connection = EnsureConnection();

            _tags_cache = tags_cache;
            _geo_cache = geo_cache;
            _id = Guid.NewGuid();
        }
Exemplo n.º 11
0
        /// <summary>
        /// Creates a new SQLite data source
        /// </summary>
        /// <param name="connection">The SQLite connection</param>
        /// <param name="create_schema">Do the db schema and tables need to be created?</param>
        public SQLiteDataSource(SQLiteConnection connection, bool create_schema = false)
        {
            _connection = connection;
            _create_and_detect_schema = create_schema;
            _connection_string = connection.ConnectionString;
            // validate the connection
            _connection = EnsureConnection();

            _geo_cache = new ConcurrentOsmDataCacheMemory();
            _tags_cache = new ConcurrentTagsCollectionCache();
            _id = Guid.NewGuid();
        }
Exemplo n.º 12
0
        /// <summary>
        /// Creates a new SQLite source
        /// </summary>
        /// <param name="in_memory">Is the DB in memory? (default is false)</param>
        /// <param name="path">The path to the DB, or its descriptor in memory (if any)</param>
        /// <param name="password">The DB password (if any)</param>
        /// <param name="create_schema">Do the db tables need to be created?</param>
        public SQLiteDataSource(bool in_memory = false, string path = null,
                                string password = null, bool create_schema = false)
        {
            // create the connection string
            _connection_string = SQLiteSchemaTools.BuildConnectionString(in_memory, path, password);
            _create_and_detect_schema = create_schema;
            _connection = EnsureConnection();

            _geo_cache = new ConcurrentOsmDataCacheMemory();
            _tags_cache = new ConcurrentTagsCollectionCache();
            _id = Guid.NewGuid();
        }