/// <summary> /// Parse a map way. /// </summary> /// <param name="reader">The reader.</param> /// <param name="map">The map.</param> /// <returns>The map way.</returns> private MapWay ParseMapWay() { if (false == string.Equals("way", this.reader.Name, StringComparison.OrdinalIgnoreCase)) { throw new ArgumentException($"Excpected a 'way' but got {this.reader.Name}"); } long id = 0; List <MapNode> nodes = new List <MapNode>(); List <KeyValuePair <string, string> > tags = new List <KeyValuePair <string, string> >(); while (reader.MoveToNextAttribute()) { switch (this.reader.Name) { case "id": id = long.Parse(reader.Value); break; } } while (this.reader.Read()) { switch (this.reader.Name) { case "way": goto loopexit; case "nd": { var node = this.ParseNodeRef(); nodes.Add(node); } break; case "tag": { var tag = MapDefinition.ParseTag(reader); tags.Add(tag); } break; default: break; } } loopexit: return(new MapWay(id, nodes, tags)); }
private IEnumerable <MapShape> TryParseRelation() { if (false == string.Equals("relation", this.reader.Name, StringComparison.OrdinalIgnoreCase)) { throw new ArgumentException($"Excpected a 'relation' but got {this.reader.Name}"); } long id = 0; while (reader.MoveToNextAttribute()) { switch (this.reader.Name) { case "id": id = long.Parse(reader.Value); break; } } List <MapWay> outer = new List <MapWay>(); List <MapWay> inner = new List <MapWay>(); List <KeyValuePair <string, string> > tags = new List <KeyValuePair <string, string> >(); while (this.reader.Read()) { switch (this.reader.Name) { case "relation": goto loopexit; case "member": { if (this.TryParseMember(out string role, out var mapWay)) { if (string.Equals("outer", role, StringComparison.OrdinalIgnoreCase)) { outer.Add(mapWay); } else if (string.Equals("inner", role, StringComparison.OrdinalIgnoreCase)) { inner.Add(mapWay); } } } break; case "tag": { var tag = MapDefinition.ParseTag(reader); tags.Add(tag); } break; default: break; } } loopexit: if (false == outer.Any()) { yield break; } var outerFlat = MapDefinition.FlattenMapways(outer).ToList(); foreach (var outerWay in outerFlat) { yield return(MapShape.Create(outerWay, tags)); } }