[gdal-dev] Reading an OSM file

Gökçen Eraslan gokcen.eraslan at gmail.com
Sun Jun 21 05:35:13 PDT 2015


Hi Even,

On 2015-06-21 14:25, Even Rouault wrote:
> Le dimanche 21 juin 2015 14:07:28, Gökçen Eraslan a écrit :
>> Hi everyone,
>>
>> I am trying to read an OSM file which I downloaded from geofabrik.
>> Although I can get the OSM driver by name (readonly), I get nothing when
>> I try to open the data source in which several .osm and osm.bz2 files
>> present:
> 
> Gökçen,
> 

Thanks for your very fast reply.

> For .osm files, you must build GDAL against the Expat library to have XML 
> support.

I am using my distro package. I think my gdal is already built with the
expat support, otherwise it wouldn't show OSM in the "ogrinfo --formats"
output, would it?

In addition, when I try:

    OGRSFDriverRegistrar *reg = OGRSFDriverRegistrar::GetRegistrar();
    OGRSFDriver *osmdrv = reg->GetDriverByName("OSM");
    OGRDataSource *myosm = osmdrv->Open("myfile.osm");

last line returns successfully, which is good, but I still don't get why
OGRSFDriverRegistrar::Open() returns NULL always.

> For .osm.bz2, you have to uncompress them priorly to ingesting into GDAL. You 
> can potentially do it on-the-fly, with something like "cat your.osm.bz2 | 
> bunzip2 | your_program /vsistdin/"
> 

OK, but I am already using a plain XML .osm file. I also have .osm.pbf
files in the same directory but OGRSFDriverRegistrar::Open() always
returns NULL. My gdal library has sqlite support built-in.

> You must also be aware that proper reading of "big" osm files require to turn 
> on "interleaved reading" mode, as explained in http://gdal.org/drv_osm.html
> 

That I didn't know. Thanks for pointing out. My .osm file is 60M and
.osm.pbf is just 3M. Compared to the planet.osm file, they really tiny :)

> Even
> 

Gokcen.

>>
>> ----
>> #include "ogrsf_frmts.h"
>>
>> int main()
>>
>> {
>>     OGRRegisterAll();
>>
>>     OGRDataSource       *poDS;
>>     OGRSFDriverRegistrar *reg = OGRSFDriverRegistrar::GetRegistrar();
>>     OGRSFDriver *osmdrv = reg->GetDriverByName("OSM");
>>
>>     if( osmdrv == NULL )
>>     {
>>         printf( "OSM driver open failed.\n" );
>>         exit( 1 );
>>     }
>>
>>     poDS = OGRSFDriverRegistrar::Open( ".", FALSE );
>>     if( poDS == NULL )
>>     {
>>         printf( "Open failed.\n" );
>>         exit( 1 );
>>     }
>>     return 0;
>> }
>> ----
>>
>> Program only prints the message "Open failed". I can also see OSM
>> (readonly) in "ogrinfo --formats" output. I would appreciate if someone
>> could help me out.
>>
>> PS: I am using gdal 1.11.2. Actually, what I would like to do is to read
>> the file from within R through rgdal but it seems I cannot even read the
>> file at C level via libgdal.
>>
>> Thanks in advance.
>>
>> Best regards.
>> Gokcen.
>> _______________________________________________
>> gdal-dev mailing list
>> gdal-dev at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/gdal-dev
> 

-- 
Gökçen Eraslan


More information about the gdal-dev mailing list