stud/I/MTM/task4-straipsnis/init.sql

37 lines
1.2 KiB
MySQL
Raw Permalink Normal View History

2019-10-26 15:12:18 +03:00
-- schema
CREATE TABLE airports (
gid SERIAL NOT NULL PRIMARY KEY,
name TEXT,
city TEXT,
country TEXT,
iata TEXT,
icao TEXT,
geom GEOMETRY,
latitude DOUBLE PRECISION,
longitude DOUBLE PRECISION,
altitude DOUBLE PRECISION,
timezone TEXT,
dst TEXT,
tz TEXT,
type TEXT,
source TEXT,
2019-10-26 15:24:58 +03:00
CONSTRAINT enforce_dims_geom CHECK (st_ndims(geom) = 3),
2019-10-26 15:12:18 +03:00
CONSTRAINT enforce_geotype_geom CHECK (geometrytype(geom) = 'POINT'::text OR geom IS NULL),
CONSTRAINT enforce_srid_geom CHECK (st_srid(geom) = 4326)
);
2019-10-26 15:31:06 +03:00
-- create index for faster spatial lookups
CREATE INDEX idx_geom ON airports USING GIN (geom);
2019-10-26 15:12:18 +03:00
-- import data from airports.dat
\copy airports(gid, name, city, country, iata, icao, latitude, longitude, altitude, timezone, dst, tz, type, source) FROM 'airports.dat' DELIMITERS ',' CSV;
2019-10-26 15:24:58 +03:00
-- put lat/lon/altitude to the "real" geom field
2019-10-26 15:12:18 +03:00
UPDATE airports
2019-10-26 15:24:58 +03:00
SET geom = ST_SetSRID(ST_MakePoint(longitude, latitude, altitude * 0.3048),4326);
ALTER TABLE airports DROP COLUMN latitude;
ALTER TABLE airports DROP COLUMN longitude;
ALTER TABLE airports DROP COLUMN altitude;
ALTER TABLE airports DROP COLUMN type;
ALTER TABLE airports DROP COLUMN source;