[postgis-users] Postgis 3.0: How to convert liblwgeom to librttopo?

pt122 at gmx.net pt122 at gmx.net
Mon Jun 27 13:55:57 PDT 2022


Hi, [once more as plain text since html was scrubbed...]

> Your function sounds a lot like existing https://postgis.net/docs/ST_AsMVTGeom.html

Thanks for the reference, I didn't hear of this before. It's in /postgis/mvt.c, right?

For reference, my signature would be the following:

    preprocess(geometry geom, box2d bounds, double resolution, double mindx, double mindy);

which feels quite different (apart from geom and bbox). Looking at the sources and docs, it seems that st_asmvtgeom can do subtasks (a) and possibly also (c) (subtasks see below in my previous post). The main difference is that subtask (b) does not do clipping, it just sorts out points (although I'm a bit unsure what st_asmvtgeom exactly does if clip_geom is set to false?), leaving this step up to some vector-based rendering framework. Another difference regarding the function parameters of st_asmvtgeom is that they have Mapbox tiles and specifications in mind whereas my function does not.

I think that both functions may have their usages. The question here is if there is an interest of adding another variant of a fast preprocessing function to postgis? One vote from me :)



Gesendet: Montag, 27. Juni 2022 um 20:14 Uhr
Von: "Darafei Komяpa Praliaskouski" <me at komzpa.net>
An: "PostGIS Users Discussion" <postgis-users at lists.osgeo.org>
Betreff: Re: [postgis-users] Postgis 3.0: How to convert liblwgeom to librttopo?

Hi,
 
Your function sounds a lot like existing https://postgis.net/docs/ST_AsMVTGeom.html  



On Mon, Jun 27, 2022 at 9:10 PM <pt122 at gmx.net[mailto:pt122 at gmx.net]> wrote:Thank you for your feedback. Since I see no practical way for me to use liblwgeom functionality after installing postgis 3.x I tried another approach and added my function to the normal postgis make process which works fine for me:
 
- put my c file into /postgis
- add it in postgis/Makefile
- append a create function in postgis/postgis.sql.in[http://postgis.sql.in]
- ./configure, make and make install
- then in psql: drop+create extension postgis to reflect changes and test.
 
Two more questions:
 
1. I'd like to ask if I could contribute with my function (since I think that the existing st_methods are not really that what I want): It is a short preprocessing function for subsequent actions like fast rendering of high resolution data within a bbox. It aims to reduce as many coordinates as possible, and as fast as possible. It is not topology-safe, works currently for multipolygons and multilines, and offers different subtasks that may be combined:
 
a) scale and remove coordinates in a sequence that lie on same grid cells (similar to st_snaptogrid and st_reduceprecision)
b) sorting out all points outside a bbox that are irrelevant for rendering data within this bbox (similar to st_clipbybox2d but without computing any new intersection points)
c) remove small parts with dimensions below a threshold (similar to st_box2d component checks, and simpler+faster than expensive st_area computations)

2. Are there any examples on how to use the officially recommented librttopo (as part of the default package-based postgis installation) for compile own c-based libraries after installation of postgis?
 
Thank you, Sven



Gesendet: Samstag, 25. Juni 2022 um 23:48 Uhr
Von: "Regina Obe" <lr at pcorp.us[mailto:lr at pcorp.us]>
An: "'PostGIS Users Discussion'" <postgis-users at lists.osgeo.org[mailto:postgis-users at lists.osgeo.org]>
Betreff: Re: [postgis-users] Postgis 3.0: How to convert liblwgeom to librttopo?

liblwgeom.so is not separate anymore and liblwgeom.h is not installed either. They are all just object libraries, statically linked in all the .sos we expose as needed.
You can take a look at https://trac.osgeo.org/postgis/ticket/4260[https://trac.osgeo.org/postgis/ticket/4260]  and https://github.com/postgis/postgis/pull/348/[https://github.com/postgis/postgis/pull/348/][https://github.com/postgis/postgis/pull/348/%5Bhttps://github.com/postgis/postgis/pull/348/%5D]
where it was removed and back track those changes.
 
By the way  https://postgis.net/docs/ST_ReducePrecision.html[https://postgis.net/docs/ST_ReducePrecision.html][https://postgis.net/docs/ST_ReducePrecision.html%5Bhttps://postgis.net/docs/ST_ReducePrecision.html%5D] is a better alternative to ST_SnapToGrid as it’s much less likely to produce invalid geometries, but as mentioned only available if you have GEOS 3.9+
 
 
Hope that helps,
Regina
 
 
 

From: postgis-users [mailto:postgis-users-bounces at lists.osgeo.org[mailto:postgis-users-bounces at lists.osgeo.org]] On Behalf Of pt122 at gmx.net[mailto:pt122 at gmx.net]
Sent: Friday, June 24, 2022 5:01 AM
To: postgis-users at lists.osgeo.org[mailto:postgis-users at lists.osgeo.org]
Subject: Re: [postgis-users] Postgis 3.0: How to convert liblwgeom to librttopo?
 

Hi Regina, thank you very much for your valuable and fast reply. What I want to

achive is quite similar to st_snaptogrid(). I'll surely give it a try to replace our function

(developed in 2013) with one or more of these functions you mentioned at some

point in the future. But, for now, I'd like to try to go forward with liblwgeom in the

first place and I am glad for your hint that it is still a usable part of PostGIS 3.x.

 

So, two questions arise:

 

(How) can I build PostGIS via gcc and special flags from source to get the required

liblwgeom.h and liblwgeom.so files?

 

Or is liblwgeom already contained in the "normal" installable package, with some

way to access it?

 

Thank you, Sven

 

Gesendet: Freitag, 24. Juni 2022 um 02:47 Uhr
Von: "Regina Obe" <lr at pcorp.us[mailto:lr at pcorp.us][mailto:lr at pcorp.us[mailto:lr at pcorp.us]]>
An: "'PostGIS Users Discussion'" <postgis-users at lists.osgeo.org[mailto:postgis-users at lists.osgeo.org][mailto:postgis-users at lists.osgeo.org[mailto:postgis-users at lists.osgeo.org]]>
Betreff: Re: [postgis-users] Postgis 3.0: How to convert liblwgeom to librttopo?

liblwgeom is still part of PostGIS but not exposed anymore as a standalone
library and is always statically linked. The reason is it caused too much
headache since we often change it even in micro versions so didn't want
anyone directly relying on it or our own code hooking onto the wrong version
installed in system.

Yes librttopo is a fork and is maintained separate from PostGIS here -
https://git.osgeo.org/gitea/rttopo/librttopo[https://git.osgeo.org/gitea/rttopo/librttopo][https://git.osgeo.org/gitea/rttopo/librttopo%5Bhttps://git.osgeo.org/gitea/rttopo/librttopo%5D] .

I'm not sure if it has a hard requirement on GEOS. It definitely has pieces
that use GEOS, so at very least a soft requirement. It is a subset of
liblwgeom, that subset that was useful for topology work in particular, but
it probably includes the subset you need.

It's unclear to me what your function does, but some possibly useful
functions to achieve the same goal are:

https://postgis.net/docs/ST_Subdivide.html[https://postgis.net/docs/ST_Subdivide.html][https://postgis.net/docs/ST_Subdivide.html%5Bhttps://postgis.net/docs/ST_Subdivide.html%5D]

https://postgis.net/docs/ST_ClipByBox2D.html

https://postgis.net/docs/ST_SquareGrid.html

https://postgis.net/docs/ST_HexagonGrid.html


Also if you are running GEOS 3.9 (+ PostGIS 3.1+) or higher, using
https://postgis.net/docs/ST_ReducePrecision.html[https://postgis.net/docs/ST_ReducePrecision.html][https://postgis.net/docs/ST_ReducePrecision.html%5Bhttps://postgis.net/docs/ST_ReducePrecision.html%5D] (and/or the newer ST_Union,
ST_Intersection, ST_Subdivide) which has reduce precision logic in them
might solve some of your problems)

Hope that helps,
Regina

> -----Original Message-----
> From: postgis-users [mailto:postgis-users-bounces at lists.osgeo.org[mailto:postgis-users-bounces at lists.osgeo.org][mailto:postgis-users-bounces at lists.osgeo.org[mailto:postgis-users-bounces at lists.osgeo.org]]] On
Behalf
> Of pt122 at gmx.net[mailto:pt122 at gmx.net][mailto:pt122 at gmx.net[mailto:pt122 at gmx.net]]
> Sent: Thursday, June 23, 2022 4:52 PM
> To: postgis-users at lists.osgeo.org[mailto:postgis-users at lists.osgeo.org][mailto:postgis-users at lists.osgeo.org[mailto:postgis-users at lists.osgeo.org]]
> Subject: [postgis-users] Postgis 3.0: How to convert liblwgeom to
librttopo?
>
> Dear Postgis community, I'm not sure if I'm in the right forum but I want
to
> give it a try. We want to upgrade from PostGIS 2.x to PostGIS 3.x and take
> over a self-written library (.so). This library was compiled with
liblwgeom of
> PostGIS 2.x. liblwgeom seems to be not part of PostGIS 3.x anymore
> (/include/liblwgeom.h is missing for instance).
>
> According to the comment in https://postgis.net/2019/10/20/postgis-3.0.0/[https://postgis.net/2019/10/20/postgis-3.0.0/][https://postgis.net/2019/10/20/postgis-3.0.0/%5Bhttps://postgis.net/2019/10/20/postgis-3.0.0/%5D],
> liblwgeom should be replaced with librttopo (which seems to be a fork of
> liblwgeom according to https://github.com/r-spatial/lwgeom/issues/30[https://github.com/r-spatial/lwgeom/issues/30][https://github.com/r-spatial/lwgeom/issues/30%5Bhttps://github.com/r-spatial/lwgeom/issues/30%5D]).
>
> Our function that makes use of our lib, used for fast scaling, clipping
and
> sorting-out coordinates, looks like:
>
> CREATE OR REPLACE FUNCTION preprocess(geometry, box2d, ...) RETURNS
> geometry AS 'path/to/lib.so', 'preprocess'
> LANGUAGE c;
> and in the c code are some LWGEOM*, LWMLINE*, LWMPOLY* and lwfree(..)
> calls.
>
> My questions are:
>
> - is lwgeom still part of Postgis 3.x? (I still see liblwgeom.h.in[http://liblwgeom.h.in] as part
of
> postgis-3.2.1.tar.gz, so it seems that is not fully removed yet)
>
> - if not, what would be a good starting point for conversion?
>
> - are there any mappings of old and new functions or types available?
>
> -are there any packages (besides librttopo and librttopo-devel) that must
be
> installed additionally with librttopo (like GEOS or similar)?
>
> -what are the PostGIS built-in alternatives for scaling and clipping?
>
> Thank you for any hints, Peter
>
> (See original post on
> https://gis.stackexchange.com/questions/434369/postgis-3-0-how-to-convert-[https://gis.stackexchange.com/questions/434369/postgis-3-0-how-to-convert-][https://gis.stackexchange.com/questions/434369/postgis-3-0-how-to-convert-%5Bhttps://gis.stackexchange.com/questions/434369/postgis-3-0-how-to-convert-%5D]
> liblwgeom-to-librttopo, but my problem is likely is too specific to ask in
> stackexchange...) _______________________________________________
> postgis-users mailing list
> postgis-users at lists.osgeo.org[mailto:postgis-users at lists.osgeo.org][mailto:postgis-users at lists.osgeo.org[mailto:postgis-users at lists.osgeo.org]]
> https://lists.osgeo.org/mailman/listinfo/postgis-users[https://lists.osgeo.org/mailman/listinfo/postgis-users][https://lists.osgeo.org/mailman/listinfo/postgis-users%5Bhttps://lists.osgeo.org/mailman/listinfo/postgis-users%5D]

_______________________________________________
postgis-users mailing list
postgis-users at lists.osgeo.org[mailto:postgis-users at lists.osgeo.org][mailto:postgis-users at lists.osgeo.org[mailto:postgis-users at lists.osgeo.org]]
https://lists.osgeo.org/mailman/listinfo/postgis-users[https://lists.osgeo.org/mailman/listinfo/postgis-users]

 

 
_______________________________________________ postgis-users mailing list postgis-users at lists.osgeo.org[mailto:postgis-users at lists.osgeo.org] https://lists.osgeo.org/mailman/listinfo/postgis-users[https://lists.osgeo.org/mailman/listinfo/postgis-users][https://lists.osgeo.org/mailman/listinfo/postgis-users%5Bhttps://lists.osgeo.org/mailman/listinfo/postgis-users%5D]
 
 
_______________________________________________
postgis-users mailing list
postgis-users at lists.osgeo.org[mailto:postgis-users at lists.osgeo.org]
https://lists.osgeo.org/mailman/listinfo/postgis-users_______________________________________________ postgis-users mailing list postgis-users at lists.osgeo.org https://lists.osgeo.org/mailman/listinfo/postgis-users[https://lists.osgeo.org/mailman/listinfo/postgis-users]


More information about the postgis-users mailing list