[postgis-tickets] [PostGIS] #5036: PostGIS 3.2.0: ST_StartPoint with empty geometries

PostGIS trac at osgeo.org
Sun Dec 26 12:53:32 PST 2021


#5036: PostGIS 3.2.0: ST_StartPoint with empty geometries
----------------------+---------------------------
 Reporter:  ezimanyi  |      Owner:  pramsey
     Type:  defect    |     Status:  new
 Priority:  medium    |  Milestone:  PostGIS 3.1.5
Component:  postgis   |    Version:  2.5.x
 Keywords:            |
----------------------+---------------------------
 While performing the regression tests for MobilityDB with the latest
 version PostGIS 3.2.0 we found out that maybe the function
 `LWGEOM_startpoint_linestring` should test whether the argument is empty.
 Although the function correctly outputs a NULL value for empty geometries,
 it throws an error message as follows


 {{{
 test=# select ST_StartPoint(geometry 'linestring empty');
 NOTICE:  lwgeom_api.c [138] called with n=0 and npoints=0
  st_startpoint
 ---------------

 (1 row)

 }}}

 It may be useful to test whether the input geometry is empty before
 calling `lwgeom_from_gserialized` as suggested below.


 {{{
 Datum LWGEOM_startpoint_linestring(PG_FUNCTION_ARGS)
 {
   GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
   /* BEGIN NEW TEST */
   if (gserialized_is_empty(geom))
   {
     PG_RETURN_NULL();
   }
   /* END NEW TEST */

   GSERIALIZED *ret;
   LWGEOM *lwgeom = lwgeom_from_gserialized(geom);
   LWGEOM *lwpoint = NULL;
   POINT4D pt;

   if (lwgeom_startpoint(lwgeom, &pt) == LW_FAILURE)
   {
     PG_RETURN_NULL();
   }
   [...]
 }

 }}}

-- 
Ticket URL: <https://trac.osgeo.org/postgis/ticket/5036>
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