[GIS] imposm: Failing to import OSM data to PostgreSQL

imposmopenstreetmappostgispostgresql

Somehow I can't import OSM data to my database. I'm using Debian, PostgreSQL 9.1 and PostGIS 1.5. The user root has been granted all privileges for the database osm.

Input:

imposm -U root -d osm -m imposm-mapping.py --read --write --optimize sweden-latest.osm.pbf

Output:

Enabling Shapely speedups.
loading imposm-mapping.py as mapping
password for root at localhost:
[16:35:06] ## reading sweden-latest.osm.pbf
[16:35:07] coords: 11724k nodes: 234k ways: 1674k relations: 11k (estimated)
[16:39:56] coords: 17332k nodes: 75k ways: 1445k relations: 7k
[16:39:57] reading took 4 m 51s
[16:39:57] ## dropping/creating tables
Traceback (most recent call last):
  File "/usr/bin/imposm", line 9, in <module>
    load_entry_point('imposm==2.4.0', 'console_scripts', 'imposm')()
  File "/usr/lib/python2.7/dist-packages/imposm/app.py", line 231, in main
    db.create_tables(tag_mapping.mappings)
  File "/usr/lib/python2.7/dist-packages/imposm/db/postgis.py", line 129, in create_tables
    self.create_table(mapping)
  File "/usr/lib/python2.7/dist-packages/imposm/db/postgis.py", line 160, in create_table
    pg_geometry_type=mapping.geom_type))
psycopg2.ProgrammingError: permission denied for relation spatial_ref_sys
CONTEXT:  SQL statement "SELECT SRID         FROM spatial_ref_sys WHERE SRID = new_srid"
PL/pgSQL function "addgeometrycolumn" line 75 at SQL statement
SQL statement "SELECT AddGeometryColumn('',$1,$2,$3,$4,$5,$6)"
PL/pgSQL function "addgeometrycolumn" line 5 at SQL statement

EDIT:

And this is what I get when I use the user postgres instead:

[13:36:35] ## dropping/creating tables
[13:36:36] ## writing data
Traceback (most recent call last):
  File "/usr/bin/imposm", line 9, in <module>
    load_entry_point('imposm==2.4.0', 'console_scripts', 'imposm')()
  File "/usr/lib/python2.7/dist-packages/imposm/app.py", line 243, in main
    writer.relations()
  File "/usr/lib/python2.7/dist-packages/imposm/writer.py", line 52, in relation                                    s
    cache = self.cache.relations_cache()
  File "/usr/lib/python2.7/dist-packages/imposm/cache/osm.py", line 59, in relat                                    ions_cache
    return self._x_cache(self.relations_fname, RelationDB, mode, estimated_recor                                    ds)
  File "/usr/lib/python2.7/dist-packages/imposm/cache/osm.py", line 68, in _x_ca                                    che
    cache = x_class(x, mode, estimated_records=estimated_records)
  File "tc.pyx", line 104, in imposm.cache.tc.BDB.__init__ (imposm/cache/tc.c:12                                    63)
IOError: 3

Best Answer

Try importing your data using user postgres (-u postgres). Before you complain ;) you don't know the password for that user, do the following:

sudo su postgres
(type your password)
psql
ALTER USER postgres WITH PASSWORD 'set_your_pass_here';
\q
exit
Related Question