Is posible to use function lwgeom_to_geojson in another c fuctions

classic Classic list List threaded Threaded
15 messages Options
Reply | Threaded
Open this post in threaded view
|

Is posible to use function lwgeom_to_geojson in another c fuctions

Jan Michálek
Hello
I need a advice about this problem
I'm trying to write some C fuction for making geojson as aggregate from records as full regular geojson with properties.
I tried to use function lwgeom_to_geojson inside my code.

something like this

                case JSONTYPE_GEOM: //je;
                        {
                        LWGEOM *lwgeom;
                        lwgeom = lwgeom_from_gserialized(
                             (GSERIALIZED*)DatumGetPointer(val)
                              );
                        outputstr = lwgeom_to_geojson(lwgeom, 0, 0, false);
                        escape_json(result, outputstr);
                        pfree(outputstr);
                        break;
                        }



I have
#include "liblwgeom.h"
And I`m able to compile this. But if I try use function in postgre, it get me an error
ERROR:  could not load library "/usr/lib/postgresql/jelejson.so": /usr/lib/postgresql/jelejson.so: undefined symbol: lwgeom_to_geojson.

What i should do? Is posible to use this function like this?

Thanks Je;

--
Jelen
Starší čeledín datovýho chlíva

_______________________________________________
postgis-devel mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/postgis-devel
Reply | Threaded
Open this post in threaded view
|

Re: Is posible to use function lwgeom_to_geojson in another c fuctions

Sandro Santilli-4
On Fri, Jun 24, 2016 at 10:34:16PM +0200, Jan Michálek wrote:
> Hello
> I need a advice about this problem
> I'm trying to write some C fuction for making geojson as aggregate from
> records as full regular geojson with properties.
> I tried to use function lwgeom_to_geojson inside my code.

[...]

> And I`m able to compile this. But if I try use function in postgre, it get
> me an error
> ERROR:  could not load library "/usr/lib/postgresql/jelejson.so":
> /usr/lib/postgresql/jelejson.so: undefined symbol: lwgeom_to_geojson.
>
> What i should do? Is posible to use this function like this?

You should statically link liblwgeom.a into your code, and avoid
exporting its symbols outside of your library.

Or lobby to change PostGIS to link to liblwgeom dynamically
and do they same yourself :)

--strk;
_______________________________________________
postgis-devel mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/postgis-devel
Reply | Threaded
Open this post in threaded view
|

Re: Is posible to use function lwgeom_to_geojson in another c fuctions

Jan Michálek
>
> You should statically link liblwgeom.a into your code, and avoid
> exporting its symbols outside of your library.
>
> Or lobby to change PostGIS to link to liblwgeom dynamically
> and do they same yourself :)
>
> --strk;

Thanks

Je;

> _______________________________________________
> postgis-devel mailing list
> [hidden email]
> http://lists.osgeo.org/mailman/listinfo/postgis-devel
_______________________________________________
postgis-devel mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/postgis-devel
Reply | Threaded
Open this post in threaded view
|

Re: Is posible to use function lwgeom_to_geojson in another c fuctions

Sebastiaan Couwenberg
In reply to this post by Sandro Santilli-4
On 06/25/2016 08:59 AM, Sandro Santilli wrote:
> Or lobby to change PostGIS to link to liblwgeom dynamically
> and do they same yourself :)

You can use the patch from the Debian package for that too:

 https://anonscm.debian.org/cgit/pkg-grass/postgis.git/tree/debian/patches/link-liblwgeom

Kind Regards,

Bas

--
 GPG Key ID: 4096R/6750F10AE88D4AF1
Fingerprint: 8182 DE41 7056 408D 6146  50D1 6750 F10A E88D 4AF1
_______________________________________________
postgis-devel mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/postgis-devel
Reply | Threaded
Open this post in threaded view
|

Re: Is posible to use function lwgeom_to_geojson in another c fuctions

Jan Michálek
>
> You can use the patch from the Debian package for that too:
>
>  https://anonscm.debian.org/cgit/pkg-grass/postgis.git/tree/debian/patches/link-liblwgeom
>
> Kind Regards,

If i wil make package and istall postgis with this patch, my code will
work without changes?

Je;
>
> --
>  GPG Key ID: 4096R/6750F10AE88D4AF1
> Fingerprint: 8182 DE41 7056 408D 6146  50D1 6750 F10A E88D 4AF1
> _______________________________________________
> postgis-devel mailing list
> [hidden email]
> http://lists.osgeo.org/mailman/listinfo/postgis-devel
_______________________________________________
postgis-devel mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/postgis-devel
Reply | Threaded
Open this post in threaded view
|

Re: Is posible to use function lwgeom_to_geojson in another c fuctions

nicklas
In reply to this post by Jan Michálek

Just a comment.
With all the new json functions in PostgreSQL this is very easy to do directly in sql too. I think it is fairly efficient too. I use it in production to export complete geojson through postgrest.

I have thougt about if we could get rid of json-c dependency and use postgresql functionality instead.
Building json with jsonb, I guess is a lot faster than dealing with text strings.

/Nicklas

Skickat från min Sony Xperia™-smartphone

---- Jan Michálek skrev ----

> Hello
>
> I need a advice about this problem
>
> I'm trying to write some C fuction for making geojson as aggregate from records as full regular geojson with properties.
>
> I tried to use function lwgeom_to_geojson inside my code.
>
> something like this
>
>                 case JSONTYPE_GEOM: //je;
>                         {
>                         LWGEOM *lwgeom;
>                         lwgeom = lwgeom_from_gserialized(
>                              (GSERIALIZED*)DatumGetPointer(val)
>                               );
>                         outputstr = lwgeom_to_geojson(lwgeom, 0, 0, false);
>                         escape_json(result, outputstr);
>                         pfree(outputstr);
>
>                         break;
>
>                         }
>
>
>
> I have
> #include "liblwgeom.h"
>
> And I`m able to compile this. But if I try use function in postgre, it get me an error
>
> ERROR:  could not load library "/usr/lib/postgresql/jelejson.so": /usr/lib/postgresql/jelejson.so: undefined symbol: lwgeom_to_geojson.
>
> What i should do? Is posible to use this function like this?
>
> Thanks Je;
>
>
> --
>
> Jelen
>
> Starší čeledín datovýho chlíva


_______________________________________________
postgis-devel mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/postgis-devel
Reply | Threaded
Open this post in threaded view
|

Re: Is posible to use function lwgeom_to_geojson in another c fuctions

Jan Michálek
In reply to this post by Sebastiaan Couwenberg
Thanks, it helped.

Have a nice day.
Je;

On Sat, Jun 25, 2016 at 11:08:29AM +0200, Sebastiaan Couwenberg wrote:

> On 06/25/2016 08:59 AM, Sandro Santilli wrote:
> > Or lobby to change PostGIS to link to liblwgeom dynamically
> > and do they same yourself :)
>
> You can use the patch from the Debian package for that too:
>
>  https://anonscm.debian.org/cgit/pkg-grass/postgis.git/tree/debian/patches/link-liblwgeom
>
> Kind Regards,
>
> Bas
>
> --
>  GPG Key ID: 4096R/6750F10AE88D4AF1
> Fingerprint: 8182 DE41 7056 408D 6146  50D1 6750 F10A E88D 4AF1
> _______________________________________________
> postgis-devel mailing list
> [hidden email]
> http://lists.osgeo.org/mailman/listinfo/postgis-devel
_______________________________________________
postgis-devel mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/postgis-devel
Reply | Threaded
Open this post in threaded view
|

Re: Is posible to use function lwgeom_to_geojson in another c fuctions

Jan Michálek
In reply to this post by Jan Michálek
I cant find liblwgeom.a on my computer after installing Postgis from package, only If i had to use patch.
Sorry, im totaly newbie in C, maybe I`m asking in a dumb way.

Je;

2016-06-25 11:46 GMT+02:00 Leknín Řepánek <[hidden email]>:
>
> You should statically link liblwgeom.a into your code, and avoid
> exporting its symbols outside of your library.
>
> Or lobby to change PostGIS to link to liblwgeom dynamically
> and do they same yourself :)
>
> --strk;

Thanks

Je;

> _______________________________________________
> postgis-devel mailing list
> [hidden email]
> http://lists.osgeo.org/mailman/listinfo/postgis-devel



--
Jelen
Starší čeledín datovýho chlíva

_______________________________________________
postgis-devel mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/postgis-devel
Reply | Threaded
Open this post in threaded view
|

Re: Is posible to use function lwgeom_to_geojson in another c fuctions

Jan Michálek
In reply to this post by nicklas
You are using postgrest on some bigger data with spatial parts? I tried it few days ago and on many features it was pretty slow... But i didn`t make any tuning, maybe is there space for optimaliyation for my usecase.

2016-06-25 13:43 GMT+02:00 Nicklas Aven <[hidden email]>:

Just a comment.
With all the new json functions in PostgreSQL this is very easy to do directly in sql too. I think it is fairly efficient too. I use it in production to export complete geojson through postgrest.

I have thougt about if we could get rid of json-c dependency and use postgresql functionality instead.
Building json with jsonb, I guess is a lot faster than dealing with text strings.

/Nicklas

Skickat från min Sony Xperia™-smartphone

---- Jan Michálek skrev ----

> Hello
>
> I need a advice about this problem
>
> I'm trying to write some C fuction for making geojson as aggregate from records as full regular geojson with properties.
>
> I tried to use function lwgeom_to_geojson inside my code.
>
> something like this
>
>                 case JSONTYPE_GEOM: //je;
>                         {
>                         LWGEOM *lwgeom;
>                         lwgeom = lwgeom_from_gserialized(
>                              (GSERIALIZED*)DatumGetPointer(val)
>                               );
>                         outputstr = lwgeom_to_geojson(lwgeom, 0, 0, false);
>                         escape_json(result, outputstr);
>                         pfree(outputstr);
>
>                         break;
>
>                         }
>
>
>
> I have
> #include "liblwgeom.h"
>
> And I`m able to compile this. But if I try use function in postgre, it get me an error
>
> ERROR:  could not load library "/usr/lib/postgresql/jelejson.so": /usr/lib/postgresql/jelejson.so: undefined symbol: lwgeom_to_geojson.
>
> What i should do? Is posible to use this function like this?
>
> Thanks Je;
>
>
> --
>
> Jelen
>
> Starší čeledín datovýho chlíva


_______________________________________________
postgis-devel mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/postgis-devel



--
Jelen
Starší čeledín datovýho chlíva

_______________________________________________
postgis-devel mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/postgis-devel
Reply | Threaded
Open this post in threaded view
|

Re: Is posible to use function lwgeom_to_geojson in another c fuctions

nicklas

Well converting to geojson on the fly will always be quite expensive. We are not using the resultndirectly, and it is not very big data. But my guess is that it will be hard to beat the performance of building jsonb with postgresql functions and cast to text string as a last step. But that is said without evidence. But aggregating to geojson including attributes also feels like a clean operation, not messing with custom aggregates and learning json-c api or even worse writing everything for building json.

About postgrest I thing performance is ok. It is at least faster than the AGS server we are communicating with sometimes (and that is a beast compared to our Linode server)
/Nicklas

Skickat från min Sony Xperia™-smartphone

---- Jan Michálek skrev ----

> You are using postgrest on some bigger data with spatial parts? I tried it few days ago and on many features it was pretty slow... But i didn`t make any tuning, maybe is there space for optimaliyation for my usecase.
>
>
> 2016-06-25 13:43 GMT+02:00 Nicklas Aven <[hidden email]>:
>
> Just a comment.
> With all the new json functions in PostgreSQL this is very easy to do directly in sql too. I think it is fairly efficient too. I use it in production to export complete geojson through postgrest.
>
> I have thougt about if we could get rid of json-c dependency and use postgresql functionality instead.
> Building json with jsonb, I guess is a lot faster than dealing with text strings.
>
> /Nicklas
>
> Skickat från min Sony Xperia™-smartphone
>
> ---- Jan Michálek skrev ----
>
> > Hello
> >
> > I need a advice about this problem
> >
> > I'm trying to write some C fuction for making geojson as aggregate from records as full regular geojson with properties.
> >
> > I tried to use function lwgeom_to_geojson inside my code.
> >
> > something like this
> >
> >                 case JSONTYPE_GEOM: //je;
> >                         {
> >                         LWGEOM *lwgeom;
> >                         lwgeom = lwgeom_from_gserialized(
> >                              (GSERIALIZED*)DatumGetPointer(val)
> >                               );
> >                         outputstr = lwgeom_to_geojson(lwgeom, 0, 0, false);
> >                         escape_json(result, outputstr);
> >                         pfree(outputstr);
> >
> >                         break;
> >
> >                         }
> >
> >
> >
> > I have
> > #include "liblwgeom.h"
> >
> > And I`m able to compile this. But if I try use function in postgre, it get me an error
> >
> > ERROR:  could not load library "/usr/lib/postgresql/jelejson.so": /usr/lib/postgresql/jelejson.so: undefined symbol: lwgeom_to_geojson.
> >
> > What i should do? Is posible to use this function like this?
> >
> > Thanks Je;
> >
> >
> > --
> >
> > Jelen
> >
> > Starší čeledín datovýho chlíva
>
>
> _______________________________________________
> postgis-devel mailing list
> [hidden email]
> http://lists.osgeo.org/mailman/listinfo/postgis-devel
>
>
>
>
> --
>
> Jelen
>
> Starší čeledín datovýho chlíva


_______________________________________________
postgis-devel mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/postgis-devel
Reply | Threaded
Open this post in threaded view
|

Re: Is posible to use function lwgeom_to_geojson in another c fuctions

Jan Michálek
There are two reasons, why I want try make it in thios way

1.) I want to try learn myself something about how it is made inside on
some real life problem and on real data.

2.) plpgsql functions can`t use record as input. I`m able to write some
plpgsql function to create json from row, but it mean`s write function
for every table (or write trigger for creating this functions on DDL
events). I would like try to write something more univerzal.

I wrote my function using postgre libs only by make few changes in
row_to_json functions (this is not agregate, only something like first
step), but I`m not able to find oid for relevant function to
geometry_out in this

outputstr = OidOutputFunctionCall(outfuncoid, val)

If I arbitrary set oid of ST_AsGeojson, this doesn`t work.

That im trying to use lwgeom_to_geojson from liblwgeom.

But my C posibilities are really low. So I should learn some basic
stuff on thos problem.

Je;

On Sat, Jun 25, 2016 at 02:19:45PM +0200, Nicklas Aven wrote:

> Well converting to geojson on the fly will always be quite expensive. We are
> not using the resultndirectly, and it is not very big data. But my guess is
> that it will be hard to beat the performance of building jsonb with postgresql
> functions and cast to text string as a last step. But that is said without
> evidence. But aggregating to geojson including attributes also feels like a
> clean operation, not messing with custom aggregates and learning json-c api or
> even worse writing everything for building json.
>
> About postgrest I thing performance is ok. It is at least faster than the AGS
> server we are communicating with sometimes (and that is a beast compared to our
> Linode server)
> /Nicklas
>
> Skickat från min Sony Xperia™-smartphone
>
> ---- Jan Michálek skrev ----
>
> > You are using postgrest on some bigger data with spatial parts? I tried it
> few days ago and on many features it was pretty slow... But i didn`t make any
> tuning, maybe is there space for optimaliyation for my usecase.
> >
> >
> > 2016-06-25 13:43 GMT+02:00 Nicklas Aven <[hidden email]>:
> >
> > Just a comment.
> > With all the new json functions in PostgreSQL this is very easy to do
> directly in sql too. I think it is fairly efficient too. I use it in production
> to export complete geojson through postgrest.
> >
> > I have thougt about if we could get rid of json-c dependency and use
> postgresql functionality instead.
> > Building json with jsonb, I guess is a lot faster than dealing with text
> strings.
> >
> > /Nicklas
> >
> > Skickat från min Sony Xperia™-smartphone
> >
> > ---- Jan Michálek skrev ----
> >
> > > Hello
> > >
> > > I need a advice about this problem
> > >
> > > I'm trying to write some C fuction for making geojson as aggregate from
> records as full regular geojson with properties.
> > >
> > > I tried to use function lwgeom_to_geojson inside my code.
> > >
> > > something like this
> > >
> > >                 case JSONTYPE_GEOM: //je;
> > >                         {
> > >                         LWGEOM *lwgeom;
> > >                         lwgeom = lwgeom_from_gserialized(
> > >                              (GSERIALIZED*)DatumGetPointer(val)
> > >                               );
> > >                         outputstr = lwgeom_to_geojson(lwgeom, 0, 0, false);
> > >                         escape_json(result, outputstr);
> > >                         pfree(outputstr);
> > >
> > >                         break;
> > >
> > >                         }
> > >
> > >
> > >
> > > I have
> > > #include "liblwgeom.h"
> > >
> > > And I`m able to compile this. But if I try use function in postgre, it get
> me an error
> > >
> > > ERROR:  could not load library "/usr/lib/postgresql/jelejson.so": /usr/lib/
> postgresql/jelejson.so: undefined symbol: lwgeom_to_geojson.
> > >
> > > What i should do? Is posible to use this function like this?
> > >
> > > Thanks Je;
> > >
> > >
> > > --
> > >
> > > Jelen
> > >
> > > Starší čeledín datovýho chlíva
> >
> >
> > _______________________________________________
> > postgis-devel mailing list
> > [hidden email]
> > http://lists.osgeo.org/mailman/listinfo/postgis-devel
> >
> >
> >
> >
> > --
> >
> > Jelen
> >
> > Starší čeledín datovýho chlíva
>

> _______________________________________________
> postgis-devel mailing list
> [hidden email]
> http://lists.osgeo.org/mailman/listinfo/postgis-devel

_______________________________________________
postgis-devel mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/postgis-devel
Reply | Threaded
Open this post in threaded view
|

Re: Is posible to use function lwgeom_to_geojson in another c fuctions

Paul Ramsey
Writing extensions that use other extensions w/o a compile-time dependency is a little tricky, but not impossible, and very gratifying from a cleanliness point of view. Here is an example from ogr-fdw of looking up function Oids by name


Also, to get the generic input/output functions for a type (which in the case of PostGIS can be used to generate/consume hexewkb or ewkb) you don’t even need to look up the function, as the in/out/send/recv functions are all part of the type definition.


ATB,

P

I wrote my function using postgre libs only by make few changes in
row_to_json functions (this is not agregate, only something like first
step), but I`m not able to find oid for relevant function to
geometry_out in this


_______________________________________________
postgis-devel mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/postgis-devel
Reply | Threaded
Open this post in threaded view
|

Re: Is posible to use function lwgeom_to_geojson in another c fuctions

Jan Michálek
Thanks

I`m going to read this.

Je;

On Sat, Jun 25, 2016 at 07:08:53AM -0700, Paul Ramsey wrote:

> Writing extensions that use other extensions w/o a compile-time dependency is a
> little tricky, but not impossible, and very gratifying from a cleanliness point
> of view. Here is an example from ogr-fdw of looking up function Oids by name
>
> https://github.com/pramsey/pgsql-ogr-fdw/blob/
> 7c5699a20371eb1230e28cd1d3be12c76ee0035c/ogr_fdw.c#L1229-L1263
>
> Also, to get the generic input/output functions for a type (which in the case
> of PostGIS can be used to generate/consume hexewkb or ewkb) you don’t even need
> to look up the function, as the in/out/send/recv functions are all part of the
> type definition.
>
> https://github.com/pramsey/pgsql-ogr-fdw/blob/
> 7c5699a20371eb1230e28cd1d3be12c76ee0035c/ogr_fdw.c#L1131-L1135
>
> ATB,
>
> P
>
>
>     I wrote my function using postgre libs only by make few changes in
>     row_to_json functions (this is not agregate, only something like first
>     step), but I`m not able to find oid for relevant function to
>     geometry_out in this
>
>

> _______________________________________________
> postgis-devel mailing list
> [hidden email]
> http://lists.osgeo.org/mailman/listinfo/postgis-devel

_______________________________________________
postgis-devel mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/postgis-devel
Reply | Threaded
Open this post in threaded view
|

Re: Is posible to use function lwgeom_to_geojson in another c fuctions

Jan Michálek
In reply to this post by Jan Michálek
No, something is wrong

test=# CREATE extension jelejson;
ERROR:  could not load library "/usr/lib/postgresql/jelejson.so": /usr/lib/postgresql/jelejson.so: undefined symbol: lwgeom_to_geojson
test=#

It works, but
lwgeom_from_gserialized throws error

test=# select f_jelejson(t4) from t4;
ERROR:  Unknown geometry type: 256 - Unknown

So I make some minor changes, reinstall and it is not able to find lwgeom to geojson. I revert changes, but it is not able to find lwgeom_to_geojson

but i haven`t liblwgeom in my search path
[jelen@laptak geojson_s_proprtama]$ locate liblwgeom.a
/home/jelen/Downloads/postgis-2.2.2/liblwgeom/.libs/liblwgeom.a
/home/jelen/packages/posgis_pitva/src/postgis-2.2.2/liblwgeom/.libs/liblwgeom.a
[jelen@laptak geojson_s_proprtama]$








2016-06-25 15:51 GMT+02:00 Leknín Řepánek <[hidden email]>:
Thanks, it helped.

Have a nice day.
Je;

On Sat, Jun 25, 2016 at 11:08:29AM +0200, Sebastiaan Couwenberg wrote:
> On 06/25/2016 08:59 AM, Sandro Santilli wrote:
> > Or lobby to change PostGIS to link to liblwgeom dynamically
> > and do they same yourself :)
>
> You can use the patch from the Debian package for that too:
>
https://anonscm.debian.org/cgit/pkg-grass/postgis.git/tree/debian/patches/link-liblwgeom
>
> Kind Regards,
>
> Bas
>
> --
>  GPG Key ID: 4096R/6750F10AE88D4AF1
> Fingerprint: 8182 DE41 7056 408D 6146  50D1 6750 F10A E88D 4AF1
> _______________________________________________
> postgis-devel mailing list
> [hidden email]
> http://lists.osgeo.org/mailman/listinfo/postgis-devel



--
Jelen
Starší čeledín datovýho chlíva

_______________________________________________
postgis-devel mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/postgis-devel
Reply | Threaded
Open this post in threaded view
|

Re: Is posible to use function lwgeom_to_geojson in another c fuctions

Sandro Santilli-4
In reply to this post by nicklas
On Sat, Jun 25, 2016 at 01:43:52PM +0200, Nicklas Aven wrote:

> I have thougt about if we could get rid of json-c dependency and use postgresql functionality instead.

Dropping deps is always good, as long as we're not forced
to drop support for otherwise supported PostgreSQL versions...

--strk;
_______________________________________________
postgis-devel mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/postgis-devel