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

Definition at line 1391 of file lwgeom_functions_basic.c.

References geometry_serialize(), gserialized_get_type(), LINETYPE, lwgeom_from_gserialized(), lwline_from_lwgeom_array(), POINTTYPE, result, LWGEOM::srid, and SRID_UNKNOWN.

Referenced by pgis_geometry_makeline_finalfn().

1392 {
1393  Datum datum;
1394  ArrayType *array;
1395  int nelems;
1396  GSERIALIZED *result=NULL;
1397  LWGEOM **geoms;
1398  LWGEOM *outlwg;
1399  uint32 ngeoms;
1400  int i;
1401  size_t offset;
1402  int srid=SRID_UNKNOWN;
1403 
1404  bits8 *bitmap;
1405  int bitmask;
1406 
1407  POSTGIS_DEBUG(2, "LWGEOM_makeline_garray called.");
1408 
1409  /* Get input datum */
1410  datum = PG_GETARG_DATUM(0);
1411 
1412  /* Return null on null input */
1413  if ( (Pointer *)datum == NULL )
1414  {
1415  elog(NOTICE, "NULL input");
1416  PG_RETURN_NULL();
1417  }
1418 
1419  /* Get actual ArrayType */
1420  array = DatumGetArrayTypeP(datum);
1421 
1422  POSTGIS_DEBUG(3, "LWGEOM_makeline_garray: array detoasted");
1423 
1424  /* Get number of geometries in array */
1425  nelems = ArrayGetNItems(ARR_NDIM(array), ARR_DIMS(array));
1426 
1427  POSTGIS_DEBUGF(3, "LWGEOM_makeline_garray: array has %d elements", nelems);
1428 
1429  /* Return null on 0-elements input array */
1430  if ( nelems == 0 )
1431  {
1432  elog(NOTICE, "0 elements input array");
1433  PG_RETURN_NULL();
1434  }
1435 
1436  /*
1437  * Deserialize all point geometries in array into the
1438  * geoms pointers array.
1439  * Count actual number of points.
1440  */
1441 
1442  /* possibly more then required */
1443  geoms = palloc(sizeof(LWGEOM *)*nelems);
1444  ngeoms = 0;
1445  offset = 0;
1446  bitmap = ARR_NULLBITMAP(array);
1447  bitmask = 1;
1448  for (i=0; i<nelems; i++)
1449  {
1450  /* Don't do anything for NULL values */
1451  if ((bitmap && (*bitmap & bitmask) != 0) || !bitmap)
1452  {
1453  GSERIALIZED *geom = (GSERIALIZED *)(ARR_DATA_PTR(array)+offset);
1454  offset += INTALIGN(VARSIZE(geom));
1455 
1456  if ( gserialized_get_type(geom) != POINTTYPE && gserialized_get_type(geom) != LINETYPE ) continue;
1457 
1458  geoms[ngeoms++] =
1460 
1461  /* Check SRID homogeneity */
1462  if ( ngeoms == 1 )
1463  {
1464  /* Get first geometry SRID */
1465  srid = geoms[ngeoms-1]->srid;
1466  /* TODO: also get ZMflags */
1467  }
1468  else
1469  {
1470  if ( geoms[ngeoms-1]->srid != srid )
1471  {
1472  elog(ERROR,
1473  "Operation on mixed SRID geometries");
1474  PG_RETURN_NULL();
1475  }
1476  }
1477 
1478  POSTGIS_DEBUGF(3, "LWGEOM_makeline_garray: element %d deserialized", i);
1479  }
1480 
1481  /* Advance NULL bitmap */
1482  if (bitmap)
1483  {
1484  bitmask <<= 1;
1485  if (bitmask == 0x100)
1486  {
1487  bitmap++;
1488  bitmask = 1;
1489  }
1490  }
1491  }
1492 
1493  /* Return null on 0-points input array */
1494  if ( ngeoms == 0 )
1495  {
1496  /* TODO: should we return LINESTRING EMPTY here ? */
1497  elog(NOTICE, "No points or linestrings in input array");
1498  PG_RETURN_NULL();
1499  }
1500 
1501  POSTGIS_DEBUGF(3, "LWGEOM_makeline_garray: elements: %d", ngeoms);
1502 
1503  outlwg = (LWGEOM *)lwline_from_lwgeom_array(srid, ngeoms, geoms);
1504 
1505  result = geometry_serialize(outlwg);
1506 
1507  PG_RETURN_POINTER(result);
1508 }
#define LINETYPE
Definition: liblwgeom.h:61
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:56
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
char ** result
Definition: liblwgeom.h:218
int32_t srid
Definition: liblwgeom.h:355
unsigned int uint32
Definition: shpopen.c:274
#define SRID_UNKNOWN
Unknown SRID value.
Definition: liblwgeom.h:154
LWLINE * lwline_from_lwgeom_array(int srid, uint32_t ngeoms, LWGEOM **geoms)
Definition: lwline.c:152
GSERIALIZED * geometry_serialize(LWGEOM *lwgeom)
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition: liblwgeom.h:60

Here is the call graph for this function:

Here is the caller graph for this function: