User Tools

Site Tools


gis:postgis

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

gis:postgis [2021/11/09 13:06] (current)
Line 1: Line 1:
 +====== Add geometry with X,Y columns ======
  
 +<code>
 +ALTER TABLE your_table ADD COLUMN geom geometry(Point, 4326);
 +UPDATE your_table SET geom = ST_SetSRID(ST_MakePoint(longitude, latitude), 4326);
 +</code>
 +
 +====== Auto regenerate X,Y while inserting ======
 +PostgreSQL 12+
 +
 +<code>
 +ALTER TABLE test ADD COLUMN geom geometry(Point,5514) GENERATED ALWAYS AS (ST_SetSRID(ST_MakePoint(jtsk_x, jtsk_y), 5514)) STORED
 +</code>
 +
 +<code>
 +CREATE TABLE table(
 +    ...
 +    geom geometry(Point,4326) GENERATED ALWAYS AS (ST_SetSRID(ST_MakePoint(longitude, latitude), 4326)) STORED
 +);
 +</code>
gis/postgis.txt · Last modified: 2021/11/09 13:06 by Jan Forman