PostGIS  3.0.0dev-r@@SVN_REVISION@@

◆ LWGEOM_makeline_garray()

Datum LWGEOM_makeline_garray ( PG_FUNCTION_ARGS  )

Definition at line 1388 of file lwgeom_functions_basic.c.

References error_if_srid_mismatch(), dumpnode::geom, geometry_serialize(), gserialized_get_type(), LINETYPE, lwgeom_from_gserialized(), LWGEOM_makeline(), lwline_from_lwgeom_array(), MULTIPOINTTYPE, PG_FUNCTION_INFO_V1(), POINTTYPE, LWGEOM::srid, SRID_UNKNOWN, and genraster::value.

Referenced by LWGEOM_line_from_mpoint(), pgis_abs_out(), and pgis_geometry_makeline_finalfn().

1389 {
1390  ArrayType *array;
1391  int nelems;
1392  GSERIALIZED *result = NULL;
1393  LWGEOM **geoms;
1394  LWGEOM *outlwg;
1395  uint32 ngeoms;
1396  int srid = SRID_UNKNOWN;
1397 
1398  ArrayIterator iterator;
1399  Datum value;
1400  bool isnull;
1401 
1402  POSTGIS_DEBUGF(2, "%s called", __func__);
1403 
1404  /* Return null on null input */
1405  if ( PG_ARGISNULL(0) )
1406  PG_RETURN_NULL();
1407 
1408  /* Get actual ArrayType */
1409  array = PG_GETARG_ARRAYTYPE_P(0);
1410 
1411  /* Get number of geometries in array */
1412  nelems = ArrayGetNItems(ARR_NDIM(array), ARR_DIMS(array));
1413 
1414  POSTGIS_DEBUGF(3, "%s: array has %d elements", __func__, nelems);
1415 
1416  /* Return null on 0-elements input array */
1417  if ( nelems == 0 )
1418  PG_RETURN_NULL();
1419 
1420 
1421  /*
1422  * Deserialize all point geometries in array into the
1423  * geoms pointers array.
1424  * Count actual number of points.
1425  */
1426 
1427  /* possibly more then required */
1428  geoms = palloc(sizeof(LWGEOM *) * nelems);
1429  ngeoms = 0;
1430 
1431 #if POSTGIS_PGSQL_VERSION >= 95
1432  iterator = array_create_iterator(array, 0, NULL);
1433 #else
1434  iterator = array_create_iterator(array, 0);
1435 #endif
1436 
1437  while( array_iterate(iterator, &value, &isnull) )
1438  {
1439  GSERIALIZED *geom;
1440 
1441  if ( isnull )
1442  continue;
1443 
1444  geom = (GSERIALIZED *)DatumGetPointer(value);
1445 
1446  if ( gserialized_get_type(geom) != POINTTYPE &&
1447  gserialized_get_type(geom) != LINETYPE &&
1449  {
1450  continue;
1451  }
1452 
1453  geoms[ngeoms++] = lwgeom_from_gserialized(geom);
1454 
1455  /* Check SRID homogeneity */
1456  if ( ngeoms == 1 )
1457  {
1458  /* Get first geometry SRID */
1459  srid = geoms[ngeoms-1]->srid;
1460  /* TODO: also get ZMflags */
1461  }
1462  else
1463  {
1464  error_if_srid_mismatch(geoms[ngeoms-1]->srid, srid);
1465  }
1466 
1467  POSTGIS_DEBUGF(3, "%s: element %d deserialized", __func__, ngeoms);
1468  }
1469  array_free_iterator(iterator);
1470 
1471  /* Return null on 0-points input array */
1472  if ( ngeoms == 0 )
1473  {
1474  /* TODO: should we return LINESTRING EMPTY here ? */
1475  elog(NOTICE, "No points or linestrings in input array");
1476  PG_RETURN_NULL();
1477  }
1478 
1479  POSTGIS_DEBUGF(3, "LWGEOM_makeline_garray: elements: %d", ngeoms);
1480 
1481  outlwg = (LWGEOM *)lwline_from_lwgeom_array(srid, ngeoms, geoms);
1482 
1483  result = geometry_serialize(outlwg);
1484 
1485  PG_RETURN_POINTER(result);
1486 }
#define LINETYPE
Definition: liblwgeom.h:85
uint32_t gserialized_get_type(const GSERIALIZED *s)
Extract the geometry type from the serialized form (it hides in the anonymous data area...
Definition: g_serialized.c:86
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
#define MULTIPOINTTYPE
Definition: liblwgeom.h:87
void error_if_srid_mismatch(int srid1, int srid2)
Definition: lwutil.c:336
int32_t srid
Definition: liblwgeom.h:401
LWGEOM * geom
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:187
LWLINE * lwline_from_lwgeom_array(int srid, uint32_t ngeoms, LWGEOM **geoms)
Definition: lwline.c:160
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:84
int value
Definition: genraster.py:61
Here is the call graph for this function:
Here is the caller graph for this function: