Skip to content

Commit

Permalink
Create airports table
Browse files Browse the repository at this point in the history
  • Loading branch information
buehner committed Oct 7, 2021
1 parent 95bf624 commit 9a94e05
Show file tree
Hide file tree
Showing 8 changed files with 68,018 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
*.iml
postgis/postgresql_data/

18 changes: 18 additions & 0 deletions docker-compose-demo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,21 @@ services:
volumes:
- ./additional_libs:/opt/additional_libs:Z # by mounting this we can install libs from host on startup
- ./additional_fonts:/opt/additional_fonts:Z # by mounting this we can install fonts from host on startup
postgis:
image: postgis/postgis:14-3.1-alpine
ports:
- 5555:5432
environment:
POSTGRES_USER: geoserver
POSTGRES_PASSWORD: geoserver
# will try to download the latest airports.csv, but may fail if the attribute set of the csv has changed (which sometimes happens)
# set this to false and the shipped airports.csv (mounted below) will be used instead
TRY_TO_USE_LATEST_AIRPORTS: true
volumes:
- ./postgis/postgresql_data:/var/lib/postgresql/data:Z
- ./postgis/init_data/01_download_airports.sh:/docker-entrypoint-initdb.d/11_download_airports.sh # in container we need to be > 10 as in 10 postgis is installed
- ./postgis/init_data/02_create_table.sql:/docker-entrypoint-initdb.d/12_create_table.sql
- ./postgis/init_data/03_copy_from_csv.sql:/docker-entrypoint-initdb.d/13_copy_from_csv.sql
- ./postgis/init_data/04_update_geom.sql:/docker-entrypoint-initdb.d/14_update_geom.sql
- ./postgis/init_data/05_create_index.sql:/docker-entrypoint-initdb.d/15_create_index.sql
- ./postgis/init_data/airports.csv:/docker-entrypoint-initdb.d/airports.csv
6 changes: 6 additions & 0 deletions postgis/init_data/01_download_airports.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

cd # go to home directory for permisson reasons (/var/lib/postgresql)
if [ ! -f /var/lib/postgresql/airports.csv ]; then
wget https://ourairports.com/data/airports.csv # download the file
fi
27 changes: 27 additions & 0 deletions postgis/init_data/02_create_table.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
CREATE TABLE airports
(
gid serial NOT NULL,
ourairports_id integer,
ident varchar(16),
"type" varchar(32),
"name" varchar(255),
lat decimal,
lon decimal,
elevation smallint,
continent varchar(2),
iso_country varchar(2),
iso_region varchar(8),
municipality varchar(64),
scheduled_service boolean,
gps_code varchar(4),
iata_code varchar(3),
local_code varchar(8),
homepage varchar(255),
wikipedia varchar(255),
keywords text,
the_geom geometry(Point, 4326),
CONSTRAINT airports_pkey PRIMARY KEY (gid),
CONSTRAINT enforce_dims_the_geom CHECK (st_ndims(the_geom) = 2),
CONSTRAINT enforce_geotype_geom CHECK (geometrytype(the_geom) = 'POINT'::text OR the_geom IS NULL),
CONSTRAINT enforce_srid_the_geom CHECK (st_srid(the_geom) = 4326)
);
20 changes: 20 additions & 0 deletions postgis/init_data/03_copy_from_csv.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
copy airports(
ourairports_id,
ident,
"type",
"name",
lat,
lon,
elevation,
continent,
iso_country,
iso_region,
municipality,
scheduled_service,
gps_code,
iata_code,
local_code,
homepage,
wikipedia,
keywords
) FROM '/var/lib/postgresql/airports.csv' DELIMITERS ',' CSV HEADER;
1 change: 1 addition & 0 deletions postgis/init_data/04_update_geom.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE airports SET the_geom = ST_GeomFromText('POINT(' || lon || ' ' || lat || ')', 4326);
4 changes: 4 additions & 0 deletions postgis/init_data/05_create_index.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CREATE INDEX airports_the_geom_gist
ON airports
USING gist
(the_geom);
67,940 changes: 67,940 additions & 0 deletions postgis/init_data/airports.csv

Large diffs are not rendered by default.

0 comments on commit 9a94e05

Please sign in to comment.