Example #1
0
        //  <relation id = "1084743" version="2" timestamp="2015-05-30T03:46:23Z" changeset="31576221" uid="2311536" user="******">
        //  <member type = "way" ref="69127471" role="outer"/>
        //  <member type = "way" ref="69127440" role="inner"/>
        //  <tag k = "building" v="yes"/>
        //  <tag k = "type" v="multipolygon"/>
        //</relation>


        private void HandlRelationRead(XmlReader reader)
        {
            var osmRelation = new OSMRelation();

            osmRelation.ID = Convert.ToInt64(reader.GetAttribute("id"));

            var     doc  = new System.Xml.XmlDocument();
            XmlNode node = doc.ReadNode(reader);

            foreach (XmlAttribute attr in node.Attributes)
            {
                osmRelation.InnerAttributes.Add(attr.Name, attr.Value);
            }

            if (node.HasChildNodes)
            {
                var members = node.SelectNodes("member");
                foreach (XmlNode member in members)
                {
                    var relationType = member.Attributes["type"].Value;
                    var id           = Convert.ToInt64(member.Attributes["ref"].Value);
                    var role         = member.Attributes["role"].Value;
                    var osmMember    = new RelationMember();
                    osmMember.MemberType = relationType;
                    osmMember.Ref        = id;
                    osmMember.Role       = role;
                    osmRelation.Members.Add(osmMember);

                    if (relationType == "way")
                    {
                        if (osmWays.ContainsKey(id))
                        {
                            osmRelation.OSMWays.Add(osmWays[id]);
                        }
                    }
                }

                var tags = node.SelectNodes("tag");
                foreach (XmlNode tag in tags)
                {
                    var key = tag.Attributes["k"].Value;
                    var val = tag.Attributes["v"].Value;

                    osmRelation.Tags.Add(key, val);
                }
            }

            var bbox = new BBox();

            foreach (var way in osmRelation.OSMWays)
            {
                bbox = SpatialUtilities.BboxUnion(bbox, way.Bbox);
            }
            osmRelation.Bbox = bbox;
            osmRelation.SetCenter();
            osmRelations.Add(osmRelation.ID, osmRelation);
        }
Example #2
0
        public BBox OuterBbox()
        {
            var bbox = new BBox();

            foreach (var node in osmNodes.Values)
            {
                bbox = SpatialUtilities.BboxUnion(bbox, node);
            }
            return(bbox);
        }
Example #3
0
 public static bool BBoxIntersects(BBox bbox1, BBox bbox2)
 {
     if ((bbox1.MaxLat < bbox2.MinLat) ||
         (bbox1.MaxLon < bbox2.MinLon) ||
         (bbox1.MinLon > bbox2.MaxLon) ||
         (bbox1.MinLat > bbox2.MaxLat))
     {
         return(false);
     }
     return(true);
 }
Example #4
0
 public static bool BBoxContains(BBox bbox, OSMNode osmNode)
 {
     if ((osmNode.Lat >= bbox.MinLat) &&
         (osmNode.Lon >= bbox.MinLon) &&
         (osmNode.Lat < bbox.MaxLat) &&
         (osmNode.Lon < bbox.MaxLon))
     {
         return(true);
     }
     return(false);
 }
Example #5
0
        /// <summary>
        /// Calculate union of area covered by both boxes,
        /// including any area between boxes
        /// </summary>
        /// <param name="bbox1"></param>
        /// <param name="bbox2"></param>
        /// <returns></returns>
        public static BBox BboxUnion(BBox bbox1, BBox bbox2)
        {
            var bbox = new BBox();

            bbox.MinLat = bbox1.MinLat < bbox2.MinLat ? bbox1.MinLat : bbox2.MinLat;
            bbox.MinLon = bbox1.MinLon < bbox2.MinLon ? bbox1.MinLon : bbox2.MinLon;

            bbox.MaxLat = bbox1.MaxLat > bbox2.MaxLat ? bbox1.MaxLat : bbox2.MaxLat;
            bbox.MaxLon = bbox1.MaxLon > bbox2.MaxLon ? bbox1.MaxLon : bbox2.MaxLon;

            return(bbox);
        }
Example #6
0
        /// <summary>
        /// set or expand box if node not already contained
        /// </summary>
        /// <param name="bbox1"></param>
        /// <param name="node"></param>
        /// <returns></returns>
        public static BBox BboxUnion(BBox bbox1, OSMNode node)
        {
            var bbox = new BBox();

            bbox.MinLat = bbox1.MinLat < node.Lat ? bbox1.MinLat : node.Lat;
            bbox.MinLon = bbox1.MinLon < node.Lon ? bbox1.MinLon : node.Lon;

            bbox.MaxLat = bbox1.MaxLat > node.Lat ? bbox1.MaxLat : node.Lat;
            bbox.MaxLon = bbox1.MaxLon > node.Lon ? bbox1.MaxLon : node.Lon;

            return(bbox);
        }
Example #7
0
 public OSMWay() : base()
 {
     Bbox     = new BBox();
     NodeList = new List <OSMNode>();
 }