/// <summary> /// Returns all relations for the given object. /// </summary> /// <param name="type"></param> /// <param name="id"></param> /// <returns></returns> public override IList <Relation> GetRelationsFor(OsmGeoType type, long id) { IList <Relation> relations = _source.GetRelationsFor(type, id); foreach (Relation relation in relations) { _relationsCache.Add(relation.Id.Value, relation); } return(relations); }
/// <summary> /// Tests writing data and getting relations using it's members. /// </summary> protected void TestGetRelationsForMember() { this.NotifyEmptyExpected(); // empty test database. // create the target and pull the data from the test-file into the sqlite database. OsmStreamTarget target = this.CreateDataStreamTarget(); target.Initialize(); PBFOsmStreamSource source = new PBFOsmStreamSource( Assembly.GetExecutingAssembly().GetManifestResourceStream("OsmSharp.Data.Test.Unittests.Data.Osm.test.osm.pbf")); IDataSourceReadOnly dataSource = this.CreateDataSource(); source.Initialize(); while (source.MoveNext()) { switch (source.Current().Type) { case OsmGeoType.Relation: Relation relation = (source.Current() as Relation); target.AddRelation(relation); target.Flush(); if (relation.Members != null) { foreach (var member in relation.Members) { OsmGeoType type = OsmGeoType.Node; switch (member.MemberType.Value) { case OsmGeoType.Node: type = OsmGeoType.Node; break; case OsmGeoType.Way: type = OsmGeoType.Way; break; case OsmGeoType.Relation: type = OsmGeoType.Relation; break; } IList <Relation> relations = dataSource.GetRelationsFor(type, member.MemberId.Value); Assert.IsNotNull(relations); Assert.IsTrue(relations.Count > 0); List <Relation> foundRelations = new List <Relation>(relations.Where <Relation>(x => x.Id == relation.Id)); Assert.AreEqual(1, foundRelations.Count); } } break; } } MemoryDataSource memorySource = MemoryDataSource.CreateFrom(source); foreach (Relation relation in memorySource.GetRelations()) { if (relation.Members != null) { foreach (var member in relation.Members) { OsmGeoType type = OsmGeoType.Node; switch (member.MemberType.Value) { case OsmGeoType.Node: type = OsmGeoType.Node; break; case OsmGeoType.Way: type = OsmGeoType.Way; break; case OsmGeoType.Relation: type = OsmGeoType.Relation; break; } IList <Relation> relations = dataSource.GetRelationsFor(type, member.MemberId.Value); Assert.IsNotNull(relations); Assert.IsTrue(relations.Count > 0); List <Relation> foundRelations = new List <Relation>(relations.Where <Relation>(x => x.Id == relation.Id)); Assert.AreEqual(1, foundRelations.Count); } } break; } }