WIP schemas
This commit is contained in:
parent
4682cdb31d
commit
e14cf80e1a
0
MTM/task4-straipsnis/import.sql
Normal file
0
MTM/task4-straipsnis/import.sql
Normal file
28
MTM/task4-straipsnis/init.sql
Normal file
28
MTM/task4-straipsnis/init.sql
Normal file
@ -0,0 +1,28 @@
|
||||
-- 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,
|
||||
CONSTRAINT enforce_dims_geom CHECK (st_ndims(geom) = 2),
|
||||
CONSTRAINT enforce_geotype_geom CHECK (geometrytype(geom) = 'POINT'::text OR geom IS NULL),
|
||||
CONSTRAINT enforce_srid_geom CHECK (st_srid(geom) = 4326)
|
||||
);
|
||||
|
||||
-- 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;
|
||||
|
||||
-- put lat/lon to the real GIS "geom" field
|
||||
UPDATE airports
|
||||
SET geom = ST_SetSRID(ST_Point(longitude, latitude),4326);
|
@ -5,12 +5,8 @@ if [[ $1 == init ]]; then
|
||||
mkdir -p db && initdb db
|
||||
pg_ctl -D db -l db/logfile start
|
||||
|
||||
psql postgres \
|
||||
-c 'CREATE DATABASE airportgames;' \
|
||||
-c 'CREATE USER airportgames;' \
|
||||
-c 'GRANT ALL PRIVILEGES ON DATABASE airportgames to airportgames;'
|
||||
psql -d airportgames \
|
||||
-c 'CREATE EXTENSION postgis'
|
||||
psql -c 'CREATE EXTENSION postgis;'
|
||||
psql < init.sql
|
||||
fi
|
||||
|
||||
if [[ $1 == start ]]; then
|
||||
|
@ -9,6 +9,11 @@ CREATE TABLE airports (
|
||||
latitude DOUBLE PRECISION,
|
||||
longitude DOUBLE PRECISION,
|
||||
altitude DOUBLE PRECISION,
|
||||
timezone TEXT,
|
||||
dst TEXT,
|
||||
tz TEXT,
|
||||
type TEXT,
|
||||
source TEXT,
|
||||
CONSTRAINT enforce_dims_geom CHECK (st_ndims(geom) = 2),
|
||||
CONSTRAINT enforce_geotype_geom CHECK (geometrytype(geom) = 'POINT'::text OR geom IS NULL),
|
||||
CONSTRAINT enforce_srid_geom CHECK (st_srid(geom) = 4326)
|
||||
|
@ -37,15 +37,14 @@ Susidarys iš kelių dalių:
|
||||
- Duomenų importavimas.
|
||||
- Užklausos.
|
||||
|
||||
Duomenų bazės sukūrimui galite naudoti skriptą:
|
||||
Oro uostų informaciją gausime iš [openflights.org][3]; `airports.dat` failas
|
||||
jūsų patogumui yra šioje repositorijoje. Sukurkime ir importuokime duomenų bazę
|
||||
(skriptai paprasti, rekomenduoju peržiūrėti):
|
||||
|
||||
```
|
||||
./managedb init
|
||||
psql airportgames < init.sql
|
||||
$ ./managedb init
|
||||
```
|
||||
|
||||
Atsisiųskime oro uostų informaciją [airports.dat][3] faile ir importuokime į duomenų bazę:
|
||||
|
||||
|
||||
|
||||
[1]: https://en.wikipedia.org/wiki/International_Air_Transport_Association_code
|
||||
|
Loading…
Reference in New Issue
Block a user