PostGIS  3.3.9dev-r@@SVN_REVISION@@

◆ LWGEOM_makeline_garray()

Datum LWGEOM_makeline_garray ( PG_FUNCTION_ARGS  )

Definition at line 1450 of file lwgeom_functions_basic.c.

1451 {
1452  ArrayType *array;
1453  int nelems;
1454  GSERIALIZED *result = NULL;
1455  LWGEOM **geoms;
1456  LWGEOM *outlwg;
1457  uint32 ngeoms;
1458  int32_t srid = SRID_UNKNOWN;
1459 
1460  ArrayIterator iterator;
1461  Datum value;
1462  bool isnull;
1463 
1464  POSTGIS_DEBUGF(2, "%s called", __func__);
1465 
1466  /* Return null on null input */
1467  if (PG_ARGISNULL(0))
1468  PG_RETURN_NULL();
1469 
1470  /* Get actual ArrayType */
1471  array = PG_GETARG_ARRAYTYPE_P(0);
1472 
1473  /* Get number of geometries in array */
1474  nelems = ArrayGetNItems(ARR_NDIM(array), ARR_DIMS(array));
1475 
1476  POSTGIS_DEBUGF(3, "%s: array has %d elements", __func__, nelems);
1477 
1478  /* Return null on 0-elements input array */
1479  if (nelems == 0)
1480  PG_RETURN_NULL();
1481 
1482  /*
1483  * Deserialize all point geometries in array into the
1484  * geoms pointers array.
1485  * Count actual number of points.
1486  */
1487 
1488  /* possibly more then required */
1489  geoms = palloc(sizeof(LWGEOM *) * nelems);
1490  ngeoms = 0;
1491 
1492  iterator = array_create_iterator(array, 0, NULL);
1493 
1494  while (array_iterate(iterator, &value, &isnull))
1495  {
1496  GSERIALIZED *geom;
1497 
1498  if (isnull)
1499  continue;
1500 
1501  geom = (GSERIALIZED *)DatumGetPointer(value);
1502 
1503  if (gserialized_get_type(geom) != POINTTYPE && gserialized_get_type(geom) != LINETYPE &&
1505  {
1506  continue;
1507  }
1508 
1509  geoms[ngeoms++] = lwgeom_from_gserialized(geom);
1510 
1511  /* Check SRID homogeneity */
1512  if (ngeoms == 1)
1513  {
1514  /* Get first geometry SRID */
1515  srid = geoms[ngeoms - 1]->srid;
1516  /* TODO: also get ZMflags */
1517  }
1518  else
1519  gserialized_error_if_srid_mismatch_reference(geom, srid, __func__);
1520 
1521  POSTGIS_DEBUGF(3, "%s: element %d deserialized", __func__, ngeoms);
1522  }
1523  array_free_iterator(iterator);
1524 
1525  /* Return null on 0-points input array */
1526  if (ngeoms == 0)
1527  {
1528  /* TODO: should we return LINESTRING EMPTY here ? */
1529  elog(NOTICE, "No points or linestrings in input array");
1530  PG_RETURN_NULL();
1531  }
1532 
1533  POSTGIS_DEBUGF(3, "LWGEOM_makeline_garray: elements: %d", ngeoms);
1534 
1535  outlwg = (LWGEOM *)lwline_from_lwgeom_array(srid, ngeoms, geoms);
1536 
1537  result = geometry_serialize(outlwg);
1538 
1539  PG_RETURN_POINTER(result);
1540 }
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition: cu_print.c:267
void gserialized_error_if_srid_mismatch_reference(const GSERIALIZED *g1, const int32_t srid2, const char *funcname)
Definition: gserialized.c:418
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
Definition: gserialized.c:239
uint32_t gserialized_get_type(const GSERIALIZED *g)
Extract the geometry type from the serialized form (it hides in the anonymous data area,...
Definition: gserialized.c:89
#define LINETYPE
Definition: liblwgeom.h:118
#define MULTIPOINTTYPE
Definition: liblwgeom.h:120
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:117
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:230
LWLINE * lwline_from_lwgeom_array(int32_t srid, uint32_t ngeoms, LWGEOM **geoms)
Definition: lwline.c:151
int value
Definition: genraster.py:62
int32_t srid
Definition: liblwgeom.h:475

References gserialized_error_if_srid_mismatch_reference(), gserialized_get_type(), LINETYPE, lwgeom_from_gserialized(), lwline_from_lwgeom_array(), MULTIPOINTTYPE, POINTTYPE, result, LWGEOM::srid, SRID_UNKNOWN, and genraster::value.

Referenced by pgis_geometry_makeline_finalfn().

Here is the call graph for this function:
Here is the caller graph for this function: