postgis.git / summary / log / commit / refs

commit    bdfcf652a6ea03ea4e8db632ff6841d6ea19d2c7
Author:   Darafei Praliaskouski <me@komzpa.net>
Date:     Tue Jul 07 13:30:49 2026 +0000

    liblwgeom: preserve explicit solid TIN dimension


doc/reference_accessor.xml | 9 +++++---- doc/reference_sfcgal.xml | 22 ++++++++++------------ liblwgeom/cunit/cu_surface.c | 31 +++++++++++++++++++++++++++++++ liblwgeom/lwgeom.c | 4 ++-- 4 files changed, 48 insertions(+), 18 deletions(-) diff --git a/doc/reference_accessor.xml b/doc/reference_accessor.xml index 03c2d88bd..36af0640f 100644 --- a/doc/reference_accessor.xml +++ b/doc/reference_accessor.xml @@ -348,10 +348,11 @@ SELECT ST_X(ST_StartPoint(ST_BoundingDiagonal( <para> <xref linkend="ST_Dimension"/> follows the SQL-MM topological dimension contract. A <varname>TIN</varname>, including a closed TIN surface, - is a surface geometry and has dimension 2. Solid geometry semantics, - such as volume, are handled separately by the SQL/MM 3D solid - functions (SQL-MM IEC 13249-3: 9.1) and by - <xref linkend="CG_MakeSolid"/>. + is a surface geometry and has dimension 2. Use + <xref linkend="CG_MakeSolid"/> to make the solid representation + explicit; the resulting solid has dimension 3. Solid geometry + semantics, such as volume, are handled separately by the SQL/MM 3D + solid functions (SQL-MM IEC 13249-3: 9.1). </para> </note> <para role="enhanced" conformance="2.0.0">Enhanced: 2.0.0 support for Polyhedral surfaces and TINs was introduced. No longer throws an exception if given empty geometry.</para> diff --git a/doc/reference_sfcgal.xml b/doc/reference_sfcgal.xml index 1f4dfe117..7f00975ee 100644 --- a/doc/reference_sfcgal.xml +++ b/doc/reference_sfcgal.xml @@ -319,7 +319,7 @@ <refnamediv> <refname>CG_Volume</refname> - <refpurpose>Computes the volume of a 3D solid. If applied to surface geometries, even closed surfaces, returns 0.</refpurpose> + <refpurpose>Computes the volume of a 3D geometry. Closed surfaces can have non-zero volume.</refpurpose> </refnamediv> <refsynopsisdiv> @@ -340,15 +340,14 @@ <para>&P_support;</para> <para>&T_support;</para> <para>&sqlmm_compliant; SQL-MM IEC 13249-3: 9.1 (same as CG_3DVolume)</para> - <para>Closed surface geometries are still surfaces by default. Use - <xref linkend="CG_MakeSolid"/> to make the solid representation explicit - before computing volume.</para> + <para>Closed surface geometries can have non-zero volume. Use + <xref linkend="CG_MakeSolid"/> when the geometry value itself must carry + the solid flag.</para> </refsection> <refsection> <title>Example</title> - <para>A closed polyhedral surface can be converted to a solid with - <xref linkend="CG_MakeSolid"/> before computing volume.</para> + <para>A closed polyhedral surface has volume. <xref linkend="CG_MakeSolid"/> makes the solid representation explicit.</para> <programlisting>SELECT CG_Volume(geom) As cube_surface_vol, CG_Volume(CG_MakeSolid(geom)) As solid_surface_vol FROM (SELECT 'POLYHEDRALSURFACE( ((0 0 0, 0 0 1, 0 1 1, 0 1 0, 0 0 0)), @@ -597,7 +596,7 @@ <refnamediv> <refname>ST_Volume</refname> - <refpurpose>Computes the volume of a 3D solid. If applied to surface geometries, even closed surfaces, returns 0.</refpurpose> + <refpurpose>Computes the volume of a 3D geometry. Closed surfaces can have non-zero volume.</refpurpose> </refnamediv> <refsynopsisdiv> @@ -624,15 +623,14 @@ <para>&P_support;</para> <para>&T_support;</para> <para>&sqlmm_compliant; SQL-MM IEC 13249-3: 9.1 (same as ST_3DVolume)</para> - <para>Closed surface geometries are still surfaces by default. Use - <xref linkend="ST_MakeSolid"/> to make the solid representation explicit - before computing volume.</para> + <para>Closed surface geometries can have non-zero volume. Use + <xref linkend="ST_MakeSolid"/> when the geometry value itself must carry + the solid flag.</para> </refsection> <refsection> <title>Example</title> - <para>A closed polyhedral surface can be converted to a solid with - <xref linkend="ST_MakeSolid"/> before computing volume.</para> + <para>A closed polyhedral surface has volume. <xref linkend="ST_MakeSolid"/> makes the solid representation explicit.</para> <programlisting>SELECT ST_Volume(geom) As cube_surface_vol, ST_Volume(ST_MakeSolid(geom)) As solid_surface_vol FROM (SELECT 'POLYHEDRALSURFACE( ((0 0 0, 0 0 1, 0 1 1, 0 1 0, 0 0 0)), diff --git a/liblwgeom/cunit/cu_surface.c b/liblwgeom/cunit/cu_surface.c index 985eb63db..57a458fd8 100644 --- a/liblwgeom/cunit/cu_surface.c +++ b/liblwgeom/cunit/cu_surface.c @@ -404,6 +404,29 @@ check_dimension(char *ewkt, int dim) lwgeom_free(geom); } +static void +check_st_dimension(char *ewkt, int dim) +{ + LWGEOM *geom; + + geom = lwgeom_from_wkt(ewkt, LW_PARSER_CHECK_NONE); + CU_ASSERT_EQUAL(strlen(cu_error_msg), 0); + CU_ASSERT_EQUAL(lwgeom_dimension(geom), dim); + lwgeom_free(geom); +} + +static void +check_solid_st_dimension(char *ewkt, int dim) +{ + LWGEOM *geom; + + geom = lwgeom_from_wkt(ewkt, LW_PARSER_CHECK_NONE); + CU_ASSERT_EQUAL(strlen(cu_error_msg), 0); + FLAGS_SET_SOLID(geom->flags, 1); + CU_ASSERT_EQUAL(lwgeom_dimension(geom), dim); + lwgeom_free(geom); +} + void surface_dimension(void) { @@ -418,6 +441,14 @@ surface_dimension(void) /* Tetrahedron */ check_dimension("POLYHEDRALSURFACE(((0 0 0,0 0 1,0 1 0,0 0 0)),((0 0 0,0 1 0,1 0 0,0 0 0)),((0 0 0,1 0 0,0 0 1,0 0 0)),((1 0 0,0 1 0,0 0 1,1 0 0)))", 3); check_dimension("TIN(((0 0 0,0 0 1,0 1 0,0 0 0)),((0 0 0,0 1 0,1 0 0,0 0 0)),((0 0 0,1 0 0,0 0 1,0 0 0)),((1 0 0,0 1 0,0 0 1,1 0 0)))", 3); + + /* ST_Dimension follows surface/solid type semantics. */ + check_st_dimension( + "TIN(((0 0 0,0 0 1,0 1 0,0 0 0)),((0 0 0,0 1 0,1 0 0,0 0 0)),((0 0 0,1 0 0,0 0 1,0 0 0)),((1 0 0,0 1 0,0 0 1,1 0 0)))", + 2); + check_solid_st_dimension( + "TIN(((0 0 0,0 0 1,0 1 0,0 0 0)),((0 0 0,0 1 0,1 0 0,0 0 0)),((0 0 0,1 0 0,0 0 1,0 0 0)),((1 0 0,0 1 0,0 0 1,1 0 0)))", + 3); } diff --git a/liblwgeom/lwgeom.c b/liblwgeom/lwgeom.c index 4d547c494..9d461c730 100644 --- a/liblwgeom/lwgeom.c +++ b/liblwgeom/lwgeom.c @@ -1636,8 +1636,8 @@ int lwgeom_dimension(const LWGEOM *geom) case MULTIPOLYGONTYPE: return 2; case TINTYPE: - /* A closed TIN surface is not a solid unless cast with MakeSolid. */ - return 2; + /* A TIN surface is dimension 2 unless it carries an explicit solid flag. */ + return FLAGS_GET_SOLID(geom->flags) ? 3 : 2; case POLYHEDRALSURFACETYPE: { /* A closed polyhedral surface contains a volume. */ [parent: 3b1b7f262663]