APERTO-NOTA

Information ouverte

Créer une grille de point sous PostGIS

Note utilisateur:  / 0
MauvaisTrès bien 

Vous avez besoin de créer une grille de point régulier sous PostGIS ? Le script ci-dessous vous permet de la construire rapidement.

-- Create the function -------------------------
CREATE OR REPLACE FUNCTION create_fishnet() RETURNS void AS
$$
DECLARE
   _x      FLOAT ;
   _y      FLOAT ;
   "query"   text ;
BEGIN
   -- Because we want a step of 0.5 and we can't divide the loop step, we double the size
   FOR i IN -360..360 LOOP
      _x = CAST(i as FLOAT) /2 ;
      FOR j in -180..180 LOOP
         _y = CAST(j as FLOAT) /2 ;
         "query" = 'INSERT INTO gridzone (geom) values
         (ST_GeomFromText (''POINT( ' || _x || ' ' || _y || ')'',4326)
         )' ;
         RAISE NOTICE '%', "query"; -- To debug the query variable
         EXECUTE "query" ;
      END LOOP ;
   END LOOP ;
END ;

$$ LANGUAGE 'PLPGSQL';

 

Vous êtes ici : Home Information Géographique Boite à Outils Créer une grille de point sous PostGIS