PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ LWGEOM_makeline_garray()

Datum LWGEOM_makeline_garray ( PG_FUNCTION_ARGS  )

Definition at line 1417 of file lwgeom_functions_basic.c.

1418{
1419 ArrayType *array;
1420 int nelems;
1421 GSERIALIZED *result = NULL;
1422 LWGEOM **geoms;
1423 LWGEOM *outlwg;
1424 uint32 ngeoms;
1425 int32_t srid = SRID_UNKNOWN;
1426
1427 ArrayIterator iterator;
1428 Datum value;
1429 bool isnull;
1430
1431 POSTGIS_DEBUGF(2, "%s called", __func__);
1432
1433 /* Return null on null input */
1434 if (PG_ARGISNULL(0))
1435 PG_RETURN_NULL();
1436
1437 /* Get actual ArrayType */
1438 array = PG_GETARG_ARRAYTYPE_P(0);
1439
1440 /* Get number of geometries in array */
1441 nelems = ArrayGetNItems(ARR_NDIM(array), ARR_DIMS(array));
1442
1443 POSTGIS_DEBUGF(3, "%s: array has %d elements", __func__, nelems);
1444
1445 /* Return null on 0-elements input array */
1446 if (nelems == 0)
1447 PG_RETURN_NULL();
1448
1449 /*
1450 * Deserialize all point geometries in array into the
1451 * geoms pointers array.
1452 * Count actual number of points.
1453 */
1454
1455 /* possibly more then required */
1456 geoms = palloc(sizeof(LWGEOM *) * nelems);
1457 ngeoms = 0;
1458
1459 iterator = array_create_iterator(array, 0, NULL);
1460
1461 while (array_iterate(iterator, &value, &isnull))
1462 {
1463 GSERIALIZED *geom;
1464
1465 if (isnull)
1466 continue;
1467
1468 geom = (GSERIALIZED *)DatumGetPointer(value);
1469
1470 if (gserialized_get_type(geom) != POINTTYPE &&
1472 gserialized_get_type(geom) != LINETYPE &&
1474 {
1475 continue;
1476 }
1477
1478 geoms[ngeoms++] = lwgeom_from_gserialized(geom);
1479
1480 /* Check SRID homogeneity */
1481 if (ngeoms == 1)
1482 {
1483 /* Get first geometry SRID */
1484 srid = geoms[ngeoms - 1]->srid;
1485 /* TODO: also get ZMflags */
1486 }
1487 else
1489
1490 POSTGIS_DEBUGF(3, "%s: element %d deserialized", __func__, ngeoms);
1491 }
1492 array_free_iterator(iterator);
1493
1494 /* Return null on 0-points input array */
1495 if (ngeoms == 0)
1496 {
1497 /* TODO: should we return LINESTRING EMPTY here ? */
1498 elog(NOTICE, "No points or linestrings in input array");
1499 PG_RETURN_NULL();
1500 }
1501
1502 POSTGIS_DEBUGF(3, "LWGEOM_makeline_garray: elements: %d", ngeoms);
1503
1504 outlwg = (LWGEOM *)lwline_from_lwgeom_array(srid, ngeoms, geoms);
1505
1506 result = geometry_serialize(outlwg);
1507
1508 PG_RETURN_POINTER(result);
1509}
char result[OUT_DOUBLE_BUFFER_SIZE]
Definition cu_print.c:267
void gserialized_error_if_srid_mismatch_reference(const GSERIALIZED *g1, const int32_t srid2, const char *funcname)
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
uint32_t gserialized_get_type(const GSERIALIZED *g)
Extract the geometry type from the serialized form (it hides in the anonymous data area,...
LWLINE * lwline_from_lwgeom_array(int32_t srid, uint32_t ngeoms, LWGEOM **geoms)
Definition lwline.c:151
#define MULTILINETYPE
Definition liblwgeom.h:106
#define LINETYPE
Definition liblwgeom.h:103
#define MULTIPOINTTYPE
Definition liblwgeom.h:105
#define POINTTYPE
LWTYPE numbers, used internally by PostGIS.
Definition liblwgeom.h:102
#define SRID_UNKNOWN
Unknown SRID value.
Definition liblwgeom.h:215
int value
Definition genraster.py:62
int32_t srid
Definition liblwgeom.h:460

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

Referenced by pgis_geometry_makeline_finalfn().

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