Example #1
0
        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));
            }
        }