So far the code is like this(In addition to the input and output functions):
struct trajectory_elem
{
int32 id;
Timestamp time_obj;
GSERIALIZED *geom_elem; /* Geometry Object */
};
PG_FUNCTION_INFO_V1(trajectory_elem);
Datum
trajectory_elem(PG_FUNCTION_ARGS)
{
int32 id = PG_GETARG_INT32(0);
Timestamp timestamp = PG_GETARG_TIMESTAMP(1);
GSERIALIZED *geom = (GSERIALIZED*)PG_DETOAST_DATUM(PG_GETARG_DATUM(2));
LWGEOM *lwgeom = lwgeom_from_gserialized(geom);
struct trajectory_elem *trje = (struct trajectory_elem *) palloc(sizeof(struct trajectory_elem));
GSERIALIZED *result;
size_t size;
/*elog(NOTICE, "trajectory_elem called");*/
if (lwgeom_is_empty(lwgeom) || lwgeom->type != POINTTYPE)
{
elog(NOTICE, "trajectory_elem is NULL, or type is not correct");
PG_RETURN_NULL();
}
/* Serialize the result back down from LWGEOM, but don't return right away */
// result = geometry_serialize(lwgeom);
result = gserialized_from_lwgeom(lwgeom, &size);
trje->id = id;
trje->time_obj = timestamp;
trje->geom_elem = result;
elog(NOTICE, "trajectory_elem finish");
/* Then call free_if_copy on the *varlena* structures you originally get as arguments */
// lwgeom_free(lwgeom);
PG_FREE_IF_COPY(lwgeom, 0);
elog(NOTICE, "trajectory_elem finish2");
// PG_RETURN_TRAJECTELEM_TYPE_P(trje);
PG_RETURN_POINTER(trje);
}
But the Postgres server crashes. Values are entering correctly, but I can not return the structure pointer..
It is wrong the way I'm programming the extension with the PostGIS?
Thanks in advance
De: Paul Ramsey <pramsey@xxxxxxxxxxxxxxxxx>
Enviado: segunda-feira, 14 de agosto de 2017 15:36 Para: Fabiana Zioti Cc: pgsql-general@xxxxxxxxxxxxxx Assunto: Re: Development of an extension for PostgreSQL and PostGIS In order to get an LWGEOM from PostGIS you'll need to convert from the serialized form (GSERIALIZED) which you can read all about in the liblwgeom.h header. You'll be adding a hard dependency of course, but hopefully you're OK with that.
If you're just hoping to build a compound type, as your example shows, you can do that without a C extension, just read up on CREATE TYPE.
For an alternate example of an extension with a lighter dependency on PostGIS, check out pgpointcloud, which has it's own structure for spatial data (a point patch) and exchanges data with PostGIS via well-known-binary. This removes the liblwgeom dependency,
which means it's possible to compile and use pgpointcloud without PostGIS installed, which is not entirely uncommon.
P
On Mon, Aug 14, 2017 at 11:18 AM, Fabiana Zioti
<fabi_zioti@xxxxxxxxxxx> wrote:
|