Osm2pgsql/o5m

From OpenStreetMap Wiki
Jump to: navigation, search
Available languages
English русский

The o5m import interface for osm2pgsql is used to allow osm2pgsql to read data which have been written in o5m file format.

Installation

Proceed as described in osm2pgsql#From_source_(generic), with one exception:

After having exported the source via svn, download the o5m import interface 2012-10-14. Then unpack the files and move them into osm2pgsql subdirectory. Two of the files are new: parse-o5m.c and parse-o5m.h, two are already existing and must be overwritten: osm2pgsql.c and Makefile.am.

The import interface has been successfully tested with osm2pgsql revision 26278. As usual: There is no warranty, to the extent permitted by law.

In case the regular source file osm2pgsql.c should have been modified since revision 26278, here the additional lines (marked with +) which will be necessary to get the import interface running:

***************
*** 54,59 ****
--- 54,60 ----
  #include "sprompt.h"
  #include "parse-xml2.h"
  #include "parse-primitive.h"
+ #include "parse-o5m.h"
  
  #ifdef BUILD_READER_PBF
  #  include "parse-pbf.h"
***************
*** 174,179 ****
--- 175,181 ----
  #ifdef BUILD_READER_PBF
      printf("              \t\tpbf       - OSM binary format.\n");
  #endif
+     printf("              \t\to5m       - OSM binary format.\n");
      printf("   -O|--output\t\tOutput backend.\n");
      printf("              \t\tpgsql - Output to a PostGIS database. (default)\n");
      printf("              \t\tgazetteer - Output to a PostGIS database suitable for gazetteer\n");
***************
*** 520,525 ****
--- 522,529 ----
          streamFile = &streamFileXML2;
        } else if (strcmp("primitive", input_reader) == 0) {
          streamFile = &streamFilePrimitive;
+       } else if (strcmp("o5m", input_reader) == 0) {
+         streamFile = &streamFileO5m;
  #ifdef BUILD_READER_PBF
        } else if (strcmp("pbf", input_reader) == 0) {
          streamFile = &streamFilePbf;
***************
*** 550,555 ****
--- 554,563 ----
          /* if input_reader is not forced by -r switch try to auto-detect it
             by file extension */
          if (strcmp("auto", input_reader) == 0) {
+           if (strcasecmp(".o5m",argv[optind]+strlen(argv[optind])-4) == 0 ||
+               strcasecmp(".o5c",argv[optind]+strlen(argv[optind])-4) == 0) {
+             streamFile = &streamFileO5m;
+           } else
  #ifdef BUILD_READER_PBF
            if (strcasecmp(".pbf",argv[optind]+strlen(argv[optind])-4) == 0) {
              streamFile = &streamFilePbf;

In Makefile.am you simply would have to add parse-o5m.c and parse-o5m.h to the compile list.

Further Information

Please see o5m related Wiki pages to get further information about this file format:

  • o5m
  • osmconvert – convert between different data formats, clip regions
  • osmfilter – filter specific OSM objects or specific tags, do offline taginfo

Benchmarks

Reading .o5m file format is usually a bit faster than reading most other OSM file formats, but you should not expect significantly increased processing speed, because writing to the database will be the bottleneck.

Feel free to add your own benchmark results.