Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#4020 closed patch (fixed)

Casting BOX3D to geometry invalid

Reported by: mat Owned by: komzpa
Priority: medium Milestone:
Component: postgis Version: 2.4.x
Keywords: Cc:

Description

When casting an actual BOX3D to geometry, the result is invalid. If it has a width of 0 in one ore more dimensions, it is fine. The problem is that the orientations of the top, front and left side of the polyhedral surface are wrong.

Example:

> SELECT ST_AsText('BOX3D(1 2 3,4 5 6)'::BOX3D);
POLYHEDRALSURFACE Z (((1 2 3,1 5 3,4 5 3,4 2 3,1 2 3)),((1 2 6,1 5 6,4 5 6,4 2 6,1 2 6)),((1 2 3,1 5 3,1 5 6,1 2 6,1 2 3)),((4 2 3,4 5 3,4 5 6,4 2 6,4 2 3)),((1 2 3,4 2 3,4 2 6,1 2 6,1 2 3)),((1 5 3,4 5 3,4 5 6,1 5 6,1 5 3)))

-- expected correct result:
POLYHEDRALSURFACE Z (((1 2 3,1 5 3,4 5 3,4 2 3,1 2 3)),((1 2 6,4 2 6,4 5 6,1 5 6,1 2 6)),((1 2 3,1 2 6,1 5 6,1 5 3,1 2 3)),((4 2 3,4 5 3,4 5 6,4 2 6,4 2 3)),((1 2 3,4 2 3,4 2 6,1 2 6,1 2 3)),((1 5 3,1 5 6,4 5 6,4 5 3,1 5 3)))

Notice the switched coordinates for the second (top), third (left) and sixth (front) polygon.

This results e.g. in ST_Volume and ST_3DArea not accepting "true" BOX3Ds:

> SELECT ST_3DArea('BOX3D(1 2 3,1 5 6)'::BOX3D); -- works
9
> SELECT ST_3DArea('BOX3D(1 2 3,4 5 6)'::BOX3D); -- doesn't work
SQL Error [XX000]: ERROR: Solid is invalid : PolyhedralSurface (shell) 0 is invalid: not connected : SOLID((((1/1 2/1 3/1,1/1 5/1 3/1,4/1 5/1 3/1,4/1 2/1 3/1,1/1 2/1 3/1)),((1/1 2/1 6/1,1/1 5/1 6/1,4/1 5/1 6/1,4/1 2/1 6/1,1/1 2/1 6/1)),((1/1 2/1 3/1,1/1 5/1 3/1,1/1 5/1 6/1,1/1 2/1

I think the error is at postgis/lwgeom_box3d.c, lines 325-342.

I'm using:

PostgreSQL 10.1, compiled by Visual C++ build 1800, 64-bit POSTGIS="2.4.3 r16312" PGSQL="100" GEOS="3.6.2-CAPI-1.10.2 4d2925d" SFCGAL="1.3.2" PROJ="Rel. 4.9.3, 15 August 2016" GDAL="GDAL 2.2.3, released 2017/11/20" LIBXML="2.7.8" LIBJSON="0.12" LIBPROTOBUF="1.2.1" RASTER

Change History (5)

comment:2 by komzpa, 7 years ago

Owner: changed from pramsey to komzpa
Type: defectpatch

comment:3 by komzpa, 7 years ago

Resolution: fixed
Status: newclosed

In 16405:

Fix cast from box3d to geometry

Patch by Matthias Bay

Closes https://github.com/postgis/postgis/pull/214
Closes #4020

comment:4 by komzpa, 7 years ago

In 16406:

Fix cast from box3d to geometry

Patch by Matthias Bay

Closes https://github.com/postgis/postgis/pull/214
Closes #4020

comment:5 by komzpa, 7 years ago

In 16407:

Fix cast from box3d to geometry

Patch by Matthias Bay

Closes https://github.com/postgis/postgis/pull/214
Closes #4020

Note: See TracTickets for help on using tickets.