Пример #1
0
 private void ResetBBoxes()
 {
     foreach (var way in osmData.osmWays.Values)
     {
         SpatialUtilities.SetBboxFor(way);
         way.SetCenter();
     }
 }
Пример #2
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);
        }
Пример #3
0
        public BBox OuterBbox()
        {
            var bbox = new BBox();

            foreach (var node in osmNodes.Values)
            {
                bbox = SpatialUtilities.BboxUnion(bbox, node);
            }
            return(bbox);
        }
Пример #4
0
        //<way id = "4526699" version="9" timestamp="2016-09-15T08:28:48Z" uid="1745400" user="******" changeset="42167009">
        //  <nd ref="28099395"/>
        //  <nd ref="1583440533"/>
        //  <nd ref="299356652"/>
        //  <nd ref="28099387"/>
        //  <nd ref="1583440406"/>
        //  <nd ref="28099388"/>
        //  <nd ref="28099389"/>
        //  <nd ref="28099390"/>
        //  <tag k = "highway" v="primary_link"/>
        //  <tag k = "oneway" v="yes"/>
        //</way>

        private void HandleWayRead(XmlReader reader)
        {
            var osmWay = new OSMWay();

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

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

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

            if (node.HasChildNodes)
            {
                var nodeRefs = node.SelectNodes("nd");
                foreach (XmlNode osmNode in nodeRefs)
                {
                    var id = Convert.ToInt64(osmNode.Attributes["ref"].Value);
                    if (osmNodes.ContainsKey(id))
                    {
                        osmWay.NodeList.Add(osmNodes[id]);
                    }
                }


                var tags = node.SelectNodes("tag");
                foreach (XmlNode tag in tags)
                {
                    var key = tag.Attributes["k"].Value;
                    var val = tag.Attributes["v"].Value;
                    osmWay.Tags.Add(key, val);
                }
            }
            SpatialUtilities.SetBboxFor(osmWay);
            osmWay.SetCenter();
            osmWays.Add(osmWay.ID, osmWay);
        }