diff --git a/etl/drop_outside_limit.sh b/etl/drop_outside_limit.sh index e27290fe..133d481c 100755 --- a/etl/drop_outside_limit.sh +++ b/etl/drop_outside_limit.sh @@ -12,53 +12,7 @@ boundary_file=$1 psql -c "DROP TABLE IF EXISTS boundary" shp2pgsql -s 3857 $boundary_file boundary | psql -# Remove restrictions on deleting linked geometries -psql -c "ALTER TABLE ONLY buildings -DROP CONSTRAINT buildings_geometry_id_fkey; - -ALTER TABLE ONLY buildings -ADD CONSTRAINT buildings_geometry_id_fkey -FOREIGN KEY (geometry_id) REFERENCES geometries(geometry_id) ON DELETE CASCADE; - -ALTER TABLE ONLY building_properties -DROP CONSTRAINT building_properties_building_id_fkey; - -ALTER TABLE ONLY building_properties -ADD CONSTRAINT building_properties_building_id_fkey -FOREIGN KEY (building_id) REFERENCES buildings(building_id) ON DELETE CASCADE; - -ALTER TABLE ONLY logs -DROP CONSTRAINT logs_building_id_fkey; - -ALTER TABLE ONLY logs -ADD CONSTRAINT logs_building_id_fkey -FOREIGN KEY (building_id) REFERENCES buildings(building_id) ON DELETE CASCADE; -" - # Delete geometries (hence buildings, building_properties) psql -c "DELETE FROM geometries as g USING boundary as b WHERE b.gid = 1 AND NOT ST_ContainsProperly(b.geom, g.geometry_geom);" - -# Put restrictions back -psql -c "ALTER TABLE ONLY buildings -DROP CONSTRAINT buildings_geometry_id_fkey; - -ALTER TABLE ONLY buildings -ADD CONSTRAINT buildings_geometry_id_fkey -FOREIGN KEY (geometry_id) REFERENCES geometries(geometry_id) ON DELETE RESTRICT; - -ALTER TABLE ONLY building_properties -DROP CONSTRAINT building_properties_building_id_fkey; - -ALTER TABLE ONLY building_properties -ADD CONSTRAINT building_properties_building_id_fkey -FOREIGN KEY (building_id) REFERENCES buildings(building_id) ON DELETE RESTRICT; - -ALTER TABLE ONLY logs -DROP CONSTRAINT logs_building_id_fkey; - -ALTER TABLE ONLY logs -ADD CONSTRAINT logs_building_id_fkey -FOREIGN KEY (building_id) REFERENCES buildings(building_id) ON DELETE RESTRICT; -"