From 8b5b46ae6712fafd8f7c81ffa9a81d8c815e976d Mon Sep 17 00:00:00 2001 From: Anastasia Alexandrova Date: Mon, 3 Jul 2023 09:36:34 +0200 Subject: [PATCH] DISTPG-570 Updated postgis docs (#413) modified: docs/solutions/postgis-deploy.md modified: docs/solutions/postgis-testing.md modified: mkdocs-base.yml --- docs/solutions/postgis-deploy.md | 27 +++++++++++++++++---------- docs/solutions/postgis-testing.md | 6 +++--- mkdocs-base.yml | 8 ++++---- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/docs/solutions/postgis-deploy.md b/docs/solutions/postgis-deploy.md index 2d17bf700..7bf60540d 100644 --- a/docs/solutions/postgis-deploy.md +++ b/docs/solutions/postgis-deploy.md @@ -5,11 +5,12 @@ The following document provides guidelines how to install PostGIS and how to run ## Preconditions 1. We assume that you have the basic knowledge of spatial data, GIS (Geographical Information System) and of shapefiles. -2. You need to acquire spatial data. For the following examples, we'll use the same [data set](https://s3.amazonaws.com/s3.cleverelephant.ca/postgis-workshop-2020.zip) as is used in [PostGIS tutorial](http://postgis.net/workshops/postgis-intro/) +2. For uploading the spatial data and querying the database, we use the same [data set](https://s3.amazonaws.com/s3.cleverelephant.ca/postgis-workshop-2020.zip) as is used in [PostGIS tutorial](http://postgis.net/workshops/postgis-intro/). + ## Install PostGIS -1. Enable Percona repository. +1. Enable Percona repository As other components of Percona Distribution for PostgreSQL, PostGIS is available from Percona repositories. Use the [`percona-release`](https://docs.percona.com/percona-software-repositories/installing.html) repository management tool to enable the repository. @@ -94,17 +95,17 @@ The following document provides guidelines how to install PostGIS and how to run FROM pg_available_extensions WHERE name LIKE 'postgis%' or name LIKE 'address%'; ``` -3. Create a database and a schema to store your data. A schema is a container that logically segments objects (tables, functions, views, and so on) for better management. Run the following commands from the `psql` terminal +3. Create a database and a schema for this database to store your data. A schema is a container that logically segments objects (tables, functions, views, and so on) for better management. Run the following commands from the `psql` terminal: ```sql CREATE database nyc; + \c nyc; CREATE SCHEMA gis; ``` -4. To make PostGIS functions and operations work, you need to enable the `postgis` extension. From the `psql` terminal, switch to the database you created and run the following command: +4. To make PostGIS functions and operations work, you need to enable the `postgis` extension. Make sure you are connected to the database you created earlier and run the following command: ```sql - \c nyc; CREATE EXTENSION postgis; ``` @@ -114,19 +115,25 @@ The following document provides guidelines how to install PostGIS and how to run SELECT postgis_full_version(); ``` - The output should be similar to the following: + The output should resemble the following: ```{.sql .no-copy} postgis_full_version ----------------------------------------------------------------------------------------------------------------------------------------------------------------- - POSTGIS="3.3.3dev 0" [EXTENSION] PGSQL="140" GEOS="3.10.2-CAPI-1.16.0" PROJ="8.2.1" LIBXML="2.9.13" LIBJSON="0.15" LIBPROTOBUF="1.3.3" WAGYU="0.5.0 (Internal)" + POSTGIS="3.3.3" [EXTENSION] PGSQL="140" GEOS="3.10.2-CAPI-1.16.0" PROJ="8.2.1" LIBXML="2.9.13" LIBJSON="0.15" LIBPROTOBUF="1.3.3" WAGYU="0.5.0 (Internal)" ``` ## Upload spatial data to PostgreSQL PostGIS provides the `shp2pgsql` command line utility that converts the binary data from shapefiles into the series of SQL commands and loads them into the database. -1. From the folder where the `.shp` files are located, execute the following command and replace the `dbname` value with the name of your database: +1. For testing purposes, download the sample data set: + + ```{.bash data-prompt="$"} + $ curl -LO https://s3.amazonaws.com/s3.cleverelephant.ca/postgis-workshop-2020.zip + ``` + +2. Unzip the archive and from the folder where the `.shp` files are located, execute the following command and replace the `dbname` value with the name of your database: ```{.bash data-prompt="$"} shp2pgsql \ @@ -147,7 +154,7 @@ PostGIS provides the `shp2pgsql` command line utility that converts the binary d * `nyc_streets` is the table name to create in the database * `dbname=nyc` is the database name -2. Check the uploaded data +3. Check the uploaded data ```sql \d nyc_streets; @@ -165,4 +172,4 @@ PostGIS provides the `shp2pgsql` command line utility that converts the binary d "nyc_streets_geom_idx" gist (geom) ``` -3. Repeat the command to upload other shapefiles in the data set: `nyc_census_blocks`, `nyc_neighborhoods`, `nyc_subway_stations` \ No newline at end of file +4. Repeat the command to upload other shapefiles in the data set: `nyc_census_blocks`, `nyc_neighborhoods`, `nyc_subway_stations` \ No newline at end of file diff --git a/docs/solutions/postgis-testing.md b/docs/solutions/postgis-testing.md index ec9cf19c7..4fb0be997 100644 --- a/docs/solutions/postgis-testing.md +++ b/docs/solutions/postgis-testing.md @@ -23,7 +23,7 @@ population To get the answer we will use the `ST_Area` function that returns the areas of polygons. ```sql -SELECT ST_Area(geom) / 1000 +SELECT ST_Area(geom) / 1000000 FROM nyc_neighborhoods WHERE name = 'Central Park'; ``` @@ -33,11 +33,11 @@ Output: ```{.sql .no-copy} st_area -------------------- - 3519.8365965413293 + 3.5198365965413293 (1 row) ``` -By default, the output is given in square meters. To get the value in square kilometers, divide it by 1000. +By default, the output is given in square meters. To get the value in square kilometers, divide it by 1 000 000. ## *How long is Columbus Circle?* diff --git a/mkdocs-base.yml b/mkdocs-base.yml index e84a71c0d..fe6172092 100644 --- a/mkdocs-base.yml +++ b/mkdocs-base.yml @@ -186,10 +186,10 @@ nav: - solutions/backup-recovery.md - solutions/dr-pgbackrest-setup.md - Spatial data handling: - - Overview: solutions/postgis.md - - Deployment: solutions/postgis-deploy.md - - Query spatial data: solutions/postgis-testing.md - #- Upgrade spatial database: solutions/postgis-upgrade.md + - Overview: solutions/postgis.md + - Deployment: solutions/postgis-deploy.md + - Query spatial data: solutions/postgis-testing.md + - Upgrade spatial database: solutions/postgis-upgrade.md - LDAP authentication: - ldap.md - Uninstall: