Message posté par : Christophe BADOL
----------------------------------------
Bonjour,
J'ai beaucoup de tables en Lambert 93 avec 9 chiffres après la virgule.
J'avais subodoré que réduire cette précision inutile ferait gagner de la place sur le
disque, augmenterait un peu la vitesse d'affichage et réduirait le temps des
géotraitements.
J'ai questionné chatGPT sur le sujet (qui n'a pas été très bon il faut le
reconnaitre) :
https://chatgpt.com/share/6714c630-6270-800a-83d0-658648c01dbe
Je vous livre mes comparaisons entre
- ST_ReducePrecision à 0.01
- ST_SnapToGrid à 0.01
- ST_QuantizeCoordinates à 0
---- Situation initiale (en Lambert93):
DROP TABLE IF EXISTS public.l_bati_agrege_pepci_006_2023;
CREATE TABLE public.l_bati_agrege_pepci_006_2023
(LIKE p_enveloppe_bati_2023.l_bati_agrege_pepci_006_2023 INCLUDING ALL);
ALTER TABLE IF EXISTS public.l_bati_agrege_pepci_006_2023
CLUSTER ON l_bati_agrege_pepci_006_2023_geom_idx;
INSERT INTO public.l_bati_agrege_pepci_006_2023
SELECT * FROM p_enveloppe_bati_2023.l_bati_agrege_pepci_006_2023;
--> Updated Rows 305707
SELECT
pg_size_pretty(pg_total_relation_size('public.l_bati_agrege_pepci_006_2023'));
--> 100 MB
---- On vacuum
VACUUM FULL public.l_bati_agrege_pepci_006_2023;
SELECT
pg_size_pretty(pg_total_relation_size('public.l_bati_agrege_pepci_006_2023'));
--> 97 MB
--- On réindexe
REINDEX TABLE public.l_bati_agrege_pepci_006_2023;
SELECT
pg_size_pretty(pg_total_relation_size('public.l_bati_agrege_pepci_006_2023'));
--> 97 MB
---- Test 1 : ST_ReducePrecision à 0.01
DROP TABLE IF EXISTS public.l_bati_agrege_pepci_006_2023_t1;
CREATE TABLE public.l_bati_agrege_pepci_006_2023_t1
(LIKE p_enveloppe_bati_2023.l_bati_agrege_pepci_006_2023 INCLUDING ALL);
ALTER TABLE IF EXISTS public.l_bati_agrege_pepci_006_2023_t1
CLUSTER ON l_bati_agrege_pepci_006_2023_t1_geom_idx;
INSERT INTO public.l_bati_agrege_pepci_006_2023_t1
SELECT * FROM p_enveloppe_bati_2023.l_bati_agrege_pepci_006_2023;
--> Updated Rows 305707
UPDATE public.l_bati_agrege_pepci_006_2023_t1
SET geom= ST_ReducePrecision(geom, 0.01)
WHERE ST_IsValid(geom)
-- Vérifie que la simplification ne change pas le nombre de polygones ou de points
AND ST_GeometryType(geom) = ST_GeometryType(ST_ReducePrecision(geom, 0.01))
-- Vérifie que la simplification ne vide pas la géographie
AND ST_Area(ST_ReducePrecision(geom,0.01)) > 0;
--> Updated Rows 305699
SELECT
pg_size_pretty(pg_total_relation_size('public.l_bati_agrege_pepci_006_2023_t1'));
--> 194 MB
---- On optimise
VACUUM FULL public.l_bati_agrege_pepci_006_2023_t1;
REINDEX TABLE public.l_bati_agrege_pepci_006_2023_t1;
SELECT
pg_size_pretty(pg_total_relation_size('public.l_bati_agrege_pepci_006_2023_t1'));
--> 196 MB
---- Test 2 : ST_SnapToGrid à 0.01
DROP TABLE IF EXISTS public.l_bati_agrege_pepci_006_2023_t2;
CREATE TABLE public.l_bati_agrege_pepci_006_2023_t2
(LIKE p_enveloppe_bati_2023.l_bati_agrege_pepci_006_2023 INCLUDING ALL);
ALTER TABLE IF EXISTS public.l_bati_agrege_pepci_006_2023_t2
CLUSTER ON l_bati_agrege_pepci_006_2023_t2_geom_idx;
INSERT INTO public.l_bati_agrege_pepci_006_2023_t2
SELECT * FROM p_enveloppe_bati_2023.l_bati_agrege_pepci_006_2023;
--> Updated Rows 305707
UPDATE public.l_bati_agrege_pepci_006_2023_t2
SET geom= ST_SnapToGrid(geom, 0.01)
WHERE ST_IsValid(geom) AND ST_IsValid(ST_SnapToGrid(geom, 0.01))
-- Vérifie que la simplification ne change pas le nombre de polygones ou de points
AND ST_GeometryType(geom) = ST_GeometryType(ST_SnapToGrid(geom, 0.01))
-- Vérifie que la simplification ne vide pas la géographie
AND ST_Area(ST_SnapToGrid(geom, 0.01)) > 0;
--> Updated Rows 305311
SELECT
pg_size_pretty(pg_total_relation_size('public.l_bati_agrege_pepci_006_2023_t2'));
--> 195 MB
---- On optimise
VACUUM FULL public.l_bati_agrege_pepci_006_2023_t2;
REINDEX TABLE public.l_bati_agrege_pepci_006_2023_t2;
SELECT
pg_size_pretty(pg_total_relation_size('public.l_bati_agrege_pepci_006_2023_t2'));
--> 195 MB
--- Test 3 : ST_QuantizeCoordinates
DROP TABLE IF EXISTS public.l_bati_agrege_pepci_006_2023_t3;
CREATE TABLE public.l_bati_agrege_pepci_006_2023_t3
(LIKE p_enveloppe_bati_2023.l_bati_agrege_pepci_006_2023 INCLUDING ALL);
ALTER TABLE IF EXISTS public.l_bati_agrege_pepci_006_2023_t3
CLUSTER ON l_bati_agrege_pepci_006_2023_t3_geom_idx;
INSERT INTO public.l_bati_agrege_pepci_006_2023_t3
SELECT * FROM p_enveloppe_bati_2023.l_bati_agrege_pepci_006_2023;
--> Updated Rows 305707
UPDATE public.l_bati_agrege_pepci_006_2023_t3
SET geom = ST_QuantizeCoordinates(geom, 0)
WHERE ST_IsValid(geom) AND ST_IsValid(ST_QuantizeCoordinates(geom, 0))
-- Vérifie que la simplification ne change pas le nombre de polygones ou de points
AND ST_GeometryType(geom) = ST_GeometryType(ST_QuantizeCoordinates(geom, 0))
-- Vérifie que la simplification ne vide pas la géographie
AND ST_Area(ST_QuantizeCoordinates(geom, 0)) > 0;
--> Updated Rows 300855
SELECT
pg_size_pretty(pg_total_relation_size('public.l_bati_agrege_pepci_006_2023_t3'));
--> 191 MB
---- On optimise
VACUUM FULL public.l_bati_agrege_pepci_006_2023_t3;
REINDEX TABLE public.l_bati_agrege_pepci_006_2023_t3;
SELECT
pg_size_pretty(pg_total_relation_size('public.l_bati_agrege_pepci_006_2023_t3'));
--> 192 MB
Si vous avez un semblant d'explication, je veux bien car je sèche un peu. Ne pas
gagner de la place car la géométrie est stockée d'une même manière quelle que soit sa
précision… je peux comprendre.
Mais doubler la taille initiale… j'étais loin de m'en douter.
d'avance merci à celles et ceux qui prendront le temps de me lire et de me répondre.
----------------------------------------
Le message est situé
https://georezo.net/forum/viewtopic.php?pid=369900#p369900
Pour y répondre : geobd(a)ml.georezo.net ou reply de votre messagerie
Pour vous désabonner connectez-vous sur le forum puis Profil / Abonnement
--
Association GeoRezo - le portail géomatique
https://georezo.net