Od jakiegoś czasu męczę się z importem OpenStreetMap do Postgresa jednak z marnymi skutkami.
Oto zamierzony efekt
A tu
więcej przykładów
Wymyśliłem sobie, że osiągnę to dzięki gotowym stylom QGISa dostępnym
tutaj
Początkowo udał mi się import (jakichś) danych za pomocą
osm2pgsql, jednak dane w tabelach atrybutów miały się nijak do tego, czego wymagały dostępne pliki stylów.
Kolejne próby podejmowałem z pomocą
Osm2postgresql, jednak zniechęciły mnie ciągłe błędy mówiące o braku bazy "tomasz" (moja nazwa użytkownika systemowego), braku użytkownika, nieprawidłowym haśle... itp.
Potem przyszła pora na
kolejną metodę, "na PostGISa"
Wszystko wydaje się iść dobrze. Do czasu. Po wydaniu polecenia:
Kod:
psql -d $dbname -f /usr/share/postgresql/8.4/contrib/hstore-new.sql
otrzymuję tego typu komunikaty:
Kod:
BEGIN
SET
CREATE TYPE
psql:/usr/share/postgresql/8.4/contrib/hstore-new.sql:18: NOTICE: return type hstore is only a shell
CREATE FUNCTION
psql:/usr/share/postgresql/8.4/contrib/hstore-new.sql:23: NOTICE: argument type hstore is only a shell
CREATE FUNCTION
psql:/usr/share/postgresql/8.4/contrib/hstore-new.sql:28: NOTICE: return type hstore is only a shell
CREATE FUNCTION
psql:/usr/share/postgresql/8.4/contrib/hstore-new.sql:33: NOTICE: argument type hstore is only a shell
CREATE FUNCTION
CREATE TYPE
CREATE FUNCTION
CREATE OPERATOR
(...)
CREATE OPERATOR CLASS
CREATE TYPE
psql:/usr/share/postgresql/8.4/contrib/hstore-new.sql:419: NOTICE: return type ghstore is only a shell
CREATE FUNCTION
psql:/usr/share/postgresql/8.4/contrib/hstore-new.sql:424: NOTICE: argument type ghstore is only a shell
CREATE FUNCTION
CREATE TYPE
CREATE FUNCTION
(...)
CREATE FUNCTION
psql:/usr/share/postgresql/8.4/contrib/hstore-new.sql:485: NOTICE: RECHECK is no longer required
LINE 4: OPERATOR 7 @> RECHECK,
^
HINT: Update your data type.
psql:/usr/share/postgresql/8.4/contrib/hstore-new.sql:485: NOTICE: RECHECK is no longer required
LINE 5: OPERATOR 9 ?(hstore,text) RECHECK,
^
HINT: Update your data type.
psql:/usr/share/postgresql/8.4/contrib/hstore-new.sql:485: NOTICE: RECHECK is no longer required
LINE 6: OPERATOR 10 ?|(hstore,text[]) RECHECK,
^
HINT: Update your data type.
psql:/usr/share/postgresql/8.4/contrib/hstore-new.sql:485: NOTICE: RECHECK is no longer required
LINE 7: OPERATOR 11 ?&(hstore,text[]) RECHECK,
^
HINT: Update your data type.
psql:/usr/share/postgresql/8.4/contrib/hstore-new.sql:485: NOTICE: RECHECK is no longer required
LINE 9: OPERATOR 13 @ RECHECK,
^
HINT: Update your data type.
CREATE OPERATOR CLASS
CREATE FUNCTION
CREATE FUNCTION
CREATE FUNCTION
psql:/usr/share/postgresql/8.4/contrib/hstore-new.sql:515: NOTICE: RECHECK is no longer required
LINE 4: OPERATOR 7 @> RECHECK,
^
HINT: Update your data type.
CREATE OPERATOR CLASS
COMMIT
Uznałem, że to nic złego (słusznie?), więc kontynuuję. Za pomocą osmosis tworzę strukturę OSM w PostgresQL i dostaję coś takiego (wygląda podejrzanie):
Kod:
tomasz@tomasz-desktop:~/Geoinformacja/wektor/osm$ psql -f /home/tomasz/osmosis-0.39/script/pgsimple_schema_0.6.sql -d $dbname
psql:/home/tomasz/osmosis-0.39/script/pgsimple_schema_0.6.sql:4: NOTICE: table "actions" does not exist, skipping
DROP TABLE
psql:/home/tomasz/osmosis-0.39/script/pgsimple_schema_0.6.sql:5: NOTICE: table "users" does not exist, skipping
DROP TABLE
psql:/home/tomasz/osmosis-0.39/script/pgsimple_schema_0.6.sql:6: NOTICE: table "nodes" does not exist, skipping
DROP TABLE
psql:/home/tomasz/osmosis-0.39/script/pgsimple_schema_0.6.sql:7: NOTICE: table "node_tags" does not exist, skipping
DROP TABLE
psql:/home/tomasz/osmosis-0.39/script/pgsimple_schema_0.6.sql:8: NOTICE: table "ways" does not exist, skipping
DROP TABLE
psql:/home/tomasz/osmosis-0.39/script/pgsimple_schema_0.6.sql:9: NOTICE: table "way_nodes" does not exist, skipping
DROP TABLE
psql:/home/tomasz/osmosis-0.39/script/pgsimple_schema_0.6.sql:10: NOTICE: table "way_tags" does not exist, skipping
DROP TABLE
psql:/home/tomasz/osmosis-0.39/script/pgsimple_schema_0.6.sql:11: NOTICE: table "relations" does not exist, skipping
DROP TABLE
psql:/home/tomasz/osmosis-0.39/script/pgsimple_schema_0.6.sql:12: NOTICE: table "relation_members" does not exist, skipping
DROP TABLE
psql:/home/tomasz/osmosis-0.39/script/pgsimple_schema_0.6.sql:13: NOTICE: table "relation_tags" does not exist, skipping
DROP TABLE
psql:/home/tomasz/osmosis-0.39/script/pgsimple_schema_0.6.sql:14: NOTICE: table "schema_info" does not exist, skipping
DROP TABLE
psql:/home/tomasz/osmosis-0.39/script/pgsimple_schema_0.6.sql:17: NOTICE: function osmosisupdate() does not exist, skipping
DROP FUNCTION
CREATE TABLE
CREATE TABLE
CREATE TABLE
addgeometrycolumn
------------------------------------------------
public.nodes.geom SRID:4326 TYPE:POINT DIMS:2
(1 row)
CREATE TABLE
CREATE TABLE
CREATE TABLE
CREATE TABLE
CREATE TABLE
CREATE TABLE
CREATE TABLE
INSERT 0 1
psql:/home/tomasz/osmosis-0.39/script/pgsimple_schema_0.6.sql:111: NOTICE: ALTER TABLE / ADD PRIMARY KEY will create implicit index "pk_schema_info" for table "schema_info"
ALTER TABLE
psql:/home/tomasz/osmosis-0.39/script/pgsimple_schema_0.6.sql:113: NOTICE: ALTER TABLE / ADD PRIMARY KEY will create implicit index "pk_users" for table "users"
ALTER TABLE
psql:/home/tomasz/osmosis-0.39/script/pgsimple_schema_0.6.sql:115: NOTICE: ALTER TABLE / ADD PRIMARY KEY will create implicit index "pk_nodes" for table "nodes"
ALTER TABLE
psql:/home/tomasz/osmosis-0.39/script/pgsimple_schema_0.6.sql:117: NOTICE: ALTER TABLE / ADD PRIMARY KEY will create implicit index "pk_ways" for table "ways"
ALTER TABLE
psql:/home/tomasz/osmosis-0.39/script/pgsimple_schema_0.6.sql:119: NOTICE: ALTER TABLE / ADD PRIMARY KEY will create implicit index "pk_way_nodes" for table "way_nodes"
ALTER TABLE
psql:/home/tomasz/osmosis-0.39/script/pgsimple_schema_0.6.sql:121: NOTICE: ALTER TABLE / ADD PRIMARY KEY will create implicit index "pk_relations" for table "relations"
ALTER TABLE
psql:/home/tomasz/osmosis-0.39/script/pgsimple_schema_0.6.sql:123: NOTICE: ALTER TABLE / ADD PRIMARY KEY will create implicit index "pk_relation_members" for table "relation_members"
ALTER TABLE
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE INDEX
CREATE FUNCTION
potem coś takiego (wygląda dobrze):
Kod:
tomasz@tomasz-desktop:~/Geoinformacja/wektor/osm$ psql -f /home/tomasz/osmosis-0.39/script/pgsimple_schema_0.6_bbox.sql -d $dbname
addgeometrycolumn
--------------------------------------------------
public.ways.bbox SRID:4326 TYPE:GEOMETRY DIMS:2
(1 row)
CREATE INDEX
i takiego:
Kod:
tomasz@tomasz-desktop:~/Geoinformacja/wektor/osm$ psql -f /home/tomasz/osmosis-0.39/script/pgsimple_schema_0.6_linestring.sql -d $dbname
addgeometrycolumn
--------------------------------------------------------
public.ways.linestring SRID:4326 TYPE:GEOMETRY DIMS:2
(1 row)
CREATE INDEX
tomasz@tomasz-desktop:~/Geoinformacja/wektor/osm$
Kolejny krok budzi moje wątpliwości, tworzę sobie gdzieś na dysku katalog i każę mu być tymczasowym(?):
Kod:
export JAVACMD_OPTIONS="-Djava.io.tmpdir=/home/tomasz/osm/tmp"
Powyższa komenda nie zwraca żadnej odpowiedzi, uznaję, że wszystko jest OK.
Jak podglądam bazę w pgAdmin III to jakieś tabele (puste) są ale wydaje mi się, że to jakoś mało.
Próbuję zaimportować małą porcję danych, początkowo wszystko wydaje się być dobrze:
Kod:
tomasz@tomasz-desktop:~/Geoinformacja/wektor/osm$ /home/tomasz/osmosis-0.39/bin/osmosis -v --read-xml file="/home/tomasz/osm/test.osm" --buffer --write-pgsql host="127.0.0.1" database="osmlodz" user="tomasz" password="mojehaslo"
2011-07-12 15:27:04 org.openstreetmap.osmosis.core.Osmosis run
INFO: Osmosis Version 0.39
2011-07-12 15:27:04 org.openstreetmap.osmosis.core.TaskRegistrar loadJPFPlugins
FINE: Searching for JPF plugins.
2011-07-12 15:27:04 org.openstreetmap.osmosis.core.TaskRegistrar loadJPFPlugins
FINE: Registering the core plugin.
(...)
Jednak potem...
Kod:
SEVERE: Thread for task 2-buffer failed
org.openstreetmap.osmosis.core.OsmosisRuntimeException: The database schema version of 5 does not match the expected version of 6.
at org.openstreetmap.osmosis.pgsnapshot.common.SchemaVersionValidator.validateDBVersion(SchemaVersionValidator.java:67)
at org.openstreetmap.osmosis.pgsnapshot.common.SchemaVersionValidator.validateVersion(SchemaVersionValidator.java:47)
at org.openstreetmap.osmosis.pgsnapshot.v0_6.impl.CopyFilesetLoader.run(CopyFilesetLoader.java:78)
at org.openstreetmap.osmosis.pgsnapshot.v0_6.PostgreSqlCopyWriter.complete(PostgreSqlCopyWriter.java:108)
at org.openstreetmap.osmosis.core.buffer.v0_6.EntityBuffer.run(EntityBuffer.java:77)
at java.lang.Thread.run(Thread.java:636)
2011-07-12 15:27:06 org.openstreetmap.osmosis.core.pipeline.common.PassiveTaskManager waitForCompletion
FINE: Task 3-write-pgsql is passive, no completion wait required.
2011-07-12 15:27:06 org.openstreetmap.osmosis.core.Osmosis main
SEVERE: Execution aborted.
org.openstreetmap.osmosis.core.OsmosisRuntimeException: One or more tasks failed.
at org.openstreetmap.osmosis.core.pipeline.common.Pipeline.waitForCompletion(Pipeline.java:146)
at org.openstreetmap.osmosis.core.Osmosis.run(Osmosis.java:92)
at org.openstreetmap.osmosis.core.Osmosis.main(Osmosis.java:37)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchStandard(Launcher.java:329)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:239)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
at org.codehaus.classworlds.Launcher.main(Launcher.java:31)
I tutaj utknąłem. Próbowałem jeszcze wyłączyć walidację "database schema version", ale niewiele to dało (inne błędy):
Kod:
tomasz@tomasz-desktop:~/Geoinformacja/wektor/osm$ /home/tomasz/osmosis-0.39/bin/osmosis -v --read-xml file="/home/tomasz/osm/test.osm" --buffer --write-pgsql host="127.0.0.1" database="osm" user="tomasz" password="mojehaslo" nodeLocationStoreType="TempFile"
(...)
SEVERE: Unable to close writer.
java.io.IOException: No space left on device
at java.io.FileOutputStream.writeBytes(Native Method)
at java.io.FileOutputStream.write(FileOutputStream.java:297)
at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:82)
at java.io.BufferedOutputStream.write(BufferedOutputStream.java:126)
at sun.nio.cs.StreamEncoder.writeBytes(StreamEncoder.java:220)
at sun.nio.cs.StreamEncoder.implClose(StreamEncoder.java:315)
at sun.nio.cs.StreamEncoder.close(StreamEncoder.java:148)
at java.io.OutputStreamWriter.close(OutputStreamWriter.java:233)
at java.io.BufferedWriter.close(BufferedWriter.java:265)
at org.openstreetmap.osmosis.pgsnapshot.common.CopyFileWriter.release(CopyFileWriter.java:386)
at org.openstreetmap.osmosis.core.lifecycle.CompletableContainer.release(CompletableContainer.java:61)
at org.openstreetmap.osmosis.pgsnapshot.v0_6.impl.CopyFilesetBuilder.release(CopyFilesetBuilder.java:246)
at org.openstreetmap.osmosis.pgsnapshot.v0_6.PostgreSqlCopyWriter.release(PostgreSqlCopyWriter.java:119)
at org.openstreetmap.osmosis.core.buffer.v0_6.EntityBuffer.run(EntityBuffer.java:85)
at java.lang.Thread.run(Thread.java:636)
2011-07-12 16:01:13 org.openstreetmap.osmosis.core.pipeline.common.ActiveTaskManager waitForCompletion
SEVERE: Thread for task 1-read-xml failed
org.openstreetmap.osmosis.core.OsmosisRuntimeException: An output error has occurred, aborting.
at org.openstreetmap.osmosis.core.store.DataPostbox.checkForOutputErrors(DataPostbox.java:78)
at org.openstreetmap.osmosis.core.store.DataPostbox.populateCentralQueue(DataPostbox.java:134)
at org.openstreetmap.osmosis.core.store.DataPostbox.put(DataPostbox.java:184)
at org.openstreetmap.osmosis.core.buffer.v0_6.EntityBuffer.process(EntityBuffer.java:38)
at org.openstreetmap.osmosis.xml.v0_6.impl.NodeElementProcessor.end(NodeElementProcessor.java:117)
at org.openstreetmap.osmosis.xml.v0_6.impl.OsmHandler.endElement(OsmHandler.java:107)
at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
at org.apache.xerces.parsers.AbstractXMLDocumentParser.emptyElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl.parse(Unknown Source)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:195)
at org.openstreetmap.osmosis.xml.v0_6.XmlReader.run(XmlReader.java:108)
at java.lang.Thread.run(Thread.java:636)
2011-07-12 16:01:13 org.openstreetmap.osmosis.core.pipeline.common.ActiveTaskManager waitForCompletion
FINE: Waiting for task 2-buffer to complete.
2011-07-12 16:01:13 org.openstreetmap.osmosis.core.pipeline.common.ActiveTaskManager waitForCompletion
SEVERE: Thread for task 2-buffer failed
org.openstreetmap.osmosis.core.OsmosisRuntimeException: Unable to write node location data to node storage file /home/tomasz/osm/tmp/nodelatlon4322851985942686318.tmp.
at org.openstreetmap.osmosis.pgsnapshot.common.PersistentNodeLocationStore.addLocation(PersistentNodeLocationStore.java:170)
at org.openstreetmap.osmosis.pgsnapshot.v0_6.impl.WayGeometryBuilder.addNodeLocation(WayGeometryBuilder.java:64)
at org.openstreetmap.osmosis.pgsnapshot.v0_6.impl.CopyFilesetBuilder.process(CopyFilesetBuilder.java:157)
at org.openstreetmap.osmosis.core.container.v0_6.NodeContainer.process(NodeContainer.java:58)
at org.openstreetmap.osmosis.pgsnapshot.v0_6.impl.CopyFilesetBuilder.process(CopyFilesetBuilder.java:115)
at org.openstreetmap.osmosis.pgsnapshot.v0_6.PostgreSqlCopyWriter.process(PostgreSqlCopyWriter.java:95)
at org.openstreetmap.osmosis.core.buffer.v0_6.EntityBuffer.run(EntityBuffer.java:74)
at java.lang.Thread.run(Thread.java:636)
Caused by: java.io.IOException: No space left on device
at java.io.FileOutputStream.writeBytes(Native Method)
at java.io.FileOutputStream.write(FileOutputStream.java:297)
at java.io.BufferedOutputStream.write(BufferedOutputStream.java:122)
at java.io.DataOutputStream.write(DataOutputStream.java:107)
at org.openstreetmap.osmosis.pgsnapshot.common.PersistentNodeLocationStore.addLocation(PersistentNodeLocationStore.java:156)
... 7 more
2011-07-12 16:01:13 org.openstreetmap.osmosis.core.pipeline.common.PassiveTaskManager waitForCompletion
FINE: Task 3-write-pgsql is passive, no completion wait required.
2011-07-12 16:01:13 org.openstreetmap.osmosis.core.Osmosis main
SEVERE: Execution aborted.
org.openstreetmap.osmosis.core.OsmosisRuntimeException: One or more tasks failed.
at org.openstreetmap.osmosis.core.pipeline.common.Pipeline.waitForCompletion(Pipeline.java:146)
at org.openstreetmap.osmosis.core.Osmosis.run(Osmosis.java:92)
at org.openstreetmap.osmosis.core.Osmosis.main(Osmosis.java:37)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchStandard(Launcher.java:329)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:239)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)
at org.codehaus.classworlds.Launcher.main(Launcher.java:31)
1. Gratuluję doczytania do tego miejsca.
2. Lojalnie informuję, że terminal nie jest moim najlepszym przyjacielem.
3. Może z moim słabym pojęciem o bazach danych porywam się z motyką na słońce i od razu dać sobie spokój?
4. Może są jakieś inne (prostsze) metody importu OSM do Postgresa a równie łatwo dające się stylizować w QGISie?
5. Czy za pomocą Osm2postgresql da się zaimportować dane do pustej bazy (lub ją utworzyć) na konkretnym serwerze (innym niż localhost) z konkretną nazwą użytkownika i hasłem?
6. Co robię źle w ostatniej metodzie, jak sobie z tym poradzić?
7. Będę wdzięczny za jakiekolwiek rozjaśnienie tematu (poruszam się w nim trochę po omacku).