[gdal-dev] Reading an OSM file

Even Rouault even.rouault at spatialys.com
Sun Jun 21 05:25:23 PDT 2015


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,

For .osm files, you must build GDAL against the Expat library to have XML 
support.
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/"

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

Even

> 
> ----
> #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

-- 
Spatialys - Geospatial professional services
http://www.spatialys.com


More information about the gdal-dev mailing list