[gdal-dev] C# OGR reading OSM features "stalls"

agerrius arno at agerrius.nl
Mon Mar 3 12:40:25 PST 2014


Arno,

I have made a small sample to show my problem. It uses the same OSM file as
I mentioned above. Hopefully you can see what I did wrong from my code.

If I read the data in non-interleaved mode it all works fine, I find 298
features on the layer:

                Ogr.RegisterAll();
                DataSource ds =
Ogr.Open(@"C:\flightsim\work\nantucket\source\geo\osm\nantucket.osm", 0);
                int count = 0;

                Layer lay = ds.GetLayerByName("multipolygons");
                Feature feat;

                Console.WriteLine("Reading layer " + lay.GetName());

                lay.SetAttributeFilter("landuse IS NOT NULL");
                feat = lay.GetNextFeature();     // work around for the
issue we discussed before
                lay.ResetReading();

                feat = lay.GetNextFeature();
                while (feat != null)
                {
                    count++;
                    feat = lay.GetNextFeature();
                }
                Console.WriteLine(String.Format("Contains {0} features",
count));

Now if I enable interleaved reading and add the extra do-while loop around
my code I get 0 features returned. I only apply the filter to the layer the
first time I go through the loop.

                Ogr.RegisterAll();
                Gdal.SetConfigOption("OGR_INTERLEAVED_READING", "YES");
                DataSource ds =
Ogr.Open(@"C:\flightsim\work\nantucket\source\geo\osm\nantucket.osm", 0);
                bool nonEmpty = false;
                bool firstRun = true;
                int count = 0;

                do
                {
                    nonEmpty = false;

                    Layer lay = ds.GetLayerByName("multipolygons");
                    Feature feat;

                    if (firstRun)
                    {
                        Console.WriteLine("Reading layer " + lay.GetName());

                        lay.SetAttributeFilter("landuse IS NOT NULL");
                        feat = lay.GetNextFeature();
                        lay.ResetReading();
                    }

                    feat = lay.GetNextFeature();
                    while (feat != null)
                    {
                        nonEmpty = true;
                        count++;
                        feat = lay.GetNextFeature();
                    }
                    firstRun = false;
                } while (nonEmpty);
                Console.WriteLine(String.Format("Contains {0} features",
count));
            }

I think the problem is that no features are found in the first "slice of the
interleaved reading. So therefore nonEmpty is never set to true and the do
loop stops directly, while the features that match the filter are probably
later in the OSM file. But I'm not sure if this assumption is OK.

Do you see any mistakes in my code?

Thanks,

Arno



--
View this message in context: http://osgeo-org.1560.x6.nabble.com/C-OGR-reading-OSM-features-stalls-tp5106937p5107214.html
Sent from the GDAL - Dev mailing list archive at Nabble.com.


More information about the gdal-dev mailing list