PostGIS  3.0.6dev-r@@SVN_REVISION@@

◆ LWGEOM_makeline_garray()

Datum LWGEOM_makeline_garray ( PG_FUNCTION_ARGS  )

Definition at line 1390 of file lwgeom_functions_basic.c.

1391 {
1392  ArrayType *array;
1393  int nelems;
1394  GSERIALIZED *result = NULL;
1395  LWGEOM **geoms;
1396  LWGEOM *outlwg;
1397  uint32 ngeoms;
1398  int32_t srid = SRID_UNKNOWN;
1399 
1400  ArrayIterator iterator;
1401  Datum value;
1402  bool isnull;
1403 
1404  POSTGIS_DEBUGF(2, "%s called", __func__);
1405 
1406  /* Return null on null input */
1407  if (PG_ARGISNULL(0))
1408  PG_RETURN_NULL();
1409 
1410  /* Get actual ArrayType */
1411  array = PG_GETARG_ARRAYTYPE_P(0);
1412 
1413  /* Get number of geometries in array */
1414  nelems = ArrayGetNItems(ARR_NDIM(array), ARR_DIMS(array));
1415 
1416  POSTGIS_DEBUGF(3, "%s: array has %d elements", __func__, nelems);
1417 
1418  /* Return null on 0-elements input array */
1419  if (nelems == 0)
1420  PG_RETURN_NULL();
1421 
1422  /*
1423  * Deserialize all point geometries in array into the
1424  * geoms pointers array.
1425  * Count actual number of points.
1426  */
1427 
1428  /* possibly more then required */
1429  geoms = palloc(sizeof(LWGEOM *) * nelems);
1430  ngeoms = 0;
1431 
1432  iterator = array_create_iterator(array, 0, NULL);
1433 
1434  while (array_iterate(iterator, &value, &isnull))
1435  {
1436  GSERIALIZED *geom;
1437 
1438  if (isnull)
1439  continue;
1440 
1441  geom = (GSERIALIZED *)DatumGetPointer(value);
1442 
1443  if (gserialized_get_type(geom) != POINTTYPE && gserialized_get_type(geom) != LINETYPE &&
1445  {
1446  continue;
1447  }
1448 
1449  geoms[ngeoms++] = lwgeom_from_gserialized(geom);
1450 
1451  /* Check SRID homogeneity */
1452  if (ngeoms == 1)
1453  {
1454  /* Get first geometry SRID */
1455  srid = geoms[ngeoms - 1]->srid;
1456  /* TODO: also get ZMflags */
1457  }
1458  else
1459  gserialized_error_if_srid_mismatch_reference(geom, srid, __func__);
1460 
1461  POSTGIS_DEBUGF(3, "%s: element %d deserialized", __func__, ngeoms);
1462  }
1463  array_free_iterator(iterator);
1464 
1465  /* Return null on 0-points input array */
1466  if (ngeoms == 0)
1467  {
1468  /* TODO: should we return LINESTRING EMPTY here ? */
1469  elog(NOTICE, "No points or linestrings in input array");
1470  PG_RETURN_NULL();
1471  }
1472 
1473  POSTGIS_DEBUGF(3, "LWGEOM_makeline_garray: elements: %d", ngeoms);
1474 
1475  outlwg = (LWGEOM *)lwline_from_lwgeom_array(srid, ngeoms, geoms);
1476 
1477  result = geometry_serialize(outlwg);
1478 
1479  PG_RETURN_POINTER(result);
1480 }
void gserialized_error_if_srid_mismatch_reference(const GSERIALIZED *g1, const int32_t srid2, const char *funcname)
Definition: gserialized.c:419
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:117
#define MULTIPOINTTYPE
Definition: liblwgeom.h:119
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:116
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:229
LWLINE * lwline_from_lwgeom_array(int32_t srid, uint32_t ngeoms, LWGEOM **geoms)
Definition: lwline.c:151
int value
Definition: genraster.py:62
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
int32_t srid
Definition: liblwgeom.h:446

References geometry_serialize(), gserialized_error_if_srid_mismatch_reference(), gserialized_get_type(), LINETYPE, lwgeom_from_gserialized(), lwline_from_lwgeom_array(), MULTIPOINTTYPE, POINTTYPE, 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: