[postgis-users] LineString resulting in empty Polygon geometry in generalization processing
Marco Boeringa
marco at boeringa.demon.nl
Sat Aug 7 08:44:22 PDT 2021
Sorry,
Just after sending the post, I noticed there is actually an errorneous
"ST_CollectionExtract" call with parameter 3 instead of 2 in the code,
which is the likely cause of the error. Setting it to '2' gives back the
LineString.
Marco
Op 7-8-2021 om 17:33 schreef Marco Boeringa:
> Hi all,
>
> When I run the below code (WKT geometry included in the code), the
> original LineString geometry is returned as an empty Polygon geometry
> in the 'way_generalized' column of the created view (this is how
> DBeaver shows it listed in table view, in pgAdmin the Geometry Viewer
> won't show anything).
>
> Is this the expected outcome? I haven't seen this issue popup before,
> and it caused a full stop in my processing of OpenStreetMap Planet
> data, as PostgreSQL / PostGIS errored out with a
>
> "Geometry type (Polygon) does not match column type (LineString)"
>
> type error when the processing flow attempted to insert the geometry
> in the final result table. So PostgreSQL / PostGIS also recognizes it
> as a Polygon geometry.
>
> Now I have seen dimensional collapse before, as in another issue we
> recently discussed here, and some PostGIS functions are documented to
> potentially return a lower dimension geometry, but in this case it is
> recognized as higher dimension one, albeit an "empty" Polygon.
>
> Note that this line hits the date line, it is this object from
> OpenStreetMap:
>
> https://www.openstreetmap.org/way/908501985
>
> Marco
>
> *** CODE: ***
>
> CREATE VIEW test2 AS SELECT way,CASE
> WHEN
> ST_NPoints(ST_Transform(ST_SimplifyVW(ST_Transform(way::geometry(GEOMETRY,
> 4326),
> '+proj=hammer'),
> 400.0),
> '+proj=hammer',
> 4326)) < 2 THEN way::geometry(GEOMETRY,
> 4326)
> ELSE
> CASE
> WHEN
> ST_IsValid(ST_Transform(ST_SimplifyVW(ST_Transform(way::geometry(GEOMETRY,
> 4326),
> '+proj=hammer'),
> 400.0),
> '+proj=hammer',
> 4326)) THEN
> ST_Transform(ST_SimplifyVW(ST_Transform(way::geometry(GEOMETRY,
> 4326),
> '+proj=hammer'),
> 400.0),
> '+proj=hammer',
> 4326)
> ELSE
> CASE
> WHEN ST_IsValid
> (CASE WHEN ST_NPoints
> (CASE WHEN
> ST_IsValid(ST_SimplifyPreserveTopology(ST_Transform(way::geometry(GEOMETRY,
> 4326),
> '+proj=hammer'),
> 30.0)) THEN
> ST_SimplifyPreserveTopology(ST_Transform(way::geometry(GEOMETRY,
> 4326),
> '+proj=hammer'),
> 30.0)
> ELSE ST_Transform(way::geometry(GEOMETRY,
> 4326),
> '+proj=hammer')
> END) >= 3 THEN ST_Transform
> (CASE WHEN
> ST_IsValid(ST_SimplifyPreserveTopology(ST_Transform(way::geometry(GEOMETRY,
> 4326),
> '+proj=hammer'),
> 30.0)) THEN
> ST_SimplifyPreserveTopology(ST_Transform(way::geometry(GEOMETRY,
> 4326),
> '+proj=hammer'),
> 30.0)
> ELSE ST_Transform(way::geometry(GEOMETRY,
> 4326),
> '+proj=hammer')
> END,
> '+proj=hammer',
> 4326)
> ELSE way
> END) THEN CASE WHEN ST_NPoints
> (CASE WHEN
> ST_IsValid(ST_SimplifyPreserveTopology(ST_Transform(way::geometry(GEOMETRY,
> 4326),
> '+proj=hammer'),
> 30.0)) THEN
> ST_SimplifyPreserveTopology(ST_Transform(way::geometry(GEOMETRY,
> 4326),
> '+proj=hammer'),
> 30.0)
> ELSE ST_Transform(way::geometry(GEOMETRY,
> 4326),
> '+proj=hammer')
> END) >= 3 THEN ST_Transform
> (CASE WHEN
> ST_IsValid(ST_SimplifyPreserveTopology(ST_Transform(way::geometry(GEOMETRY,
> 4326),
> '+proj=hammer'),
> 30.0)) THEN
> ST_SimplifyPreserveTopology(ST_Transform(way::geometry(GEOMETRY,
> 4326),
> '+proj=hammer'),
> 30.0)
> ELSE ST_Transform(way::geometry(GEOMETRY,
> 4326),
> '+proj=hammer')
> END,
> '+proj=hammer',
> 4326)
> ELSE way
> END
> ELSE
> CASE
> WHEN
> ST_IsValid(ST_CollectionExtract(ST_MakeValid(ST_SimplifyVW(way,
> 4e-08)),
> 3)) THEN
> ST_CollectionExtract(ST_MakeValid(ST_SimplifyVW(way,
> 4e-08)),
> 3)
> ELSE
> CASE
> WHEN
> ST_IsValid(ST_Transform(ST_SimplifyVW(ST_Transform(way::geometry(GEOMETRY,
> 4326),
> '+proj=hammer'),
> 400.0),
> '+proj=hammer',
> 4326)) THEN
> ST_Transform(ST_SimplifyVW(ST_Transform(way::geometry(GEOMETRY,
> 4326),
> '+proj=hammer'),
> 400.0),
> '+proj=hammer',
> 4326)
> ELSE way::geometry(GEOMETRY,
> 4326)
> END
> END
> END
> END
> END AS way_generalized FROM (SELECT ST_GeomFromText('LINESTRING
> (179.9345326 66.6525225, 179.9349511 66.6521355, 179.9356913
> 66.651081, 179.9361205 66.6506048, 179.9397398 66.6485957, 179.9438882
> 66.6466073, 179.9452185 66.6460885, 179.9465918 66.6458333,
> 179.9489522 66.6456207, 179.9532437 66.6453144, 179.957428 66.6449487,
> 179.9589729 66.644685, 179.9608612 66.6435876, 179.9620628 66.6428049,
> 179.9632934 66.641673, 179.9656462 66.6397847, 179.9662435 66.6393901,
> 179.968813 66.6379373, 179.9728575 66.6373146, 179.9772827 66.6375222,
> 179.980566 66.6383147, 179.9850388 66.6392392, 179.9884647 66.6394656,
> 179.9954119 66.6399939, 179.9987826 66.6403544, 180 66.6405909)',4326)
> AS way) AS foo
>
> _______________________________________________
> postgis-users mailing list
> postgis-users at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/postgis-users
More information about the postgis-users
mailing list