CREATE EXTENSION postgis;
SELECT * FROM spatial_ref_sys WHERE srid = 5514;
INSERT, COPY, shp2pgsql
CREATE TABLE cities (
name varchar PRIMARY KEY,
x float NOT NULL,
y float NOT NULL
);
úplně obyčejná tabulka
INSERT INTO cities (name, x, y)
VALUES ('Brno', 16.62, 49.2);
s úplně obyčejným záznamem
SELECT AddGeometryColumn('cities', 'geom', 4326, 'point', 2); // #1
ALTER TABLE cities ADD COLUMN geom geometry(Point,4326); // #2
už vůbec není obyčejná
UPDATE cities
SET geom = ST_MakePoint(x, y);
proč to sakra nefunguje?
ERROR: Geometry SRID (0) does not match column SRID (4326)
UPDATE cities
SET geom = ST_SetSRID(ST_MakePoint(x, y), 4326);
SELECT geom FROM cities; // wtf?
SELECT ST_AsText(geom) FROM cities; // aha!
SELECT ST_AsGML(geom) FROM cities; // wtf?
SELECT ST_AsGeoJson(geom) FROM cities; // wtf?
SELECT ST_AsLatLonText(geom) FROM cities; // aha!
TRUNCATE TABLE cities;
INSERT INTO cities (name, x, y) VALUES ('Brno',16.62,49.2);
INSERT INTO cities (name, x, y) VALUES ('Olomouc',17.250833,49.593889);
INSERT INTO cities (name, x, y) VALUES ('Praha',14.4211,50.0872);
INSERT INTO cities (name, x, y) VALUES ('Pardubice',15.77916,50.03861);
INSERT INTO cities (name, x, y) VALUES ('Hradec Králové',15.8375,50.211111);
INSERT INTO cities (name, x, y) VALUES ('Ostrava',18.292778,49.835556);
INSERT INTO cities (name, x, y) VALUES ('Plzeň',13.3775,49.746944);
INSERT INTO cities (name, x, y) VALUES ('České Budějovice',14.474722,48.974722);
INSERT INTO cities (name, x, y) VALUES ('Liberec',15.06666,50.71666);
INSERT INTO cities (name, x, y) VALUES ('Jablonec',15.171111,50.724167);
SELECT * FROM cities;
A co geometrie?
UPDATE cities SET
geom = ST_SetSRID(ST_MakePoint(x, y), 4326);
CREATE INDEX cities_idx ON cities USING GIST (geom);