예제 #1
0
        internal static MapShape Create(MapWay outer, IEnumerable <MapWay> inners, IEnumerable <KeyValuePair <string, string> > tags)
        {
            var len        = outer.Nodes.Count();
            var outerEdge  = new PrimitiveLine(outer.Nodes.Take(len - 1).Select(n => new PrimitivePoint(n.Coordinate)).ToList());
            var innerEdges = inners.Select(inner => new PrimitivePolygon(new PrimitiveLine(inner.Nodes.Take(len - 1).Select(n => new PrimitivePoint(n.Coordinate)).ToList())));

            var primitive = new PrimitivePolygon(outerEdge, innerEdges);

            return(new MapShape(primitive, tags));
        }
예제 #2
0
 internal static MapShape Create(MapWay way, IEnumerable <KeyValuePair <string, string> > tags)
 {
     if (way.IsClosed)
     {
         var len       = way.Nodes.Count();
         var outerEdge = new PrimitiveLine(way.Nodes.Take(len - 1).Select(n => new PrimitivePoint(n.Coordinate)).ToList());
         var primitive = new PrimitivePolygon(outerEdge, Enumerable.Empty <PrimitivePolygon>());
         return(new MapShape(primitive, tags));
     }
     else
     {
         var primitive = new PrimitiveLine(way.Nodes.Select(n => new PrimitivePoint(n.Coordinate)).ToList());
         return(new MapShape(primitive, tags));
     }
 }
예제 #3
0
        /// <summary>
        /// Parses a member node from the map.
        /// </summary>
        /// <returns>The member node.</returns>
        private bool TryParseMember(out string role, out MapWay mapWay)
        {
            if (false == string.Equals("member", this.reader.Name))
            {
                throw new ArgumentException($"This {reader.Name} is not a member attribute.");
            }

            long   refId   = 0;
            string refType = null;

            role = null;

            while (this.reader.MoveToNextAttribute())
            {
                switch (this.reader.Name)
                {
                case "type":
                    refType = this.reader.Value;
                    break;

                case "ref":
                    refId = long.Parse(this.reader.Value);
                    break;

                case "role":
                    role = this.reader.Value;
                    break;
                }
            }

            if (false == string.Equals(refType, "way") ||
                false == this.ways.TryGetValue(refId, out mapWay) ||
                role == null)
            {
                role   = null;
                mapWay = null;
                return(false);
            }

            return(true);
        }