Skip to content

Commit 67d9bbe

Browse files
authored
Merge pull request #237 from cvvergara/refining-sdg11-chapter
Refs/heads/refining sdg11 chapter
2 parents 4e20d5f + 2aeaed5 commit 67d9bbe

File tree

15 files changed

+666
-588
lines changed

15 files changed

+666
-588
lines changed

.github/dependabot.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "github-actions"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"

.github/scripts/update_locale.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
# ------------------------------------------------------------------------------
3+
# /*PGR-GNU*****************************************************************
4+
# File: update_locale.sh
5+
# Copyright (c) 2021 pgRouting developers
6+
# Mail: project@pgrouting.org
7+
# ------
8+
# This program is free software; you can redistribute it and/or modify
9+
# it under the terms of the GNU General Public License as published by
10+
# the Free Software Foundation; either version 2 of the License, or
11+
# (at your option) any later version.
12+
# This program is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU General Public License for more details.
16+
# You should have received a copy of the GNU General Public License
17+
# along with this program; if not, write to the Free Software
18+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19+
# ********************************************************************PGR-GNU*/
20+
# ------------------------------------------------------------------------------
21+
22+
DIR=$(git rev-parse --show-toplevel)
23+
24+
pushd "${DIR}" > /dev/null || exit 1
25+
26+
mkdir -p build
27+
pushd build > /dev/null || exit 1
28+
cmake -DLOCALE=ON ..
29+
30+
make locale
31+
popd > /dev/null || exit 1
32+
33+
# List all the files that needs to be committed in build/docs/locale_changes.txt
34+
awk '/^Update|^Create/{print $2}' build/docs/locale_changes.txt > build/docs/locale_changes_po.txt # .po files
35+
cp build/docs/locale_changes_po.txt build/docs/locale_changes_po_pot.txt
36+
perl -ne '/\/en\// && print' build/docs/locale_changes_po.txt | \
37+
perl -pe 's/(.*)en\/LC_MESSAGES(.*)/$1pot$2t/' >> build/docs/locale_changes_po_pot.txt # .pot files
38+
39+
# Remove obsolete entries #~ from .po files
40+
bash .github/scripts/remove_obsolete_entries.sh
41+
42+
while read -r f; do git add "$f"; done < build/docs/locale_changes_po_pot.txt
43+
44+
popd > /dev/null || exit 1

.github/workflows/locale.yml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
name: Update Locale
2+
3+
# This action runs:
4+
# - When this file changes
5+
# - When changes on documentation (doc)
6+
# - When is triggered manually
7+
8+
on:
9+
workflow_dispatch:
10+
push:
11+
12+
permissions:
13+
contents: write
14+
15+
jobs:
16+
update-locale:
17+
name: Update Locale
18+
runs-on: ubuntu-latest
19+
20+
strategy:
21+
fail-fast: false
22+
23+
steps:
24+
- name: Checkout repository
25+
uses: actions/checkout@v4
26+
with:
27+
fetch-depth: 0
28+
29+
- name: Get postgres version
30+
run: |
31+
sudo service postgresql start
32+
pgver=$(psql --version | grep -Po '(?<=psql \(PostgreSQL\) )[^;]+(?=\.\d+ \()')
33+
echo "PGVER=${pgver}" >> $GITHUB_ENV
34+
echo "PGIS=3" >> $GITHUB_ENV
35+
36+
- name: Extract branch name and commit hash
37+
run: |
38+
branch=${GITHUB_REF#refs/heads/}
39+
git_hash=$(git rev-parse --short "$GITHUB_SHA")
40+
echo "GIT_HASH=$git_hash" >> $GITHUB_ENV
41+
42+
- name: Add PostgreSQL APT repository
43+
run: |
44+
sudo apt-get install curl ca-certificates gnupg
45+
curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
46+
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ \
47+
$(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
48+
49+
- name: Install python
50+
uses: actions/setup-python@v5
51+
with:
52+
python-version: '3.x'
53+
54+
- name: Install dependencies
55+
run: |
56+
sudo apt-get update
57+
sudo apt-get install -y osm2pgrouting \
58+
postgresql-${PGVER}-postgis-${PGIS} \
59+
postgresql-${PGVER}-postgis-${PGIS}-scripts \
60+
postgresql-${PGVER}-pgrouting
61+
62+
python -m pip install --upgrade pip
63+
pip install -r REQUIREMENTS.txt
64+
pip list
65+
66+
- name: Configure
67+
run: |
68+
service postgresql status
69+
sudo service postgresql start
70+
service postgresql status
71+
sudo -u postgres createdb -p ${POSTGRES_PORT} setup
72+
sudo -u postgres psql -c 'CREATE ROLE "runner" SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN PASSWORD $$runner$$;' -d setup
73+
echo :5432:*:runner:runner >> .pgpass
74+
sudo -u postgres psql -c 'CREATE ROLE "user" SUPERUSER CREATEDB CREATEROLE INHERIT LOGIN PASSWORD $$user$$;' -d setup
75+
echo :5432:*:user:user >> .pgpass
76+
mkdir build
77+
cd build
78+
cmake -DLOCALE=ON ..
79+
env:
80+
POSTGRES_HOST: localhost
81+
POSTGRES_PORT: 5432
82+
POSTGRES_USER: postgres
83+
POSTGRES_PASSWORD: postgres
84+
POSTGRES_DB: setup
85+
86+
- name: Initialize mandatory git config
87+
run: |
88+
git config user.name "github-actions[bot]"
89+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
90+
91+
- name: Update locale
92+
run: |
93+
bash .github/scripts/update_locale.sh
94+
95+
# Add the files, commit and push
96+
git diff --staged --quiet || git commit -m "Update locale: commit ${{ env.GIT_HASH }}"
97+
git restore . # Remove the unstaged changes before rebasing
98+
git push

.github/workflows/ubuntu.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
fail-fast: false
1212

1313
steps:
14-
- uses: actions/checkout@v3
14+
- uses: actions/checkout@v4
1515

1616
- name: Get postgres version
1717
run: |
@@ -28,7 +28,7 @@ jobs:
2828
$(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
2929
3030
- name: Install python
31-
uses: actions/setup-python@v4
31+
uses: actions/setup-python@v5
3232
with:
3333
python-version: '3.x'
3434

.github/workflows/locale-and-website.yml renamed to .github/workflows/website.yml

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
name: Update Locale and Website
1+
name: Update Website
22

33
on:
44
workflow_dispatch:
55
push:
66
branches:
77
- develop
8-
- un-challenge
8+
- main
99

1010
jobs:
1111
update-documentation:
12-
name: Update Locale and Website
12+
name: Update Website
1313
runs-on: ubuntu-latest
1414

1515
strategy:
@@ -44,7 +44,7 @@ jobs:
4444
$(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
4545
4646
- name: Install python
47-
uses: actions/setup-python@v4
47+
uses: actions/setup-python@v5
4848
with:
4949
python-version: '3.x'
5050

@@ -90,25 +90,6 @@ jobs:
9090
git config user.name "github-actions[bot]"
9191
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
9292
93-
- name: Update locale
94-
if: github.ref == 'refs/heads/develop'
95-
run: |
96-
# List all the files that needs to be committed in build/docs/locale_changes.txt
97-
awk '/^Update|^Create/{print $2}' build/docs/locale_changes.txt > tmp && mv tmp build/docs/locale_changes.txt # .po files
98-
cat build/docs/locale_changes.txt | perl -pe 's/(.*)en\/LC_MESSAGES(.*)/$1pot$2t/' >> build/docs/locale_changes.txt # .pot files
99-
cat build/docs/locale_changes.txt
100-
101-
# Remove obsolete entries #~ from .po files
102-
tools/transifex/remove_obsolete_entries.sh
103-
104-
# Add the files, commit and push
105-
for line in `cat build/docs/locale_changes.txt`; do git add "$line"; done
106-
git diff --staged --quiet || git commit -m "Update locale: commit ${{ env.GIT_HASH }}"
107-
git fetch origin develop
108-
git restore . # Remove the unstaged changes before rebasing
109-
git rebase origin/develop
110-
git push origin develop
111-
11293
- name: Update Website
11394
run: |
11495
if [[ "${{ env.BRANCH }}" == "develop" ]]; then

docs/index.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ United Nations Sustainable Development Goals
4949
un_sdg/sdg3-health.rst
5050
un_sdg/sdg7-energy.rst
5151
un_sdg/sdg11-cities.rst
52-
un_sdg/appendix.rst
5352

5453
Interaction with other software
5554
===============================================================================

docs/scripts/un_sdg/sdg11/all_exercises_sdg11.sql

Lines changed: 83 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,107 @@
1-
-- Enumerate all the schemas
2-
\dn
1+
\o create_city1.txt
32

3+
CREATE TABLE bangladesh (
4+
id BIGINT,
5+
name TEXT,
6+
geom geometry,
7+
city_buffer geometry
8+
);
49

5-
-- Show the current search path
6-
SHOW search_path;
10+
\o create_city2.txt
711

8-
-- Set the search path
9-
SET search_path TO waterways,public;
10-
SHOW search_path;
12+
INSERT INTO bangladesh(id, name, geom) VALUES
13+
(5, 'Munshigang', ST_SetSRID(ST_Point(89.1967, 22.2675), 4326));
1114

15+
\o create_city3.txt
16+
17+
UPDATE bangladesh
18+
SET city_buffer = ST_Buffer((geom),0.005)
19+
WHERE name = 'Munshigang';
1220

13-
-- Enumerate all the tables
21+
\o create_city4.txt
22+
\dS+ bangladesh
23+
\o set_path.txt
24+
SET search_path TO waterways,public;
25+
SHOW search_path;
26+
\o get_extensions.txt
27+
\dx
28+
\o get_tables.txt
1429
\dt
15-
\o exercise_1.txt
16-
CREATE TABLE city_vertex (id BIGINT, name TEXT, geom geometry);
17-
INSERT INTO city_vertex(id, name, geom) VALUES (
18-
5,'Munshigang', ST_SetSRID(ST_Point(89.1967,22.2675),4326));
1930
\o exercise_6.txt
31+
2032
SELECT count(*) FROM waterways_ways;
21-
\o exercise_7.txt
22-
DELETE FROM waterways_ways
23-
WHERE osm_id
33+
34+
\o delete1.txt
35+
36+
DELETE FROM waterways_ways
37+
WHERE osm_id
2438
IN (721133202, 908102930, 749173392, 652172284, 126774195, 720395312);
25-
\o exercise_8.txt
26-
-- Add a column for storing the component
27-
ALTER TABLE waterways_ways_vertices_pgr
28-
ADD COLUMN component INTEGER;
2939

30-
ALTER TABLE waterways_ways
31-
ADD COLUMN component INTEGER;
32-
-- Get the Connected Components of Waterways
33-
UPDATE waterways_ways_vertices_pgr SET component = subquery.component
34-
FROM (SELECT * FROM pgr_connectedComponents(
35-
'SELECT gid AS id, source, target, cost, reverse_cost FROM waterways_ways')
36-
) AS subquery
40+
\o delete2.txt
41+
42+
DELETE FROM waterways_ways WHERE osm_id = 815893446;
43+
44+
\o only_connected1.txt
45+
46+
SELECT * INTO waterways.waterways_vertices
47+
FROM pgr_extractVertices(
48+
'SELECT gid AS id, source, target
49+
FROM waterways.waterways_ways ORDER BY id');
50+
51+
\o only_connected2.txt
52+
53+
UPDATE waterways_vertices SET geom = ST_startPoint(the_geom)
54+
FROM waterways_ways WHERE source = id;
55+
56+
UPDATE waterways_vertices SET geom = ST_endPoint(the_geom)
57+
FROM waterways_ways WHERE geom IS NULL AND target = id;
58+
59+
UPDATE waterways_vertices set (x,y) = (ST_X(geom), ST_Y(geom));
60+
61+
\o only_connected3.txt
62+
63+
ALTER TABLE waterways_ways ADD COLUMN component BIGINT;
64+
ALTER TABLE waterways_vertices ADD COLUMN component BIGINT;
65+
66+
\o only_connected4.txt
67+
68+
UPDATE waterways_vertices SET component = c.component
69+
FROM (
70+
SELECT * FROM pgr_connectedComponents(
71+
'SELECT gid as id, source, target, cost, reverse_cost FROM waterways_ways')
72+
) AS c
3773
WHERE id = node;
3874

39-
UPDATE waterways_ways SET component=a.component FROM (
40-
SELECT id, component FROM waterways_ways_vertices_pgr
41-
) AS a
42-
WHERE id = source;
43-
\o exercise_9.txt
44-
-- Adding column to store Buffer geometry
45-
ALTER TABLE waterways.city_vertex
46-
ADD COLUMN city_buffer geometry;
47-
-- Storing Buffer geometry
48-
UPDATE waterways.city_vertex
49-
SET city_buffer = ST_Buffer((geom),0.005)
50-
WHERE name = 'Munshigang';
51-
-- Showing results of Buffer operation
52-
SELECT city_buffer FROM waterways.city_vertex;
75+
\o only_connected5.txt
76+
77+
UPDATE waterways_ways SET component = v.component
78+
FROM (SELECT id, component FROM waterways_vertices) AS v
79+
WHERE source = v.id;
80+
5381
\o exercise_10.txt
82+
5483
CREATE OR REPLACE FUNCTION get_city_buffer(city_id INTEGER)
5584
RETURNS geometry AS
56-
$BODY$
57-
SELECT city_buffer FROM city_vertex WHERE id = city_id;
85+
$BODY$
86+
SELECT city_buffer FROM bangladesh WHERE id = city_id;
5887
$BODY$
5988
LANGUAGE SQL;
89+
6090
\o exercise_11.txt
61-
-- Intersection of City Buffer and River Components
91+
6292
SELECT DISTINCT component
63-
FROM waterways.city_vertex, waterways.waterways_ways
64-
WHERE ST_Intersects(the_geom, get_city_buffer(5));
65-
\o exercise_12.txt
66-
-- Buffer of River Components
93+
FROM bangladesh JOIN waterways.waterways_ways
94+
ON (ST_Intersects(the_geom, get_city_buffer(5)));
95+
96+
\o get_rain_zone1.txt
97+
6798
ALTER TABLE waterways_ways
6899
ADD COLUMN rain_zone geometry;
69-
-- Storing Buffer geometry (rain_zone)
70-
UPDATE waterways.waterways_ways
71-
SET rain_zone = ST_Buffer((the_geom),0.005)
100+
101+
\o get_rain_zone2.txt
102+
103+
UPDATE waterways.waterways_ways
104+
SET rain_zone = ST_Buffer((the_geom),0.005)
72105
WHERE ST_Intersects(the_geom, get_city_buffer(5));
73106
\o exercise_13.txt
74107
-- Combining mutliple rain zones

docs/un_sdg/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ set(PGR_WORKSHOP_FILES
1111
sdg3-health.rst
1212
sdg7-energy.rst
1313
sdg11-cities.rst
14-
appendix.rst
1514
)
1615

1716

0 commit comments

Comments
 (0)