Beispiel #1
0
        public bool BBox(double left, double bottom, double right, double top)
        {
            var mapRequest = OsmMapUrl + "bbox=" + left.ToString() + "," + bottom.ToString() + "," + right.ToString() + "," + top.ToString();

            Xdoc = MakeRequest(mapRequest);
            if (!Xdoc.Equals(null))
            {
                Tile = new TileBound(Mercator.ToMeters(top, left), Mercator.ToMeters(bottom, right));
                Buildings();
                return(true);
            }
            return(false);
        }
Beispiel #2
0
        public BuildingPart BuildPart(XElement way, bool volume = true)
        {
            var tags = way.Descendants("tag")
                       .ToDictionary(
                tag => tag.Attribute("k").Value,  // add key
                tag => tag.Attribute("v").Value); // add value

            // Building creation
            var buildingPart = new BuildingPart(
                tags.ContainsKey("name") ? tags["name"] : "",
                Convert.ToInt64(way.Attribute("id").Value));

            // Outline construction
            // TODO check if closed?
            foreach (var elt in way.Descendants("nd"))
            {
                // find node that matches ways' node ref
                var query = (from node in Xdoc.Descendants("node")
                             where (string)node.Attribute("id") == (string)elt.Attribute("ref")
                             select node).First();

                var pos = Mercator.ToMeters(Convert.ToDouble(query.Attribute("lat").Value), Convert.ToDouble(query.Attribute("lon").Value));
                var x   = pos.X - Tile.Center.X;
                var y   = pos.Y - Tile.Center.Y;
                buildingPart.Outline.Add(new Vector2(x, y));
            }

            // Part data
            PartData part;

            part.volume       = volume;
            part.height       = float.Parse(tags.ContainsKey("height") ? Regex.Match(tags["height"], @"\d+").Value : "-1", CultureInfo.InvariantCulture);
            part.min_height   = float.Parse(tags.ContainsKey("min_height") ? Regex.Match(tags["min_height"], @"\d+").Value : "-1", CultureInfo.InvariantCulture);
            part.levels       = Convert.ToInt16(tags.ContainsKey("building:levels") ? tags["building:levels"] : "-1");
            part.min_level    = Convert.ToInt16(tags.ContainsKey("building:min_level") ? tags["building:min_level"] : "-1");
            buildingPart.Data = part;

            Surface surf;

            surf.colour              = tags.ContainsKey("building:colour") ? tags["building:colour"] : "";
            surf.material            = tags.ContainsKey("building:material") ? tags["building:material"] : "";
            buildingPart.PartSurface = surf;

            return(buildingPart);
        }