Skip to content

Commit

Permalink
Merge pull request #81 from max-trolliet/patch-4
Browse files Browse the repository at this point in the history
Create SQL code for changing reach direction
  • Loading branch information
m-kuhn authored Aug 18, 2018
2 parents 69fe77e + d6ae829 commit f61cfdc
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 1 deletion.
37 changes: 37 additions & 0 deletions delta/delta_1.1.1_add_reach_direction_change.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/***************************************************************************
reach_direction_change.sql
---------------------
begin : August 2018
copyright : (C) 2018 by Matthias Kuhn, OPENGIS.ch
email : [email protected]
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

/**
* This function changes the direction of a set of reaches.
* It will change the direction of the line itself as well as switch the two reach points
* to make sure the topology and reach point attributes stay the way they were.
*
* With the parameter `reach_obj_ids` it is possible to specify on which reaches this operation
* should be performed by passing in an array of obj_ids
*/
CREATE OR REPLACE FUNCTION qgep_od.reach_direction_change(reach_obj_ids text[])RETURNS void AS $BODY$

BEGIN

UPDATE qgep_od.reach
SET
progression_geometry = (ST_ForceCurve(ST_Reverse(ST_CurveToLine(progression_geometry)))),
fk_reach_point_from = fk_reach_point_to,
fk_reach_point_to = fk_reach_point_from
WHERE obj_id = ANY(reach_obj_ids);
END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
37 changes: 37 additions & 0 deletions functions/reach_direction_change.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/***************************************************************************
reach_direction_change.sql
---------------------
begin : August 2018
copyright : (C) 2018 by Matthias Kuhn, OPENGIS.ch
email : [email protected]
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

/**
* This function changes the direction of a set of reaches.
* It will change the direction of the line itself as well as switch the two reach points
* to make sure the topology and reach point attributes stay the way they were.
*
* With the parameter `reach_obj_ids` it is possible to specify on which reaches this operation
* should be performed by passing in an array of obj_ids
*/
CREATE OR REPLACE FUNCTION qgep_od.reach_direction_change(reach_obj_ids text[])RETURNS void AS $BODY$

BEGIN

UPDATE qgep_od.reach
SET
progression_geometry = (ST_ForceCurve(ST_Reverse(ST_CurveToLine(progression_geometry)))),
fk_reach_point_from = fk_reach_point_to,
fk_reach_point_to = fk_reach_point_from
WHERE obj_id = ANY(reach_obj_ids);
END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
4 changes: 3 additions & 1 deletion scripts/db_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,13 @@ psql "service=${PGSERVICE}" -v ON_ERROR_STOP=1 -c "$(${DIR}/view/vw_oo_organisat
psql "service=${PGSERVICE}" -v ON_ERROR_STOP=1 -v SRID=$SRID -f ${DIR}/view/vw_catchment_area_connections.sql
psql "service=${PGSERVICE}" -v ON_ERROR_STOP=1 -v SRID=$SRID -f ${DIR}/view/vw_change_points.sql

psql "service=${PGSERVICE}" -v ON_ERROR_STOP=1 -v SRID=$SRID -f ${DIR}/functions/reach_direction_change.sql

if [[ $roles ]]; then
psql "service=${PGSERVICE}" -v ON_ERROR_STOP=1 -f ${DIR}/12_roles.sql
fi

VERSION=$(cat ${DIR}/system/CURRENT_VERSION.txt)
pum baseline -p ${PGSERVICE} -t qgep_sys.pum_info -d ${DIR}/delta/ -b ${VERSION}

psql "service=${PGSERVICE}" -v ON_ERROR_STOP=1 -v SRID=$SRID -f ${DIR}/13_import.sql
psql "service=${PGSERVICE}" -v ON_ERROR_STOP=1 -v SRID=$SRID -f ${DIR}/13_import.sql

0 comments on commit f61cfdc

Please sign in to comment.