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

Definition at line 1339 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(), POINTTYPE, LWGEOM::srid, SRID_UNKNOWN, and genraster::value.

Referenced by pgis_geometry_makeline_finalfn().

1340 {
1341  ArrayType *array;
1342  int nelems;
1343  GSERIALIZED *result = NULL;
1344  LWGEOM **geoms;
1345  LWGEOM *outlwg;
1346  uint32 ngeoms;
1347  int srid = SRID_UNKNOWN;
1348 
1349  ArrayIterator iterator;
1350  Datum value;
1351  bool isnull;
1352 
1353  POSTGIS_DEBUGF(2, "%s called", __func__);
1354 
1355  /* Return null on null input */
1356  if ( PG_ARGISNULL(0) )
1357  PG_RETURN_NULL();
1358 
1359  /* Get actual ArrayType */
1360  array = PG_GETARG_ARRAYTYPE_P(0);
1361 
1362  /* Get number of geometries in array */
1363  nelems = ArrayGetNItems(ARR_NDIM(array), ARR_DIMS(array));
1364 
1365  POSTGIS_DEBUGF(3, "%s: array has %d elements", __func__, nelems);
1366 
1367  /* Return null on 0-elements input array */
1368  if ( nelems == 0 )
1369  PG_RETURN_NULL();
1370 
1371 
1372  /*
1373  * Deserialize all point geometries in array into the
1374  * geoms pointers array.
1375  * Count actual number of points.
1376  */
1377 
1378  /* possibly more then required */
1379  geoms = palloc(sizeof(LWGEOM *) * nelems);
1380  ngeoms = 0;
1381 
1382 #if POSTGIS_PGSQL_VERSION >= 95
1383  iterator = array_create_iterator(array, 0, NULL);
1384 #else
1385  iterator = array_create_iterator(array, 0);
1386 #endif
1387 
1388  while( array_iterate(iterator, &value, &isnull) )
1389  {
1390  GSERIALIZED *geom;
1391 
1392  if ( isnull )
1393  continue;
1394 
1395  geom = (GSERIALIZED *)DatumGetPointer(value);
1396 
1397  if ( gserialized_get_type(geom) != POINTTYPE &&
1398  gserialized_get_type(geom) != LINETYPE )
1399  {
1400  continue;
1401  }
1402 
1403  geoms[ngeoms++] = lwgeom_from_gserialized(geom);
1404 
1405  /* Check SRID homogeneity */
1406  if ( ngeoms == 1 )
1407  {
1408  /* Get first geometry SRID */
1409  srid = geoms[ngeoms-1]->srid;
1410  /* TODO: also get ZMflags */
1411  }
1412  else
1413  {
1414  error_if_srid_mismatch(geoms[ngeoms-1]->srid, srid);
1415  }
1416 
1417  POSTGIS_DEBUGF(3, "%s: element %d deserialized", __func__, ngeoms);
1418  }
1419  array_free_iterator(iterator);
1420 
1421  /* Return null on 0-points input array */
1422  if ( ngeoms == 0 )
1423  {
1424  /* TODO: should we return LINESTRING EMPTY here ? */
1425  elog(NOTICE, "No points or linestrings in input array");
1426  PG_RETURN_NULL();
1427  }
1428 
1429  POSTGIS_DEBUGF(3, "LWGEOM_makeline_garray: elements: %d", ngeoms);
1430 
1431  outlwg = (LWGEOM *)lwline_from_lwgeom_array(srid, ngeoms, geoms);
1432 
1433  result = geometry_serialize(outlwg);
1434 
1435  PG_RETURN_POINTER(result);
1436 }
#define LINETYPE
Definition: liblwgeom.h:71
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:55
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
void error_if_srid_mismatch(int srid1, int srid2)
Definition: lwutil.c:341
int32_t srid
Definition: liblwgeom.h:383
LWGEOM * geom
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:172
LWLINE * lwline_from_lwgeom_array(int srid, uint32_t ngeoms, LWGEOM **geoms)
Definition: lwline.c:153
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:70

Here is the call graph for this function:

Here is the caller graph for this function: