This is a static archive of our old OpenStreetMap Help Site. Please post any new questions and answers at community.osm.org.

OsmSharp filtering and completion is slow

1

I'm not sure I'm doing this correctly. I'm trying to get hold of the coastline of a specific little island using OsmSharp and an osm-map of Singapore (xml format).

    XmlOsmStreamSource source = new XmlOsmStreamSource(fileStream);

    var islandsIncomplete = from osmGeo in source where (osmGeo.Type == OsmSharp.OsmGeoType.Relation && osmGeo.Tags.Contains("name", "Pulau Ubin"))
    || (osmGeo.Type == OsmSharp.OsmGeoType.Way && osmGeo.Tags.Contains("natural", "coastline"))
    || (osmGeo.Type == OsmSharp.OsmGeoType.Node)
    select osmGeo;

    var completes = incompletes.ToComplete();

    var relations = from osmGeo in completes where osmGeo.Type == OsmSharp.OsmGeoType.Relation select osmGeo;
    return relations.Cast<CompleteRelation>().ToArray();

So I looked into the xml file for these specific keys and values and I think I'm only extracting the necessary objects for completion. Yet, the process takes a really long time to complete. What is it doing that is taking so long? The above example seems to never complete, but even in other examples I try to extract a small amout of specific ways from the file, and it takes many minutes. Maybe there is something I don't understand here. Maybe I should better parse the xml file myself?

Is there any OsmSharp forum?

asked 12 Nov '20, 12:31

laban77's gravatar image

laban77
26112
accept rate: 0%


One Answer:

0

Also, try opening an issue on the OSMSharp Github at https://github.com/OsmSharp/core

answered 13 Nov '20, 12:32

Mike%20N's gravatar image

Mike N
2.9k22254
accept rate: 17%

I would if I thought that there were something wrong. I have a feeling though that I have just misunderstood the whole thing. It's not stated anywhere that the processing should take such a long time. By the way I found out why the example above never finishes. I had forgotten to check that osmGeo.Tags is not null before checking what it contains. The error is probably swallowed later by the Cast command.

The problem is really a lack of documentation. The best I have found so far is to look through the examples in the source code itself.

(13 Nov '20, 15:24) laban77

Source code available on GitHub .