[postgis-devel] Can I call LWGEOM_x_point directly from another stored procedure?

Stephen Woodbridge woodbri at swoodbridge.com
Sun Nov 17 12:04:01 PST 2013


Ok, thanks. I have decided to take this approach instead.

I'm going to change my function signature to take two float8[] arrays 
instead of a point[], then add another function to unnest(point) and 
aggregate that into two arrays like:

create or replace function myfunction(float8[], float8[])
returns text as
$$
...
$$
language 'c';

create or replace function myfunction(geometry[])
returns text as
$$
with a as (
select array_agg(st_x(g)) as x, array_agg(st_y(g)) as y
   from unnest($1) as g
)
select * from myfunction(a.x, a.y);
$$
language 'sql';

This is just a lot easier and I already know how to access arrays. It is 
just too hard (IMO) to try and directly use postGIS functions from C 
code if your code is not in the PostGIS project.

Anyway, thank you for your insights, I learned a lot in this exercise 
that I didn't know about before, so I count that as a win :)

-Steve

On 11/17/2013 11:27 AM, Paul Ramsey wrote:
> Ah, if you don't have postgis headers to compile against you're not
> going to be able to pass DirectFunctionCall something it
> understands. What I did for pointcloud was, for the functions I
> needed to interop with PostGIS, emitted and consumed WKB in
> postgresql bytea format. Then I could pass that to geomfromwkb and
> that to whatever, and do it all in SQL wrappers.
>
> The SQL wrappers would have a dependency on the existence of the
> 'geometry' type in the system catalogs, but the actual code has no
> compile-time (or even run-time) dependency on postgis code.
>
> You can see how it works sort of in the the pointcloud repo and the
> pgsql_postgis directory
>
> P.
>




More information about the postgis-devel mailing list