colouring-montreal/etl/update_building_records.sh
2022-04-14 09:28:34 +01:00

35 lines
1.2 KiB
Bash
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
## Comments:
## Is dynamics_has_demolished_buildings = TRUE sufficient to prevent buildings being loaded? - No
## Lets mark them, then see if there even are any
## Describe these changes in PR and ask for comment if the bool is sufficient
## Prerequisites:
## - Make geometries table have coordinates (load_coordinates.sh) - DONE
## - <mastermap download>= release_geometries
# for geometry in geometries
# if geometry.TOID not in builings
# Add TOID to temp table called new_geometries
psql -c "CREATE TABLE new_geometries (
geometry_id serial PRIMARY KEY,
source_id varchar(30)
);"
psql -c "INSERT INTO buildings ( geometry_id, ref_toid )
SELECT geometry_id, source_id
FROM geometries
ON CONFLICT ( ref_toid )
DO UPDATE SET new_geometries.source_id=EXCLUDED.ref_toid
;"
# for building in buildings
# if building.TOID not in new release_geometries
# buildings.dynamics_has_demolished_buildings = TRUE
# secondarily, if building.coordinates <10m away from any new_geometry.coordinates
# older_building.dynamics_has_demolished_buildings = TRUE
# link new_geometry TOID in the geometries table to old building and delete duplicate building we just created for new_geometry