core icon indicating copy to clipboard operation
core copied to clipboard

Overpass XML cannot be read with XmlOsmStreamSource.

Open verenion opened this issue 6 years ago • 1 comments

According to this issue #75, XML exported from overpass should work perfectly fine. I'm running OSMSharp 6.2.0 from Nuget. I have a seemingly simple issue, but OSMSharp seems to be ignoring the Nodes and Ways from the XML (I assume because they don't have the correct attributes, such as version etc.)

My code is very trivial:

using (var fileStream = new FileInfo(@"tmp.osm").OpenRead())
{
    var source = new OsmSharp.Streams.XmlOsmStreamSource(fileStream);                
    var filtered = from osmGeo in source
                    where osmGeo.Type == OsmGeoType.Way || osmGeo.Type == OsmGeoType.Node
                    select osmGeo;
    var features = filtered.ToFeatureSource();
    foreach (var e in features)
    {
        Console.WriteLine("---"  + e.Geometry.ToString());
    }
}

I'm simply trying to read an OSM from overpass, extract the data as Polygons and use Mapsui to show them. However, features always returns empty. The foreach is never hit.

The OSM file is below, just one simple polygon. tmp.osm.txt

Is there something I'm missing, or is this a bug?

verenion avatar Dec 11 '19 23:12 verenion

Seems like you don't get anything when you read the file? Try:

using (var fileStream = File.OpenRead("tmp.osm.txt"))
{
    XmlSerializer Serializer = new XmlSerializer(typeof(Osm));
    var osm = (Osm)Serializer.Deserialize(fileStream);
    var way = osm.Ways[0];
}

you'll need a using: System.Xml.Serialization;

blackboxlogic avatar Jan 23 '20 14:01 blackboxlogic