From e32e9c22586e89e4f7115a841cf67ba5c9c19ede Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Rodrigo?= Date: Sun, 16 Jul 2023 14:47:53 +0200 Subject: [PATCH] On enableKeepPartialLinestring, output a closed linestring if the original way is closed even on missing start/end node #133 --- doc/detailed-usage.adoc | 14 ++++++++++---- .../pgsimple/v0_6/impl/WayGeometryBuilder.java | 5 +++++ .../pgsnapshot/v0_6/impl/WayGeometryBuilder.java | 6 ++++++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/doc/detailed-usage.adoc b/doc/detailed-usage.adoc index 43630c636..df2dc94fd 100644 --- a/doc/detailed-usage.adoc +++ b/doc/detailed-usage.adoc @@ -1684,7 +1684,9 @@ the linestring geometry column. |yes, no |no built from option enableLinestringBuilder. When an invalid or a missing node location is encountered the linestring is not built by default. Enabling this option keeps it as a partial linestring. It will result in -a different geometry than the original one. |yes, no |no +a different geometry than the original one. If the original geometry is +a loop the imported geometry is a loop, even in case of faulty start and +end. |yes, no |no |nodeLocationStoreType |This option only takes effect if at least one of the enableBboxBuilder and enableLinestringBuilder options are enabled. @@ -1902,7 +1904,8 @@ is more efficient for smaller datasets. |"InMemory", "TempFile", built. When an invalid or a missing node location is encountered the linestring is not built by default. Enabling this option keeps it as a partial linestring. It will result in a different geometry than the -original one. |yes, no |no +original one. If the original geometry is a loop the imported geometry +is a loop, even in case of faulty start and end. |yes, no |no |======================================================================= ==== --write-pgsimp-dump (--wsd) @@ -1939,7 +1942,9 @@ the linestring geometry column. |yes, no |no built from option enableLinestringBuilder. When an invalid or a missing node location is encountered the linestring is not built by default. Enabling this option keeps it as a partial linestring. It will result in -a different geometry than the original one. |yes, no |no +a different geometry than the original one. If the original geometry is +a loop the imported geometry is a loop, even in case of faulty start and +end. |yes, no |no |nodeLocationStoreType |This option only takes effect if at least one of the enableBboxBuilder and enableLinestringBuilder options are enabled. @@ -1957,7 +1962,8 @@ the default database geometry building implementation, or the built. When an invalid or a missing node location is encountered the linestring is not built by default. Enabling this option keeps it as a partial linestring. It will result in a different geometry than the -original one. |yes, no |no +original one. If the original geometry is a loop the imported geometry +is a loop, even in case of faulty start and end. |yes, no |no |======================================================================= ==== --truncate-pgsimp (--ts) diff --git a/osmosis-pgsimple/src/main/java/org/openstreetmap/osmosis/pgsimple/v0_6/impl/WayGeometryBuilder.java b/osmosis-pgsimple/src/main/java/org/openstreetmap/osmosis/pgsimple/v0_6/impl/WayGeometryBuilder.java index d0099d822..6c01bbf57 100644 --- a/osmosis-pgsimple/src/main/java/org/openstreetmap/osmosis/pgsimple/v0_6/impl/WayGeometryBuilder.java +++ b/osmosis-pgsimple/src/main/java/org/openstreetmap/osmosis/pgsimple/v0_6/impl/WayGeometryBuilder.java @@ -216,6 +216,11 @@ public LineString createWayLinestring(Way way, boolean enableKeepPartialLinestri } } + if (enableKeepPartialLinestring && way.isClosed() && linePoints.size() > 1 + && !linePoints.get(0).equals(linePoints.get(linePoints.size() - 1))) { + linePoints.add(linePoints.get(0)); + } + if (numValidNodes >= 2) { return createLinestring(linePoints); } else { diff --git a/osmosis-pgsnapshot/src/main/java/org/openstreetmap/osmosis/pgsnapshot/v0_6/impl/WayGeometryBuilder.java b/osmosis-pgsnapshot/src/main/java/org/openstreetmap/osmosis/pgsnapshot/v0_6/impl/WayGeometryBuilder.java index 557b8b0ca..fa0576908 100644 --- a/osmosis-pgsnapshot/src/main/java/org/openstreetmap/osmosis/pgsnapshot/v0_6/impl/WayGeometryBuilder.java +++ b/osmosis-pgsnapshot/src/main/java/org/openstreetmap/osmosis/pgsnapshot/v0_6/impl/WayGeometryBuilder.java @@ -213,6 +213,12 @@ public LineString createWayLinestring(Way way, boolean enableKeepPartialLinestri } } } + + if (enableKeepPartialLinestring && way.isClosed() && linePoints.size() > 1 + && !linePoints.get(0).equals(linePoints.get(linePoints.size() - 1))) { + linePoints.add(linePoints.get(0)); + } + return createLinestring(linePoints); }