clean-tables target

This commit is contained in:
Motiejus Jakštys 2021-03-23 18:40:25 +02:00
parent 728665e590
commit 25150f1cbd
2 changed files with 19 additions and 12 deletions

View File

@ -9,10 +9,17 @@ test: tests.sql .faux.db
test-integration: .faux_filter-rivers test-integration: .faux_filter-rivers
./db -f tests-integration.sql ./db -f tests-integration.sql
.PHONY: clean
clean: clean:
-./db stop -./db stop
-rm .faux_filter-rivers .faux_import-osm .faux.db -rm .faux_filter-rivers .faux_import-osm .faux.db
.PHONY: clean-tables
clean-tables:
for t in $$(./db -c '\dt' | awk '/demo_|integ_/{print $$3}'); do \
./db -c "drop table $$t"; \
done
.faux_filter-rivers: .faux_import-osm .faux_filter-rivers: .faux_import-osm
./db -v where="$(WHERE)" -f aggregate-rivers.sql ./db -v where="$(WHERE)" -f aggregate-rivers.sql
touch $@ touch $@

View File

@ -328,23 +328,23 @@ begin
mutated = true; mutated = true;
foreach line in array lines loop foreach line in array lines loop
while mutated loop while mutated loop
execute format('drop table if exists demo_%safigures', i); execute format('drop table if exists integ_%safigures', i);
execute format('create table demo_%safigures (way geometry)', i); execute format('create table integ_%safigures (way geometry)', i);
-- if anyone has suggestions how to insert a variable to a table without -- if anyone has suggestions how to insert a variable to a table without
-- such hackery, I'll be glad to know -- such hackery, I'll be glad to know
execute format('insert into demo_%safigures select $1;', i) using (select unnest(array[line])); execute format('insert into integ_%safigures select $1;', i) using (select unnest(array[line]));
bends = detect_bends(line); bends = detect_bends(line);
execute format('drop table if exists demo_%sbbends', i); execute format('drop table if exists integ_%sbbends', i);
execute format('create table demo_%sbbends (i bigint, way geometry)', i); execute format('create table integ_%sbbends (i bigint, way geometry)', i);
execute format('insert into demo_%sbbends (i, way) select generate_subscripts($1, 1), unnest($1)', i) using bends; execute format('insert into integ_%sbbends (i, way) select generate_subscripts($1, 1), unnest($1)', i) using bends;
bends = fix_gentle_inflections(bends); bends = fix_gentle_inflections(bends);
execute format('drop table if exists demo_%scinflections', i); execute format('drop table if exists integ_%scinflections', i);
execute format('create table demo_%scinflections (i bigint, way geometry)', i); execute format('create table integ_%scinflections (i bigint, way geometry)', i);
execute format('insert into demo_%scinflections (i, way) select generate_subscripts($1, 1), unnest($1)', i) using bends; execute format('insert into integ_%scinflections (i, way) select generate_subscripts($1, 1), unnest($1)', i) using bends;
select * from self_crossing(bends) into bends, mutated; select * from self_crossing(bends) into bends, mutated;
execute format('drop table if exists demo_%sdselfcrossing', i); execute format('drop table if exists integ_%sdselfcrossing', i);
execute format('create table demo_%sdselfcrossing (i bigint, way geometry)', i); execute format('create table integ_%sdselfcrossing (i bigint, way geometry)', i);
execute format('insert into demo_%sdselfcrossing (i, way) select generate_subscripts($1, 1), unnest($1)', i) using bends; execute format('insert into integ_%sdselfcrossing (i, way) select generate_subscripts($1, 1), unnest($1)', i) using bends;
line = st_linemerge(st_union(bends)); line = st_linemerge(st_union(bends));
i = i + 1; i = i + 1;
end loop; end loop;