예제 #1
0
        /// <summary>
        /// Reads the ways from the file.
        /// </summary>
        /// <returns>The ways.</returns>
        public IEnumerable <MapShape> ReadWays()
        {
            do
            {
                switch (reader.Name)
                {
                case "node":
                    var node = MapDefinition.ParseNode(reader);
                    this.nodes.Add(node.Index, node);
                    break;

                case "way":
                    var nextWay = ParseMapWay();
                    this.ways.Add(nextWay.Id, nextWay);
                    yield return(MapShape.Create(nextWay, nextWay.Tags));

                    break;

                case "relation":
                {
                    foreach (var relation in this.TryParseRelation())
                    {
                        yield return(relation);
                    }
                }
                break;
                }
            } while (reader.Read());

            yield break;
        }
예제 #2
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));
            }
        }