postgis: add withSfcgal option

This commit is contained in:
Augustin Trancart
2025-01-17 09:14:55 +01:00
parent 459db35f4a
commit 007496f756
+34 -10
View File
@@ -26,6 +26,8 @@
automake,
libtool,
which,
sfcgal,
withSfcgal ? false,
}:
let
@@ -47,15 +49,18 @@ buildPostgresqlExtension (finalAttrs: {
hash = "sha256-wh7Lav2vnKzGWuSvvMFvAaGV7ynD+KgPsFUgujdtzlA=";
};
buildInputs = [
libxml2
geos
proj
gdal
json_c
protobufc
pcre2.dev
] ++ lib.optional stdenv.hostPlatform.isDarwin libiconv;
buildInputs =
[
libxml2
geos
proj
gdal
json_c
protobufc
pcre2.dev
]
++ lib.optional stdenv.hostPlatform.isDarwin libiconv
++ lib.optional withSfcgal sfcgal;
nativeBuildInputs = [
autoconf
automake
@@ -87,7 +92,7 @@ buildPostgresqlExtension (finalAttrs: {
"--with-gdalconfig=${gdal}/bin/gdal-config"
"--with-jsondir=${json_c.dev}"
"--disable-extension-upgrades-install"
];
] ++ lib.optional withSfcgal "--with-sfcgal=${sfcgal}/bin/sfcgal-config";
makeFlags = [
"PERL=${perl}/bin/perl"
@@ -130,6 +135,25 @@ buildPostgresqlExtension (finalAttrs: {
end$$;
-- st_makepoint goes through c code
select st_makepoint(1, 1);
''
+ lib.optionalString withSfcgal ''
CREATE EXTENSION postgis_sfcgal;
do $$
begin
if postgis_sfcgal_version() <> '${sfcgal.version}' then
raise '"%" does not match "${sfcgal.version}"', postgis_sfcgal_version();
end if;
end$$;
CREATE TABLE geometries (
name varchar,
geom geometry(PolygonZ) NOT NULL
);
INSERT INTO geometries(name, geom) VALUES
('planar geom', 'PolygonZ((1 1 0, 1 2 0, 2 2 0, 2 1 0, 1 1 0))'),
('nonplanar geom', 'PolygonZ((1 1 1, 1 2 -1, 2 2 2, 2 1 0, 1 1 1))');
SELECT name from geometries where cg_isplanar(geom);
'';
};