<div dir="ltr">Hi,<div><br></div><div>Your function sounds a lot like existing <a href="https://postgis.net/docs/ST_AsMVTGeom.html">https://postgis.net/docs/ST_AsMVTGeom.html</a> </div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Jun 27, 2022 at 9:10 PM <<a href="mailto:pt122@gmx.net">pt122@gmx.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">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:<br>
 <br>
- put my c file into /postgis<br>
- add it in postgis/Makefile<br>
- append a create function in postgis/<a href="http://postgis.sql.in" rel="noreferrer" target="_blank">postgis.sql.in</a><br>
- ./configure, make and make install<br>
- then in psql: drop+create extension postgis to reflect changes and test.<br>
 <br>
Two more questions:<br>
 <br>
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:<br>
 <br>
a) scale and remove coordinates in a sequence that lie on same grid cells (similar to st_snaptogrid and st_reduceprecision)<br>
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)<br>
c) remove small parts with dimensions below a threshold (similar to st_box2d component checks, and simpler+faster than expensive st_area computations)<br>
<br>
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?<br>
 <br>
Thank you, Sven<br>
<br>
<br>
<br>
Gesendet: Samstag, 25. Juni 2022 um 23:48 Uhr<br>
Von: "Regina Obe" <<a href="mailto:lr@pcorp.us" target="_blank">lr@pcorp.us</a>><br>
An: "'PostGIS Users Discussion'" <<a href="mailto:postgis-users@lists.osgeo.org" target="_blank">postgis-users@lists.osgeo.org</a>><br>
Betreff: Re: [postgis-users] Postgis 3.0: How to convert liblwgeom to librttopo?<br>
<br>
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.<br>
You can take a look at <a href="https://trac.osgeo.org/postgis/ticket/4260" rel="noreferrer" target="_blank">https://trac.osgeo.org/postgis/ticket/4260</a>  and <a href="https://github.com/postgis/postgis/pull/348/%5Bhttps://github.com/postgis/postgis/pull/348/%5D" rel="noreferrer" target="_blank">https://github.com/postgis/postgis/pull/348/[https://github.com/postgis/postgis/pull/348/]</a><br>
where it was removed and back track those changes.<br>
 <br>
By the way  <a href="https://postgis.net/docs/ST_ReducePrecision.html%5Bhttps://postgis.net/docs/ST_ReducePrecision.html%5D" rel="noreferrer" target="_blank">https://postgis.net/docs/ST_ReducePrecision.html[https://postgis.net/docs/ST_ReducePrecision.html]</a> 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+<br>
 <br>
 <br>
Hope that helps,<br>
Regina<br>
 <br>
 <br>
 <br>
<br>
From: postgis-users [mailto:<a href="mailto:postgis-users-bounces@lists.osgeo.org" target="_blank">postgis-users-bounces@lists.osgeo.org</a>] On Behalf Of <a href="mailto:pt122@gmx.net" target="_blank">pt122@gmx.net</a><br>
Sent: Friday, June 24, 2022 5:01 AM<br>
To: <a href="mailto:postgis-users@lists.osgeo.org" target="_blank">postgis-users@lists.osgeo.org</a><br>
Subject: Re: [postgis-users] Postgis 3.0: How to convert liblwgeom to librttopo?<br>
 <br>
<br>
Hi Regina, thank you very much for your valuable and fast reply. What I want to<br>
<br>
achive is quite similar to st_snaptogrid(). I'll surely give it a try to replace our function<br>
<br>
(developed in 2013) with one or more of these functions you mentioned at some<br>
<br>
point in the future. But, for now, I'd like to try to go forward with liblwgeom in the<br>
<br>
first place and I am glad for your hint that it is still a usable part of PostGIS 3.x.<br>
<br>
 <br>
<br>
So, two questions arise:<br>
<br>
 <br>
<br>
(How) can I build PostGIS via gcc and special flags from source to get the required<br>
<br>
liblwgeom.h and liblwgeom.so files?<br>
<br>
 <br>
<br>
Or is liblwgeom already contained in the "normal" installable package, with some<br>
<br>
way to access it?<br>
<br>
 <br>
<br>
Thank you, Sven<br>
<br>
 <br>
<br>
Gesendet: Freitag, 24. Juni 2022 um 02:47 Uhr<br>
Von: "Regina Obe" <<a href="mailto:lr@pcorp.us" target="_blank">lr@pcorp.us</a>[mailto:<a href="mailto:lr@pcorp.us" target="_blank">lr@pcorp.us</a>]><br>
An: "'PostGIS Users Discussion'" <<a href="mailto:postgis-users@lists.osgeo.org" target="_blank">postgis-users@lists.osgeo.org</a>[mailto:<a href="mailto:postgis-users@lists.osgeo.org" target="_blank">postgis-users@lists.osgeo.org</a>]><br>
Betreff: Re: [postgis-users] Postgis 3.0: How to convert liblwgeom to librttopo?<br>
<br>
liblwgeom is still part of PostGIS but not exposed anymore as a standalone<br>
library and is always statically linked. The reason is it caused too much<br>
headache since we often change it even in micro versions so didn't want<br>
anyone directly relying on it or our own code hooking onto the wrong version<br>
installed in system.<br>
<br>
Yes librttopo is a fork and is maintained separate from PostGIS here -<br>
<a href="https://git.osgeo.org/gitea/rttopo/librttopo%5Bhttps://git.osgeo.org/gitea/rttopo/librttopo%5D" rel="noreferrer" target="_blank">https://git.osgeo.org/gitea/rttopo/librttopo[https://git.osgeo.org/gitea/rttopo/librttopo]</a> .<br>
<br>
I'm not sure if it has a hard requirement on GEOS. It definitely has pieces<br>
that use GEOS, so at very least a soft requirement. It is a subset of<br>
liblwgeom, that subset that was useful for topology work in particular, but<br>
it probably includes the subset you need.<br>
<br>
It's unclear to me what your function does, but some possibly useful<br>
functions to achieve the same goal are:<br>
<br>
<a href="https://postgis.net/docs/ST_Subdivide.html%5Bhttps://postgis.net/docs/ST_Subdivide.html%5D" rel="noreferrer" target="_blank">https://postgis.net/docs/ST_Subdivide.html[https://postgis.net/docs/ST_Subdivide.html]</a><br>
<br>
<a href="https://postgis.net/docs/ST_ClipByBox2D.html" rel="noreferrer" target="_blank">https://postgis.net/docs/ST_ClipByBox2D.html</a><br>
<br>
<a href="https://postgis.net/docs/ST_SquareGrid.html" rel="noreferrer" target="_blank">https://postgis.net/docs/ST_SquareGrid.html</a><br>
<br>
<a href="https://postgis.net/docs/ST_HexagonGrid.html" rel="noreferrer" target="_blank">https://postgis.net/docs/ST_HexagonGrid.html</a><br>
<br>
<br>
Also if you are running GEOS 3.9 (+ PostGIS 3.1+) or higher, using<br>
<a href="https://postgis.net/docs/ST_ReducePrecision.html%5Bhttps://postgis.net/docs/ST_ReducePrecision.html%5D" rel="noreferrer" target="_blank">https://postgis.net/docs/ST_ReducePrecision.html[https://postgis.net/docs/ST_ReducePrecision.html]</a> (and/or the newer ST_Union,<br>
ST_Intersection, ST_Subdivide) which has reduce precision logic in them<br>
might solve some of your problems)<br>
<br>
Hope that helps,<br>
Regina<br>
<br>
> -----Original Message-----<br>
> From: postgis-users [mailto:<a href="mailto:postgis-users-bounces@lists.osgeo.org" target="_blank">postgis-users-bounces@lists.osgeo.org</a>[mailto:<a href="mailto:postgis-users-bounces@lists.osgeo.org" target="_blank">postgis-users-bounces@lists.osgeo.org</a>]] On<br>
Behalf<br>
> Of <a href="mailto:pt122@gmx.net" target="_blank">pt122@gmx.net</a>[mailto:<a href="mailto:pt122@gmx.net" target="_blank">pt122@gmx.net</a>]<br>
> Sent: Thursday, June 23, 2022 4:52 PM<br>
> To: <a href="mailto:postgis-users@lists.osgeo.org" target="_blank">postgis-users@lists.osgeo.org</a>[mailto:<a href="mailto:postgis-users@lists.osgeo.org" target="_blank">postgis-users@lists.osgeo.org</a>]<br>
> Subject: [postgis-users] Postgis 3.0: How to convert liblwgeom to<br>
librttopo?<br>
><br>
> Dear Postgis community, I'm not sure if I'm in the right forum but I want<br>
to<br>
> give it a try. We want to upgrade from PostGIS 2.x to PostGIS 3.x and take<br>
> over a self-written library (.so). This library was compiled with<br>
liblwgeom of<br>
> PostGIS 2.x. liblwgeom seems to be not part of PostGIS 3.x anymore<br>
> (/include/liblwgeom.h is missing for instance).<br>
><br>
> According to the comment in <a href="https://postgis.net/2019/10/20/postgis-3.0.0/%5Bhttps://postgis.net/2019/10/20/postgis-3.0.0/%5D" rel="noreferrer" target="_blank">https://postgis.net/2019/10/20/postgis-3.0.0/[https://postgis.net/2019/10/20/postgis-3.0.0/]</a>,<br>
> liblwgeom should be replaced with librttopo (which seems to be a fork of<br>
> liblwgeom according to <a href="https://github.com/r-spatial/lwgeom/issues/30%5Bhttps://github.com/r-spatial/lwgeom/issues/30%5D" rel="noreferrer" target="_blank">https://github.com/r-spatial/lwgeom/issues/30[https://github.com/r-spatial/lwgeom/issues/30]</a>).<br>
><br>
> Our function that makes use of our lib, used for fast scaling, clipping<br>
and<br>
> sorting-out coordinates, looks like:<br>
><br>
> CREATE OR REPLACE FUNCTION preprocess(geometry, box2d, ...) RETURNS<br>
> geometry AS 'path/to/lib.so', 'preprocess'<br>
> LANGUAGE c;<br>
> and in the c code are some LWGEOM*, LWMLINE*, LWMPOLY* and lwfree(..)<br>
> calls.<br>
><br>
> My questions are:<br>
><br>
> - is lwgeom still part of Postgis 3.x? (I still see <a href="http://liblwgeom.h.in" rel="noreferrer" target="_blank">liblwgeom.h.in</a> as part<br>
of<br>
> postgis-3.2.1.tar.gz, so it seems that is not fully removed yet)<br>
><br>
> - if not, what would be a good starting point for conversion?<br>
><br>
> - are there any mappings of old and new functions or types available?<br>
><br>
> -are there any packages (besides librttopo and librttopo-devel) that must<br>
be<br>
> installed additionally with librttopo (like GEOS or similar)?<br>
><br>
> -what are the PostGIS built-in alternatives for scaling and clipping?<br>
><br>
> Thank you for any hints, Peter<br>
><br>
> (See original post on<br>
> <a href="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" rel="noreferrer" target="_blank">https://gis.stackexchange.com/questions/434369/postgis-3-0-how-to-convert-[https://gis.stackexchange.com/questions/434369/postgis-3-0-how-to-convert-]</a><br>
> liblwgeom-to-librttopo, but my problem is likely is too specific to ask in<br>
> stackexchange...) _______________________________________________<br>
> postgis-users mailing list<br>
> <a href="mailto:postgis-users@lists.osgeo.org" target="_blank">postgis-users@lists.osgeo.org</a>[mailto:<a href="mailto:postgis-users@lists.osgeo.org" target="_blank">postgis-users@lists.osgeo.org</a>]<br>
> <a href="https://lists.osgeo.org/mailman/listinfo/postgis-users%5Bhttps://lists.osgeo.org/mailman/listinfo/postgis-users%5D" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/postgis-users[https://lists.osgeo.org/mailman/listinfo/postgis-users]</a><br>
<br>
_______________________________________________<br>
postgis-users mailing list<br>
<a href="mailto:postgis-users@lists.osgeo.org" target="_blank">postgis-users@lists.osgeo.org</a>[mailto:<a href="mailto:postgis-users@lists.osgeo.org" target="_blank">postgis-users@lists.osgeo.org</a>]<br>
<a href="https://lists.osgeo.org/mailman/listinfo/postgis-users" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/postgis-users</a><br>
<br>
 <br>
<br>
 <br>
_______________________________________________ postgis-users mailing list <a href="mailto:postgis-users@lists.osgeo.org" target="_blank">postgis-users@lists.osgeo.org</a> <a href="https://lists.osgeo.org/mailman/listinfo/postgis-users%5Bhttps://lists.osgeo.org/mailman/listinfo/postgis-users%5D" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/postgis-users[https://lists.osgeo.org/mailman/listinfo/postgis-users]</a><br>
 <br>
 <br>
_______________________________________________<br>
postgis-users mailing list<br>
<a href="mailto:postgis-users@lists.osgeo.org" target="_blank">postgis-users@lists.osgeo.org</a><br>
<a href="https://lists.osgeo.org/mailman/listinfo/postgis-users" rel="noreferrer" target="_blank">https://lists.osgeo.org/mailman/listinfo/postgis-users</a><br>
</blockquote></div>