[PostGIS] #5754: ST_ForcePolygonCCW unexpectedly modifies line geometries

PostGIS trac at osgeo.org
Sat Oct 11 12:44:57 PDT 2025


#5754: ST_ForcePolygonCCW unexpectedly modifies line geometries
----------------------+---------------------
  Reporter:  nti      |      Owner:  pramsey
      Type:  defect   |     Status:  new
  Priority:  medium   |  Milestone:
 Component:  postgis  |    Version:  3.4.x
Resolution:           |   Keywords:
----------------------+---------------------
Comment (by endafarrell):

 Hi all.

 I too was affected by this. We had created a "standardizer" for our usage
 of the data as we often create GeoJSON, and we have points, linestrings,
 polygons and multi-variants of all, and so we had this function in our
 app:


 {{{
 CREATE OR REPLACE FUNCTION public.App_AsText(geom geometry)
     RETURNS text
     LANGUAGE 'plpgsql' IMMUTABLE LEAKPROOF PARALLEL SAFE
 AS $BODY$
 BEGIN
     RETURN ST_AsText(ST_ForcePolygonCCW(ST_Force2D(geom)), 6)
 END
 $BODY$;
 }}}


 An example of what happens is this linestring:

 {{{
 LINESTRING(13.2786 52.50159,13.27841 52.50167,13.27812 52.50174,13.27782
 52.50179,13.27747 52.50181,13.27721 52.50164)
 }}}


 is reversed:

 {{{
 spatialindex=> select ST_AsText(st_forcepolygonccw('LINESTRING(13.2786
 52.50159,13.27841 52.50167,13.27812 52.50174,13.27782 52.50179,13.27747
 52.50181,13.27721 52.50164)'));
                                                        st_astext
 ------------------------------------------------------------------------------------------------------------------------
  LINESTRING(13.27721 52.50164,13.27747 52.50181,13.27782 52.50179,13.27812
 52.50174,13.27841 52.50167,13.2786 52.50159)
 (1 row)

 spatialindex=>
 }}}


 We're still on last year's versions:


 {{{
 spatialindex=> select version();
                                                     version
 ----------------------------------------------------------------------------------------------------------------
  PostgreSQL 17.6 on aarch64-unknown-linux-gnu, compiled by gcc (GCC)
 11.5.0 20240719 (Red Hat 11.5.0-5), 64-bit
 (1 row)

 spatialindex=> select postgis_version();
             postgis_version
 ---------------------------------------
  3.5 USE_GEOS=1 USE_PROJ=1 USE_STATS=1
 (1 row)
 }}}
-- 
Ticket URL: <https://trac.osgeo.org/postgis/ticket/5754#comment:1>
PostGIS <http://trac.osgeo.org/postgis/>
The PostGIS Trac is used for bug, enhancement & task tracking, a user and developer wiki, and a view into the subversion code repository of PostGIS project.


More information about the postgis-tickets mailing list