public void OSMRelationConstructorInitializesAllProperties() { int id = 1273; OSMRelation target = new OSMRelation(id); Assert.Equal(id, target.ID); Assert.NotNull(target.Members); }
public void OSMDatabaseNodesAcceptsAndReturnsRelations() { OSMDB target = new OSMDB(); OSMRelation relation = new OSMRelation(1454); target.Relations.Add(relation); Assert.Same(relation, target.Relations[relation.ID]); }
public void OSMXmlDataWriteRelationCanWriteRelationWithTags() { MemoryStream ms = new MemoryStream(); using (OSMXmlDataWriter target = new OSMXmlDataWriter(ms)) { OSMRelation relation = new OSMRelation(1232); relation.Members.Add(new OSMRelationMember(OSMRelationMemberType.node, 12, "test")); relation.Tags.Add(new OSMTag("name", "test")); target.WriteRelation(relation); } ms.Seek(0, 0); XElement osmRoot = XDocument.Load(new StreamReader(ms)).Root; XElement relationElement = osmRoot.Element("relation"); Assert.NotNull(relationElement); Assert.Equal(1232, int.Parse(relationElement.Attribute("id").Value, System.Globalization.NumberFormatInfo.InvariantInfo)); Assert.Equal("name", relationElement.Element("tag").Attribute("k").Value); }
/// <summary> /// Saves the read OSMRelation to the internal storage /// </summary> /// <param name="node">The OSMRelation read</param> public void ProcessRelation(OSMRelation relation) { _readRelations.Add(relation); }
private void ReadRelation() { string attId = _xmlReader.GetAttribute("id"); if (attId == null) throw new XmlException("Attribute 'id' is missing."); int relationId = int.Parse(attId, CultureInfo.InvariantCulture); OSMRelation relation = new OSMRelation(relationId); if (false == _xmlReader.IsEmptyElement) { _xmlReader.Read(); while (_xmlReader.NodeType != XmlNodeType.EndElement) { switch (_xmlReader.NodeType) { case XmlNodeType.Element: switch (_xmlReader.Name) { case "member": relation.Members.Add(ReadRelationMember()); continue; case "tag": relation.Tags.Add(ReadTag()); continue; default: _xmlReader.Skip(); continue; } default: _xmlReader.Skip(); break; } } } OnRelationRead(relation); _xmlReader.Skip(); }
/// <summary> /// Raises the RelationRead event /// </summary> /// <param name="node">The OSMRelation read from the database</param> protected void OnRelationRead(OSMRelation relation) { OSMRelationReadHandler temp = RelationRead; if (temp != null) { temp(relation); } }
/// <summary> /// Writes the specific OSMRelation to the output /// </summary> /// <param name="relation">The OSMRelation to be written.</param> public void WriteRelation(OSMRelation relation) { _xmlWriter.WriteStartElement("relation"); WriteOSMObjectAttributes(relation); foreach (var member in relation.Members) { _xmlWriter.WriteStartElement("member"); _xmlWriter.WriteAttributeString("type", member.Type.ToString()); _xmlWriter.WriteAttributeString("ref", member.Reference.ToString(System.Globalization.NumberFormatInfo.InvariantInfo)); _xmlWriter.WriteAttributeString("role", member.Role); _xmlWriter.WriteEndElement(); } WriteOSMObjectTags(relation); _xmlWriter.WriteEndElement(); }