Opened 8 years ago

Last modified 8 years ago

#3650 new enhancement

osmosis creates incorrect linestring geometry in simple schema

Reported by: bestoujev@… Owned by: bretth
Priority: major Milestone:
Component: osmosis Version:
Keywords: one node ways Cc:

Description

When a one node way is present in the database and osmosis creates a linestring geometry for it the resulting geometry is something like LINESTRING(139.386972 37.095865)

When we process this linestring with any postgis function it gives us an error - the linestring must contain 0 or > 1 nodes.

When linestring objects are created with internal osmosis functions the number of nodes is checked to be >= 2, but the sql-command does not contain such a check.

I suggest changing the code of WayDao?.java from:

private static final String SQL_UPDATE_WAY_LINESTRING =

"UPDATE ways w SET linestring = (" + " SELECT MakeLine?(c.geom) AS way_line FROM (" + " SELECT n.geom AS geom FROM nodes n INNER JOIN way_nodes wn ON n.id = wn.node_id" + " WHERE (wn.way_id = w.id) ORDER BY wn.sequence_id" + " ) c" + " )" + " WHERE w.id = ?";

to

private static final String SQL_UPDATE_WAY_LINESTRING =

"UPDATE ways w SET linestring = (" + " SELECT MakeLine?(c.geom) AS way_line FROM (" + " SELECT n.geom AS geom FROM nodes n INNER JOIN way_nodes wn ON n.id = wn.node_id" + " WHERE (wn.way_id = w.id) and array_length(nodes, 1) > 1 ORDER BY wn.sequence_id" + " ) c" + " )" + " WHERE w.id = ?";

the "and array_length(nodes, 1) > 1" code will make sure that there are more than 1 node in this way.

I am not a java programmer, so I am not sure that it is the best solution, but this is surely a workaround for the problem . One node ways do not allow to work with the database properly, so this is a very important issue.

Change History (1)

comment:1 Changed 8 years ago by bestoujev@…

The origin of duplicate nodes can be found here: http://trac.openstreetmap.org/ticket/2501

Second problem is also from that poltach bug: ways with two nodes, where both nodes are same. I have not figured yet how to solve it easily...

Note: See TracTickets for help on using tickets.