PostGIS  2.5.0dev-r@@SVN_REVISION@@
Datum LWGEOM_makeline_garray ( PG_FUNCTION_ARGS  )

Definition at line 1386 of file lwgeom_functions_basic.c.

References error_if_srid_mismatch(), dumpnode::geom, geometry_serialize(), 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().

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

Here is the call graph for this function:

Here is the caller graph for this function: