jlpoole Guru


Joined: 01 Nov 2005 Posts: 491 Location: Salem, OR
|
Posted: Thu Dec 19, 2024 12:46 pm Post subject: PostgreSQL/PostGIS And SFCGAL |
|
|
There exists an extension to PostGIS, postgis_sfcgal, which is not explicitly supported by Gentoo. The postgis_sfcgal extension provides access to a system's installation of SFCGAL, "Simple Features for CGAL," where "CGAL" is the Computational Geometry Algorithms Library. Thus, SFCGAL provides a bridge that allows the use of advanced geometric operations compliant with the Simple Features standard on top of CGAL. In other words, SFCGAL is a library which provides advanced 2D and 3D spatial functions. Gentoo does not offer SFCGAL as a package, though Bug 653086 "sci-geosciences/sfcgal - new package" tracks a request.
By "explicit support" I mean that there is not a USE flag or any mention of this extension. Yet, the PostGIS configuration file for building PostGIS recognizes (see Chapter 8. SFCGAL Functions Reference" of the PostGIS 3.5.1dev Manual ) and will install support for SFCGAL if SFCGAL is present on the system. See also https://postgis.net/docs/manual-3.0/reference.html#reference_sfcgal.
I thought I would want to be able to define a 3 dimensional object in space on a map and then perform queries against the object to determine if a 3 dimensional positions, e.g. latitude, longitude, and elevation, fall within object. I'm tracking aircraft. It turns out in PostGIS, you can have 3 dimensional objects such as a six-sided box, but if your try to query whether an object is "within" the box, you are really performing a 2 dimensional query or a query of whether an object is within a face of the box. Since my application concerns aircraft and defining whether an aircraft is within a three dimensional "approach" to a runway. I don't want to be concerned with jets flying 5,000 or more feet above, I only want to identify those which are within certain altitudes and which the "Glide Slope" of the approach path. I learned that PostGIS differentiates between box-like structures containing six faces and "solids" and that SFCGAL is what I would need to define a solid area and then perform queries if an aircraft's track goes through the solid. As I went down this trail I learned the following:
You can have an instance of Gentoo's Postgis and have it extended to use the SFCGAL libraries by doing the following:
1) Download and install SFCGAL. I use /usr/local/src to stage foreign projects.
Code: | cd /usr/local/src
wget https://gitlab.com/SFCGAL/SFCGAL/-/archive/v2.0.0/SFCGAL-v2.0.0.tar.gz
tar -xf SFCGAL-v2.0.0.tar.gz
time cmake -S . -B build && time cmake --build build |
Building takes several minutes, e.g. more than 10?, on a Ryzen 7950.
Then perform an install in SFCGAL's default location.
Code: | sudo cmake --install build |
I have staged permanently on PasteBin the 141 line install session showing what is installed where. PostGIS will, during the "config" phase of a build, search for any installation of SFGAL on the system, so I re-installed dev-db/postgis on my Gentoo system, and PostGIS's configuration script determined I had SFCGAL installed and included it in the build.
However, the emerge session noted a warning:
Quote: | * QA Notice: Unresolved soname dependencies:
*
* /usr/lib64/postgresql-16/lib64/postgis_sfcgal-3.so: libSFCGAL.so.2
* |
This "Unresolved" issue is easily overcome by creating a soft link within the postgresql's lib64 subdirectory (if you have several versions of postgresql, you may have to go through the re-install and soft link creation).
Code: |
ln -s /usr/local/lib64/libSFCGAL.so.2 /usr/lib64/postgresql-16/lib64/libSFCGAL.so.2 |
Then restart PostgreSQL and in a psql session install the extension:
Code: | CREATE EXTENSION IF NOT EXISTS postgis_sfcgal; |
You can use the above CREATE command again to confirm:
Code: |
mydb=# CREATE EXTENSION IF NOT EXISTS postgis_sfcgal;
NOTICE: extension "postgis_sfcgal" already exists, skipping
CREATE EXTENSION
mydb=# |
You can also verify installation with:
Code: |
SELECT PostGIS_Full_Version();
|
Example, see "SFCGAL="SFCGAL 2.0.0, CGAL 5.6, BOOST 1.84.0"' below:
Code: |
mydb=# SELECT PostGIS_Full_Version();
postgis_full_version
POSTGIS="3.5.0 d2c3ca4" [EXTENSION] PGSQL="160" GEOS="3.12.1-CAPI-1.18.1" SFCGAL="SFCGAL 2.0.0, CGAL 5.6, BOOST 1.84.0" PROJ="9.4.1 NETWORK_ENABLED=OFF URL_ENDPOINT=https://cdn.proj.org USER_WRITABLE_DIRECTORY=/var/lib/postgresql/.local/share/proj DATABASE_PATH=/usr/share/proj/proj.db" (compiled against PROJ 9.12.1) GDAL="GDAL 3.9.1, released 2024/06/22" LIBXML="2.12.9" LIBJSON="0.18" LIBPROTOBUF="1.5.0" WAGYU="0.5.0 (Internal)" RASTER (raster procs from "3.4.2 c19ce56" need upgrade)
(1 row)
mydb=# |
As for testing and trying out queries, see the Official PostGIS documentation for SFCGAL where some examples are provided. See also: https://github.com/postgis/postgis/blob/master/regress/run_test.pl
(ChatGPT 4o users: ChatGPT is not up to the task for mastering 3D queries as of 12/18/2024, you're better off using the examples in the documentation) |
|