PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ LWGEOM_makeline_garray()

Datum LWGEOM_makeline_garray ( PG_FUNCTION_ARGS  )

Definition at line 1389 of file lwgeom_functions_basic.c.

1390 {
1391  ArrayType *array;
1392  int nelems;
1393  GSERIALIZED *result = NULL;
1394  LWGEOM **geoms;
1395  LWGEOM *outlwg;
1396  uint32 ngeoms;
1397  int srid = SRID_UNKNOWN;
1398 
1399  ArrayIterator iterator;
1400  Datum value;
1401  bool isnull;
1402 
1403  POSTGIS_DEBUGF(2, "%s called", __func__);
1404 
1405  /* Return null on null input */
1406  if ( PG_ARGISNULL(0) )
1407  PG_RETURN_NULL();
1408 
1409  /* Get actual ArrayType */
1410  array = PG_GETARG_ARRAYTYPE_P(0);
1411 
1412  /* Get number of geometries in array */
1413  nelems = ArrayGetNItems(ARR_NDIM(array), ARR_DIMS(array));
1414 
1415  POSTGIS_DEBUGF(3, "%s: array has %d elements", __func__, nelems);
1416 
1417  /* Return null on 0-elements input array */
1418  if ( nelems == 0 )
1419  PG_RETURN_NULL();
1420 
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 #if POSTGIS_PGSQL_VERSION >= 95
1433  iterator = array_create_iterator(array, 0, NULL);
1434 #else
1435  iterator = array_create_iterator(array, 0);
1436 #endif
1437 
1438  while( array_iterate(iterator, &value, &isnull) )
1439  {
1440  GSERIALIZED *geom;
1441 
1442  if ( isnull )
1443  continue;
1444 
1445  geom = (GSERIALIZED *)DatumGetPointer(value);
1446 
1447  if ( gserialized_get_type(geom) != POINTTYPE &&
1448  gserialized_get_type(geom) != LINETYPE &&
1450  {
1451  continue;
1452  }
1453 
1454  geoms[ngeoms++] = lwgeom_from_gserialized(geom);
1455 
1456  /* Check SRID homogeneity */
1457  if ( ngeoms == 1 )
1458  {
1459  /* Get first geometry SRID */
1460  srid = geoms[ngeoms-1]->srid;
1461  /* TODO: also get ZMflags */
1462  }
1463  else
1464  {
1465  error_if_srid_mismatch(geoms[ngeoms-1]->srid, srid);
1466  }
1467 
1468  POSTGIS_DEBUGF(3, "%s: element %d deserialized", __func__, ngeoms);
1469  }
1470  array_free_iterator(iterator);
1471 
1472  /* Return null on 0-points input array */
1473  if ( ngeoms == 0 )
1474  {
1475  /* TODO: should we return LINESTRING EMPTY here ? */
1476  elog(NOTICE, "No points or linestrings in input array");
1477  PG_RETURN_NULL();
1478  }
1479 
1480  POSTGIS_DEBUGF(3, "LWGEOM_makeline_garray: elements: %d", ngeoms);
1481 
1482  outlwg = (LWGEOM *)lwline_from_lwgeom_array(srid, ngeoms, geoms);
1483 
1484  result = geometry_serialize(outlwg);
1485 
1486  PG_RETURN_POINTER(result);
1487 }
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
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
#define LINETYPE
Definition: liblwgeom.h:86
#define MULTIPOINTTYPE
Definition: liblwgeom.h:88
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:85
void error_if_srid_mismatch(int srid1, int srid2)
Definition: lwutil.c:338
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:188
LWLINE * lwline_from_lwgeom_array(int srid, uint32_t ngeoms, LWGEOM **geoms)
Definition: lwline.c:160
int value
Definition: genraster.py:61
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
int32_t srid
Definition: liblwgeom.h:402

References error_if_srid_mismatch(), 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().

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