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:
Hello.
I will start developing an extension to PostgreSQL next to PostGIS using the C language.
If my new type were:
CREATE TYPE mytype (.., .., .., geom geometry);
The creation of the structure in c, would be something like?
#include "liblwgeom.h"
Struct mytype{Int32 id;LWGEOM lwgeom;
};
In the extension I will create new data types for PostgreSQL, but I would like to use the geometric objects that the PostGIS extension offers, such as POINT, LINE, POLYGON, etc. In addition to their input functions (wkt- ST_GeomFromText ()), operators, index, etc.
In this case just importing the liblwgeom library would be enough to develop an extension to PostgreSQL / PostGIS?
Would you have any examples of such a project?
Thanks in advance!!