[gdal-dev] C# OGR reading OSM features "stalls"
Even Rouault
even.rouault at mines-paris.org
Mon Mar 3 14:39:45 PST 2014
Arno,
>
> 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?
Te issue has nothing to do with the attribute filter (if you remove it, you
will get 0 results as well), but it is due to the fact that you are not
implementing properly the pattern which is documented in
http://gdal.org/ogr/drv_osm.html.... (grrrrrr !!! :-))
In interleaved mode,you need to iterate over ALL layers, and as many times as
one of them report to have a features, and even on the ones you are not
interested in.
And to apply an attribute filter, before running that read pattern itself, set
the filter on the multipolygons layer.
Even
--
Geospatial professional services
http://even.rouault.free.fr/services.html
More information about the gdal-dev
mailing list