IV: finding bends
This commit is contained in:
parent
34f7268688
commit
677809e06b
26
IV/bend.sql
Normal file
26
IV/bend.sql
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
create or replace function detect_bends(line geometry) returns table(bend geometry) as $$
|
||||||
|
/* for each bend, should return:
|
||||||
|
- size (area)
|
||||||
|
- shape (cmp, compactness index)
|
||||||
|
*/
|
||||||
|
declare
|
||||||
|
pi real;
|
||||||
|
p geometry;
|
||||||
|
p1 geometry;
|
||||||
|
p2 geometry;
|
||||||
|
p3 geometry;
|
||||||
|
begin
|
||||||
|
pi = radians(180);
|
||||||
|
|
||||||
|
for p in (select (dp).geom from st_dumppoints(line) as dp) loop
|
||||||
|
p3 = p2;
|
||||||
|
p2 = p1;
|
||||||
|
p1 = p;
|
||||||
|
if p3 is null then continue; end if;
|
||||||
|
raise notice 'ANGLE %', degrees(pi - st_angle(p1, p2, p2, p3));
|
||||||
|
end loop;
|
||||||
|
end
|
||||||
|
$$ language plpgsql;
|
||||||
|
|
||||||
|
drop table if exists bends;
|
||||||
|
create table bends as (select * from detect_bends((select way from figures where name='fig3')));
|
51
IV/db
Executable file
51
IV/db
Executable file
@ -0,0 +1,51 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
name=wm-mj
|
||||||
|
|
||||||
|
_psql() {
|
||||||
|
env \
|
||||||
|
PGPASSWORD=osm \
|
||||||
|
PGHOST=127.0.0.1 \
|
||||||
|
PGUSER=osm \
|
||||||
|
PGDATABASE=osm \
|
||||||
|
psql "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
_wait_for_postgres() {
|
||||||
|
>&2 echo -n "Waiting for postgres"
|
||||||
|
for _ in $(seq 240); do
|
||||||
|
if _psql -qc '\q' 2>/dev/null; then
|
||||||
|
>&2 echo " up"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
>&2 echo -n .
|
||||||
|
sleep 1
|
||||||
|
done
|
||||||
|
>&2 echo " down"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
case ${1:-} in
|
||||||
|
start)
|
||||||
|
docker run -d --rm \
|
||||||
|
-p 5432:5432 \
|
||||||
|
-e POSTGRES_DBNAME=osm \
|
||||||
|
-e POSTGRES_USER=osm \
|
||||||
|
-e POSTGRES_PASSWORD=osm \
|
||||||
|
--name "$name" \
|
||||||
|
postgis/postgis:13-3.1-alpine
|
||||||
|
_wait_for_postgres
|
||||||
|
;;
|
||||||
|
stop)
|
||||||
|
docker stop "$name"
|
||||||
|
;;
|
||||||
|
"" | --)
|
||||||
|
[[ $# -gt 1 ]] && shift
|
||||||
|
_psql "$@"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
>&2 echo "Unknown command: '$*'"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
4
IV/figures.sql
Normal file
4
IV/figures.sql
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
drop table if exists figures;
|
||||||
|
create table figures (name text, way geometry);
|
||||||
|
|
||||||
|
insert into figures (name, way) values ('fig3', ST_GeomFromText('LINESTRING(0 0, 12 0, 13 4, 20 2, 20 0, 32 0, 33 10, 38 16, 43 15, 44 10, 44 0, 60 0)'));
|
Loading…
Reference in New Issue
Block a user