waymarkedtrails / waymarkedtrails-backend

Database backend and rendering styles for waymarkedtrails website.
GNU General Public License v3.0
15 stars 6 forks source link

ERROR: Geometry type (GeometryCollection) does not match column type (LineString) #11

Open TommasoDb opened 1 year ago

TommasoDb commented 1 year ago

Command wmt-makedb cycling import does not work because of the error Geometry type (GeometryCollection) does not match column type (LineString).

I would like to share the test data but the size of the file is 5GB. Can I upload it somewhere?

Whole error message:

23-08-15 09:17:05 Importing changed_objects...
23-08-15 09:17:05 Importing filtered_relations...
23-08-15 09:17:14 Importing way_relations...
23-08-15 09:17:15 Using 1 parallel threads.
23-08-15 09:50:47 Importing segments...
23-08-15 09:51:02 Using 1 parallel threads.
Exception in thread Thread-2 (worker_loop):
Traceback (most recent call last):
  File "/home/dibucchianico/.local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1905, in _execute_context
    self.dialect.do_execute(
  File "/home/dibucchianico/.local/lib/python3.10/site-packages/sqlalchemy/engine/default.py", line 736, in do_execute
    cursor.execute(statement, parameters)
psycopg2.errors.InvalidParameterValue: FEHLER:  Geometry type (GeometryCollection) does not match column type (LineString)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.10/threading.py", line 953, in run
    self._target(*self._args, **self._kwargs)
  File "/home/dibucchianico/.local/lib/python3.10/site-packages/osgende/common/threads.py", line 53, in worker_loop
    process_func(req)
  File "/home/dibucchianico/.local/lib/python3.10/site-packages/osgende/lines/segments.py", line 368, in _process_next
    self._write_segment(properties, w)
  File "/home/dibucchianico/.local/lib/python3.10/site-packages/osgende/lines/segments.py", line 375, in _write_segment
    self.thread.conn.execute(self.src.data.insert(fields))
  File "/home/dibucchianico/.local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1385, in execute
    return meth(self, multiparams, params, _EMPTY_EXECUTION_OPTS)
  File "/home/dibucchianico/.local/lib/python3.10/site-packages/sqlalchemy/sql/elements.py", line 334, in _execute_on_connection
    return connection._execute_clauseelement(
  File "/home/dibucchianico/.local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1577, in _execute_clauseelement
    ret = self._execute_context(
  File "/home/dibucchianico/.local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1948, in _execute_context
    self._handle_dbapi_exception(
  File "/home/dibucchianico/.local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 2129, in _handle_dbapi_exception
    util.raise_(
  File "/home/dibucchianico/.local/lib/python3.10/site-packages/sqlalchemy/util/compat.py", line 211, in raise_
    raise exception
  File "/home/dibucchianico/.local/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 1905, in _execute_context
    self.dialect.do_execute(
  File "/home/dibucchianico/.local/lib/python3.10/site-packages/sqlalchemy/engine/default.py", line 736, in do_execute
    cursor.execute(statement, parameters)
sqlalchemy.exc.DataError: (psycopg2.errors.InvalidParameterValue) FEHLER:  Geometry type (GeometryCollection) does not match column type (LineString)

[SQL: INSERT INTO cycling.segments (rels, nodes, ways, geom) VALUES (%(rels)s::BIGINT[], %(nodes)s::BIGINT[], %(ways)s::BIGINT[], ST_GeomFromEWKT(%(geom)s)) RETURNING cycling.segments.id]
[parameters: {'rels': [176651], 'nodes': [1425940282, 331360441, 6464375366, 331360445, 331360449, 331360450, 331360451, 331360452, 331360453, 331360454, 331360455, 331360456, 331360457, 3313 ... (445 characters truncated) ... , 331360535, 331360536, 6464375586, 331360538, 331360541, 331360542, 331360544, 9042917012, 6464552338, 331360546, 7682663100, 6464552337, 7682663105], 'ways': [30084469], 'geom': 'SRID=3857;GEOMETRYCOLLECTION EMPTY'}]
(Background on this error at: https://sqlalche.me/e/14/9h9h)
23-08-15 09:51:48 Internal error. Thread died. Killing other threads.
Traceback (most recent call last):
  File "/home/dibucchianico/.local/lib/python3.10/site-packages/osgende/common/threads.py", line 71, in add_task
    self.queue.put(data, True, 2)
  File "/usr/lib/python3.10/queue.py", line 148, in put
    raise Full
queue.Full

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/dibucchianico/.local/bin/wmt-makedb", line 248, in <module>
    exit(action())
  File "/home/dibucchianico/.local/bin/wmt-makedb", line 125, in construct
    self.mapdb.construct()
  File "/home/dibucchianico/.local/lib/python3.10/site-packages/osgende/mapdb.py", line 127, in construct
    tab.construct(self.engine)
  File "/home/dibucchianico/.local/lib/python3.10/site-packages/osgende/lines/segments.py", line 114, in construct
    wayproc.process_ways(prev_prop, wayset)
  File "/home/dibucchianico/.local/lib/python3.10/site-packages/osgende/lines/segments.py", line 281, in process_ways
    self.workers.add_task((properties, ways))
  File "/home/dibucchianico/.local/lib/python3.10/site-packages/osgende/common/threads.py", line 143, in add_task
    self.worker.add_task(data)
  File "/home/dibucchianico/.local/lib/python3.10/site-packages/osgende/common/threads.py", line 74, in add_task
    self.check_worker_state()
  File "/home/dibucchianico/.local/lib/python3.10/site-packages/osgende/common/threads.py", line 85, in check_worker_state
    raise WorkerError("Internal error. Thread died.")
osgende.common.threads.WorkerError: Internal error. Thread died.
lonvia commented 1 year ago

Please reduce your data to the problematic case. The error already tells you that relation 176651 is the problematic one. Extract it from your data file using osmium-tool. Then rerun the import and check that the error is still there.

TommasoDb commented 1 year ago

I created a new osm file with osmium only containing the relation 176651. The import works well in this case. Data: germany_relation_176651.zip

Hint: the file I'm trying to import has been generated by osmconverter by clipping the file europe-latest.osm.pbf with this poly file: germany_buffer_30km.zip.

I used this command: osmconvert europe-latest.osm.pbf -B=germany_buffer_30km.poly -o=germany_buffer_30km.pbf

lonvia commented 1 year ago

I already suspected that it has something to do with clipped data but I really need a test case to provide a fix. Smaller than planet imports are simply not a use case for me.

You could also try and cut the extract with osmium instead of osmconvert. Maybe it creates more consistent data.