523 ArrayType *arr_geoms = NULL;
524 ArrayType *arr_ids = NULL;
525 int num_geoms, num_ids, i = 0;
527 ArrayIterator iter_geoms, iter_ids;
528 bool null_geom, null_id;
529 Datum val_geom, val_id;
531 int is_homogeneous =
true;
536 int64_t *idlist = NULL;
545 if ( PG_NARGS() < 2 || PG_ARGISNULL(0) || PG_ARGISNULL(1) )
548 arr_geoms = PG_GETARG_ARRAYTYPE_P(0);
549 arr_ids = PG_GETARG_ARRAYTYPE_P(1);
551 num_geoms = ArrayGetNItems(ARR_NDIM(arr_geoms), ARR_DIMS(arr_geoms));
552 num_ids = ArrayGetNItems(ARR_NDIM(arr_ids), ARR_DIMS(arr_ids));
554 if ( num_geoms != num_ids )
556 elog(ERROR,
"size of geometry[] and integer[] arrays must match");
563 #if POSTGIS_PGSQL_VERSION >= 95 564 iter_geoms = array_create_iterator(arr_geoms, 0, NULL);
565 iter_ids = array_create_iterator(arr_ids, 0, NULL);
567 iter_geoms = array_create_iterator(arr_geoms, 0);
568 iter_ids = array_create_iterator(arr_ids, 0);
571 while( array_iterate(iter_geoms, &val_geom, &null_geom) &&
572 array_iterate(iter_ids, &val_id, &null_id) )
577 if ( null_geom || null_id )
579 elog(NOTICE,
"ST_AsTWKB skipping NULL entry at position %d", i);
584 uid = DatumGetInt64(val_id);
594 idlist = palloc0(num_geoms *
sizeof(int64_t));
600 elog(ERROR,
"Geometries have differenct dimensionality");
601 PG_FREE_IF_COPY(arr_geoms, 0);
602 PG_FREE_IF_COPY(arr_ids, 1);
613 is_homogeneous =
false;
621 array_free_iterator(iter_geoms);
622 array_free_iterator(iter_ids);
626 elog(NOTICE,
"No valid geometry - id pairs found");
627 PG_FREE_IF_COPY(arr_geoms, 0);
628 PG_FREE_IF_COPY(arr_ids, 1);
631 if ( is_homogeneous )
640 if ( PG_NARGS() > 2 && ! PG_ARGISNULL(2) )
641 sp.precision_xy = PG_GETARG_INT32(2);
644 if ( PG_NARGS() > 3 && ! PG_ARGISNULL(3) )
645 sp.precision_z = PG_GETARG_INT32(3);
648 if ( PG_NARGS() > 4 && ! PG_ARGISNULL(4) )
649 sp.precision_m = PG_GETARG_INT32(4);
655 if ( PG_NARGS() > 5 && ! PG_ARGISNULL(5) && PG_GETARG_BOOL(5) )
659 if ( PG_NARGS() > 6 && ! PG_ARGISNULL(6) && PG_GETARG_BOOL(6) )
665 sp.precision_xy, sp.precision_z, sp.precision_m,
669 result = palloc(twkb_size + VARHDRSZ);
670 memcpy(VARDATA(result), twkb, twkb_size);
671 SET_VARSIZE(result, twkb_size + VARHDRSZ);
677 PG_FREE_IF_COPY(arr_geoms, 0);
678 PG_FREE_IF_COPY(arr_ids, 1);
680 PG_RETURN_BYTEA_P(result);
int lwtype_get_collectiontype(uint8_t type)
Given an lwtype number, what homogeneous collection can hold it?
uint8_t * lwgeom_to_twkb_with_idlist(const LWGEOM *geom, int64_t *idlist, uint8_t variant, int8_t precision_xy, int8_t precision_z, int8_t precision_m, size_t *twkb_size)
Convert LWGEOM to a char* in TWKB format.
LWGEOM * lwgeom_from_gserialized(const GSERIALIZED *g)
Allocate a new LWGEOM from a GSERIALIZED.
uint32_t lwgeom_get_type(const LWGEOM *geom)
Return LWTYPE number.
int32_t lwgeom_get_srid(const LWGEOM *geom)
Return SRID number.
int lwgeom_has_z(const LWGEOM *geom)
Return LW_TRUE if geometry has Z ordinates.
#define TWKB_DEFAULT_PRECISION
void lwcollection_free(LWCOLLECTION *col)
LWCOLLECTION * lwcollection_construct_empty(uint8_t type, int srid, char hasz, char hasm)
int lwgeom_has_m(const LWGEOM *geom)
Return LW_TRUE if geometry has M ordinates.
LWCOLLECTION * lwcollection_add_lwgeom(LWCOLLECTION *col, const LWGEOM *geom)
Appends geom to the collection managed by col.
LWGEOM * lwcollection_as_lwgeom(const LWCOLLECTION *obj)