prostorová nadstavba PostgreSQL
CREATE EXTENSION postgis;
a je to!
vektory
rastry
topologie
routování
projekce
TIN
3D data
výstupy
standards for the win
SELECT * FROM spatial_ref_sys WHERE srid = 5514; -- A co Křovák?
INSERT, COPY, shp2pgsql
geometry (rovina) × geography (sféra)
CREATE TABLE cities (
name varchar PRIMARY KEY,
x float NOT NULL,
y float NOT NULL
);
INSERT INTO cities (name, x, y)
VALUES ('Brno', 16.62, 49.2);
ALTER TABLE cities ADD COLUMN geom geometry(Point,4326);
UPDATE cities
SET geom = ST_MakePoint(x, y);
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;
UPDATE cities SET geom = ST_SetSRID(ST_MakePoint(x, y), 4326);
INSERT, COPY, ogr2ogr
QGIS -> Databáze -> SPIT -> připojit DB -> vybrat soubor -> OK
CREATE INDEX cities_idx ON cities USING GIST (geom);