PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ LWGEOM_makeline_garray()

Datum LWGEOM_makeline_garray ( PG_FUNCTION_ARGS  )

Definition at line 1385 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(), and pgis_geometry_makeline_finalfn().

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