PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ LWGEOM_makeline_garray()

Datum LWGEOM_makeline_garray ( PG_FUNCTION_ARGS  )

Definition at line 1453 of file lwgeom_functions_basic.c.

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

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: