Building a PostGIS Docker Container
In this article, I will introduce how to set up PostGIS using Docker. By utilizing the official Docker image provided below, you can easily launch a PostgreSQL Docker container with PostGIS pre-installed.
To start the PostGIS container, execute the following command:
$ docker run --name my-postgis -e POSTGRES_PASSWORD=mysecretpassword -d postgis/postgis
To enter the container and connect to PostgreSQL, use the following command:
bash
$ docker exec -it my-postgis psql -U postgres
postgres=#
Now, you have successfully connected to PostgreSQL.
PostGIS Operations
Let's perform some basic operations with PostGIS. First, we'll create an airports
table.
bash
postgres=# create table airports
( id serial primary key,
name text,
iata_code text,
location geography(POINT, 4326)
);
CREATE TABLE
Next, let's insert data into the airports
table.
bash
postgres=# insert into airports (name, iata_code, location)
values ( 'Haneda Airport' , 'HND' , ST_GeogFromText('SRID=4326;POINT(139.7776446 35.5493975)') );
INSERT 0 1
Now, let's check the airports
table.
bash
postgres=# select * from airports;
id | name | iata_code | location
----+----------------+-----------+----------------------------------------------------
1 | Haneda Airport | HND | 0101000020E6100000279DED76E2786140888043A852C64140
(1 row)
Let's try converting the location
column to the POINT type.
bash
postgres=# select id, name, iata_code, ST_AsText(location) from airports;
id | name | iata_code | st_astext
----+----------------+-----------+-------------------------------
1 | Haneda Airport | HND | POINT(139.7776446 35.5493975)
(1 row)
Lastly, let's calculate the distance from the point (139.00 35.00)
.
bash
postgres=# select ST_Distance(
location,
ST_GeogFromText('SRID=4326;POINT(139.00 35.00)')
) as distance from airports;
distance
----------------
93386.17699288
(1 row)
References
AlloyDB
Amazon Cognito
Amazon EC2
Amazon ECS
Amazon QuickSight
Amazon RDS
Amazon Redshift
Amazon S3
API
Autonomous Vehicle
AWS
AWS API Gateway
AWS Chalice
AWS Control Tower
AWS IAM
AWS Lambda
AWS VPC
BERT
BigQuery
Causal Inference
ChatGPT
Chrome Extension
CircleCI
Classification
Cloud Functions
Cloud IAM
Cloud Run
Cloud Storage
Clustering
CSS
Data Engineering
Data Modeling
Database
dbt
Decision Tree
Deep Learning
Descriptive Statistics
Differential Equation
Dimensionality Reduction
Discrete Choice Model
Docker
Economics
FastAPI
Firebase
GIS
git
GitHub
GitHub Actions
Google
Google Cloud
Google Search Console
Hugging Face
Hypothesis Testing
Inferential Statistics
Interval Estimation
JavaScript
Jinja
Kedro
Kubernetes
LightGBM
Linux
LLM
Mac
Machine Learning
Macroeconomics
Marketing
Mathematical Model
Meltano
MLflow
MLOps
MySQL
NextJS
NLP
Nodejs
NoSQL
ONNX
OpenAI
Optimization Problem
Optuna
Pandas
Pinecone
PostGIS
PostgreSQL
Probability Distribution
Product
Project
Psychology
Python
PyTorch
QGIS
R
ReactJS
Regression
Rideshare
SEO
Singer
sklearn
Slack
Snowflake
Software Development
SQL
Statistical Model
Statistics
Streamlit
Tabular
Tailwind CSS
TensorFlow
Terraform
Transportation
TypeScript
Urban Planning
Vector Database
Vertex AI
VSCode
XGBoost