Skip to content

Commit

Permalink
DISTPG-570 Updated postgis docs (#413)
Browse files Browse the repository at this point in the history
modified:   docs/solutions/postgis-deploy.md
	modified:   docs/solutions/postgis-testing.md
	modified:   mkdocs-base.yml
  • Loading branch information
nastena1606 authored Jul 3, 2023
1 parent 2309e26 commit 8b5b46a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
27 changes: 17 additions & 10 deletions docs/solutions/postgis-deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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;
```

Expand All @@ -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 \
Expand All @@ -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;
Expand All @@ -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`
4. Repeat the command to upload other shapefiles in the data set: `nyc_census_blocks`, `nyc_neighborhoods`, `nyc_subway_stations`
6 changes: 3 additions & 3 deletions docs/solutions/postgis-testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -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';
```
Expand All @@ -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?*

Expand Down
8 changes: 4 additions & 4 deletions mkdocs-base.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 8b5b46a

Please sign in to comment.