コード例 #1
0
        /// <summary>
        /// Sets all the info about the buildings and landuses into their lists
        /// </summary>
        private void getBuildingsAndLanduses() {
            FileInfo fileInfo = new FileInfo(OSMFILE);
            XmlOsmStreamSource xmlSource = new XmlOsmStreamSource(fileInfo.OpenRead());
            xmlSource.Initialize();

            while (xmlSource.MoveNextWay()) {
                OsmSharp.Osm.Way way = (OsmSharp.Osm.Way)xmlSource.Current();
                if ((way != null) && (way.Visible.HasValue) && (bool)(way.Visible) && (way.Tags != null)) {

                    // Info about buildings
                    if (way.Tags.ContainsKey("building")) {
                        List<long> buildingNodes = new List<long>();
                        int height = 10; // Standard height is 10
                        string amenity = "";

                        // Check amenity and if it is a church
                        if (way.Tags.ContainsKey("amenity")) {
                            amenity = way.Tags["amenity"];

                            if (amenity == "place_of_worship") height = 25;
                        }

                        // Check height
                        if (way.Tags.ContainsKey("height")) {
                            height = (int)(float.Parse(way.Tags["height"], System.Globalization.CultureInfo.InvariantCulture));
                        } else if (way.Tags.ContainsKey("building:levels")) {
                            string[] verdiepen = way.Tags["building:levels"].Split('-');
                            height = 3 * Convert.ToInt32(verdiepen[verdiepen.Length - 1]);
                            amenity = "apartment";
                        }

                        foreach (long id in way.Nodes) buildingNodes.Add(id);

                        buildings.Add(new Building(buildingNodes, height, amenity, ZOOM));
                    }

                    // Info about landuses
                    if (way.Tags.ContainsKey("landuse")) {
                        List<long> landuseNodes = new List<long>();
                        foreach (long id in way.Nodes) landuseNodes.Add(id);

                        landuses.Add(new Landuse(landuseNodes, 0, way.Tags["landuse"], ZOOM));
                    }
                }
            }

            xmlSource.Dispose();
        }
コード例 #2
0
        /// <summary>
        /// Reads an osmGeo object from disk.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="type"></param>
        private OsmGeo Read(long id, OsmGeoType type)
        {
            XmlOsmStreamSource source = new XmlOsmStreamSource(this.StoreFileName(id, type));
            List<OsmGeo> readObjects = new List<OsmGeo>(source);
            source.Dispose();

            if (readObjects != null && readObjects.Count == 1)
            {
                return readObjects[0];
            }
            throw new InvalidDataException("Invalid cached file read, make sure not to modify the cached while in use or to synchonize access.");
        }