public OSMreader() { _peeks = new List <Peek>(); file = new FileInfo(@"OSMrecources\België.osm"); xmlSource = new XmlOsmStreamSource(file.OpenRead()); xmlSource.Initialize(); read(); }
/// <summary> /// Sets all the nodes into the global variable nodes /// </summary> private void getNodes() { xmlSource.Initialize(); while (xmlSource.MoveNextNode()) { OsmSharp.Osm.Node node = (OsmSharp.Osm.Node)xmlSource.Current(); if ((node != null) && (node.Id.HasValue && (node.Visible.HasValue) && (bool)(node.Visible))) { nodes.Add((long)node.Id, node); } } }
/// <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(); }