Skip to content

Commit

Permalink
#1015 replace gwolofs with gis
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielwol committed Jul 25, 2024
1 parent 1160fd1 commit eaf4872
Show file tree
Hide file tree
Showing 14 changed files with 101 additions and 101 deletions.
10 changes: 5 additions & 5 deletions gis/text_to_centreline/sql/function-centreline_case1.sql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
DROP FUNCTION IF EXISTS gwolofs._centreline_case1 (text, text, text, double precision);
DROP FUNCTION IF EXISTS gis._centreline_case1 (text, text, text, double precision);

CREATE OR REPLACE FUNCTION gwolofs._centreline_case1(
CREATE OR REPLACE FUNCTION gis._centreline_case1(
highway2 text,
btwn2 text,
direction_btwn2 text,
Expand Down Expand Up @@ -63,7 +63,7 @@ WITH get_int AS
ST_MakeLine(oid_geom, oid_geom_translated) AS new_line, -- line from the intersection point to the translated point
int_id_found AS int1,
get_geom.lev_sum
FROM gwolofs._get_intersection_geom(highway2, btwn2, direction_btwn2, metres_btwn2, 0) get_geom
FROM gis._get_intersection_geom(highway2, btwn2, direction_btwn2, metres_btwn2, 0) get_geom
),

get_lines AS (
Expand Down Expand Up @@ -242,5 +242,5 @@ EXCEPTION WHEN SQLSTATE 'XX000' THEN
END;
$BODY$;

ALTER FUNCTION gwolofs._centreline_case1(text, text, text, double precision)
OWNER TO gwolofs;
ALTER FUNCTION gis._centreline_case1(text, text, text, double precision)
OWNER TO gis_admins;
12 changes: 6 additions & 6 deletions gis/text_to_centreline/sql/function-centreline_case2.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
DROP FUNCTION IF EXISTS gwolofs._centreline_case2 (
DROP FUNCTION IF EXISTS gis._centreline_case2 (
text, text, text, double precision, text, text, double precision, text, text
);
CREATE OR REPLACE FUNCTION gwolofs._centreline_case2(
CREATE OR REPLACE FUNCTION gis._centreline_case2(
highway2 text,
btwn1 text,
direction_btwn1 text,
Expand Down Expand Up @@ -69,12 +69,12 @@ CREATE TEMP TABLE IF NOT EXISTS _wip2 (

TRUNCATE TABLE _wip2;

_int1_result := gwolofs._get_intersection_geom(highway2, btwn1, direction_btwn1, metres_btwn1, 0);
_int1_result := gis._get_intersection_geom(highway2, btwn1, direction_btwn1, metres_btwn1, 0);

_int2_result := (
CASE WHEN btwn2_orig LIKE '%point%' AND (btwn2_check NOT LIKE '% of %' OR btwn2_check LIKE ('% of ' || TRIM(btwn1)))
THEN gwolofs._get_intersection_geom(highway2, btwn2, direction_btwn2, metres_btwn2, 0)
ELSE gwolofs._get_intersection_geom(highway2, btwn2, direction_btwn2, metres_btwn2, _int1_result.int_id_found)
THEN gis._get_intersection_geom(highway2, btwn2, direction_btwn2, metres_btwn2, 0)
ELSE gis._get_intersection_geom(highway2, btwn2, direction_btwn2, metres_btwn2, _int1_result.int_id_found)
END
);

Expand All @@ -84,7 +84,7 @@ TRUNCATE TABLE _wip2;
_int1_result.oid_geom AS oid1_geom, _int1_result.oid_geom_translated AS oid1_geom_translated,
_int2_result.oid_geom AS oid2_geom, _int2_result.oid_geom_translated AS oid2_geom_translated,
rout.objectid, rout.fcode, rout.fcode_desc, _int1_result.lev_sum + _int2_result.lev_sum
FROM gwolofs._get_lines_btwn_interxn(highway2, _int1_result.int_id_found, _int2_result.int_id_found) rout;
FROM gis._get_lines_btwn_interxn(highway2, _int1_result.int_id_found, _int2_result.int_id_found) rout;

--those centreline found from buffer are where int_start, int_end, seq, lev_sum = NULL
INSERT INTO _wip2 (geo_id, lf_name, ind_line_geom, new_line1, new_line2,
Expand Down
76 changes: 38 additions & 38 deletions gis/text_to_centreline/sql/function-clean_bylaws_text.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--First create a table
CREATE TABLE IF NOT EXISTS gwolofs.cleaned_bylaws_text (
CREATE TABLE IF NOT EXISTS gis.cleaned_bylaws_text (
bylaw_id int,
highway2 text,
btwn1 text,
Expand All @@ -13,11 +13,11 @@ CREATE TABLE IF NOT EXISTS gwolofs.cleaned_bylaws_text (
);

--Then, create a function
DROP FUNCTION IF EXISTS gwolofs._clean_bylaws_text(int, text, text, text);
CREATE OR REPLACE FUNCTION gwolofs._clean_bylaws_text(
DROP FUNCTION IF EXISTS gis._clean_bylaws_text(int, text, text, text);

Check notice on line 16 in gis/text_to_centreline/sql/function-clean_bylaws_text.sql

View workflow job for this annotation

GitHub Actions / SQLFluff Lint

SQLFluff

LT01: Expected single whitespace between naked identifier and start bracket '('.
CREATE OR REPLACE FUNCTION gis._clean_bylaws_text(
_bylaw_id int, highway text, frm text, t text
)
RETURNS gwolofs.cleaned_bylaws_text
RETURNS gis.cleaned_bylaws_text
LANGUAGE 'plpgsql'
AS $$

Expand All @@ -29,7 +29,7 @@ DECLARE

-- when the input was btwn instead of from and to
btwn1_v1 text := CASE WHEN t IS NULL THEN
gwolofs.abbr_street(regexp_REPLACE
gis.abbr_street(regexp_REPLACE
(regexp_REPLACE
(regexp_REPLACE
(split_part
Expand All @@ -43,7 +43,7 @@ DECLARE
, '[Bb]etween ', '', 'g')
, 'A point', '', 'g'))

ELSE gwolofs.abbr_street(regexp_REPLACE
ELSE gis.abbr_street(regexp_REPLACE
(regexp_REPLACE
(regexp_REPLACE(frm, '\(.*?\)', '', 'g')
, '[0123456789.,]* metres (north|south|east|west|East|northeast|northwest|southwest|southeast) of ', '', 'g')
Expand All @@ -60,7 +60,7 @@ DECLARE

btwn2_orig_v1 text := CASE WHEN t IS NULL THEN
(CASE WHEN split_part(regexp_REPLACE(frm, '\(.*?\)', '', 'g'), ' and ', 2) <> ''
THEN gwolofs.abbr_street(regexp_REPLACE
THEN gis.abbr_street(regexp_REPLACE
(split_part
(regexp_REPLACE
(regexp_REPLACE
Expand All @@ -72,7 +72,7 @@ DECLARE
, '[Bb]etween |(A point)|(thereof)|(the northeast of)', '', 'g'))

WHEN split_part(frm, ' to ', 2) <> ''
THEN gwolofs.abbr_street(regexp_REPLACE
THEN gis.abbr_street(regexp_REPLACE
(regexp_REPLACE
(split_part
(regexp_REPLACE
Expand All @@ -86,7 +86,7 @@ DECLARE
END)

ELSE
gwolofs.abbr_street(regexp_REPLACE
gis.abbr_street(regexp_REPLACE
(regexp_REPLACE
(regexp_REPLACE
(regexp_REPLACE(t, '\(.*?\)', '', 'g')
Expand All @@ -103,20 +103,20 @@ DECLARE
END
);

highway2 text := gwolofs.abbr_street(highway);
highway2 text := gis.abbr_street(highway);

direction_btwn1 text := CASE WHEN t IS NULL THEN
(
CASE WHEN btwn1 LIKE '% m %'
OR gwolofs.abbr_street( regexp_REPLACE
OR gis.abbr_street( regexp_REPLACE
(split_part
(split_part
(frm, ' to ', 1)
, ' and ', 1)
, '[Bb]etween ', '', 'g')) LIKE '% m %'
THEN split_part
(split_part
(gwolofs.abbr_street
(gis.abbr_street
(regexp_REPLACE
(regexp_REPLACE
(regexp_REPLACE
Expand All @@ -134,11 +134,11 @@ DECLARE
ELSE
(
CASE WHEN btwn1 LIKE '% m %'
OR gwolofs.abbr_street(frm) LIKE '% m %'
OR gis.abbr_street(frm) LIKE '% m %'
THEN regexp_replace(regexp_replace
(split_part
(split_part
(gwolofs.abbr_street(frm), ' m ', 2)
(gis.abbr_street(frm), ' m ', 2)
, ' of ', 1)
, 'further ', '', 'g')
, 'east/north', 'northeast', 'g')
Expand All @@ -152,27 +152,27 @@ DECLARE
OR
(
CASE WHEN split_part(frm, ' and ', 2) <> ''
THEN gwolofs.abbr_street( regexp_REPLACE(split_part(frm, ' and ', 2), '[Bb]etween ', '', 'g'))
THEN gis.abbr_street( regexp_REPLACE(split_part(frm, ' and ', 2), '[Bb]etween ', '', 'g'))
WHEN split_part(frm, ' to ', 2) <> ''
THEN gwolofs.abbr_street( regexp_REPLACE(split_part(frm, ' to ', 2), '[Bb]etween ', '', 'g'))
THEN gis.abbr_street( regexp_REPLACE(split_part(frm, ' to ', 2), '[Bb]etween ', '', 'g'))
END
) LIKE '% m %'
THEN
(
CASE WHEN split_part(frm, ' and ', 2) <> ''
THEN regexp_REPLACE(regexp_replace(split_part(split_part( gwolofs.abbr_street(regexp_REPLACE(split_part(frm, ' and ', 2), '[Bb]etween ', '', 'g')), ' m ', 2), ' of ', 1), 'further | thereof', '', 'g'), 'east/north', 'northeast', 'g')
THEN regexp_REPLACE(regexp_replace(split_part(split_part( gis.abbr_street(regexp_REPLACE(split_part(frm, ' and ', 2), '[Bb]etween ', '', 'g')), ' m ', 2), ' of ', 1), 'further | thereof', '', 'g'), 'east/north', 'northeast', 'g')
WHEN split_part(frm, ' to ', 2) <> ''
THEN regexp_REPLACE(regexp_replace(split_part(split_part(gwolofs.abbr_street(regexp_REPLACE(split_part(frm, ' to ', 2), '[Bb]etween ', '', 'g')), ' m ', 2), ' of ', 1), 'further | thereof', '', 'g'), 'east/north', 'northeast', 'g')
THEN regexp_REPLACE(regexp_replace(split_part(split_part(gis.abbr_street(regexp_REPLACE(split_part(frm, ' to ', 2), '[Bb]etween ', '', 'g')), ' m ', 2), ' of ', 1), 'further | thereof', '', 'g'), 'east/north', 'northeast', 'g')
END
)
ELSE NULL
END)
ELSE
(
CASE WHEN btwn2_orig LIKE '% m %'
OR gwolofs.abbr_street(t) LIKE '% m %'
OR gis.abbr_street(t) LIKE '% m %'
THEN
regexp_REPLACE(regexp_replace(split_part(split_part(gwolofs.abbr_street(t), ' m ', 2), ' of ', 1), 'further ', '', 'g'), 'east/north', 'northeast', 'g')
regexp_REPLACE(regexp_replace(split_part(split_part(gis.abbr_street(t), ' m ', 2), ' of ', 1), 'further ', '', 'g'), 'east/north', 'northeast', 'g')
ELSE NULL
END
)
Expand All @@ -182,7 +182,7 @@ DECLARE
metres_btwn1 float := (CASE WHEN t IS NULL THEN
(
CASE WHEN btwn1 LIKE '% m %'
OR gwolofs.abbr_street(regexp_REPLACE
OR gis.abbr_street(regexp_REPLACE
(split_part
(split_part(frm, ' to ', 1)
, ' and ', 1)
Expand All @@ -191,7 +191,7 @@ DECLARE
(regexp_REPLACE
(regexp_REPLACE
(split_part
(gwolofs.abbr_street
(gis.abbr_street
(regexp_REPLACE
(split_part
(split_part(frm, ' to ', 1)
Expand All @@ -207,12 +207,12 @@ DECLARE
ELSE
(
CASE WHEN btwn1 LIKE '% m %'
OR gwolofs.abbr_street(frm) LIKE '% m %'
OR gis.abbr_street(frm) LIKE '% m %'
THEN regexp_REPLACE
(regexp_REPLACE
(regexp_REPLACE
(split_part
(gwolofs.abbr_street(frm), ' m ' ,1)
(gis.abbr_street(frm), ' m ' ,1)
, 'a point ', '', 'g')
, 'A point', '', 'g')
, ',', 'g')::float
Expand All @@ -226,18 +226,18 @@ DECLARE
( CASE WHEN btwn2_orig LIKE '% m %' OR
(
CASE WHEN split_part(frm, ' and ', 2) <> ''
THEN gwolofs.abbr_street( regexp_REPLACE(regexp_REPLACE(split_part(frm, ' and ', 2), '\(.*?\)', '', 'g'), '[Bb]etween ', '', 'g'))
THEN gis.abbr_street( regexp_REPLACE(regexp_REPLACE(split_part(frm, ' and ', 2), '\(.*?\)', '', 'g'), '[Bb]etween ', '', 'g'))
WHEN split_part(frm, ' to ', 2) <> ''
THEN gwolofs.abbr_street( regexp_REPLACE(regexp_REPLACE(split_part(frm, ' to ', 2), '\(.*?\)', '', 'g'), '[Bb]etween ', '', 'g'))
THEN gis.abbr_street( regexp_REPLACE(regexp_REPLACE(split_part(frm, ' to ', 2), '\(.*?\)', '', 'g'), '[Bb]etween ', '', 'g'))
END
)
LIKE '% m %'
THEN
(
CASE WHEN split_part(frm, ' and ', 2) <> ''
THEN regexp_REPLACE(regexp_REPLACE(regexp_REPLACE(split_part( gwolofs.abbr_street( regexp_REPLACE(regexp_REPLACE(split_part(frm, ' and ', 2), '\(.*\)', '', 'g'), '[Bb]etween ', '', 'g')), ' m ', 1), 'a point ', '', 'g'), 'A point', '', 'g'), ',', '', 'g')::float
THEN regexp_REPLACE(regexp_REPLACE(regexp_REPLACE(split_part( gis.abbr_street( regexp_REPLACE(regexp_REPLACE(split_part(frm, ' and ', 2), '\(.*\)', '', 'g'), '[Bb]etween ', '', 'g')), ' m ', 1), 'a point ', '', 'g'), 'A point', '', 'g'), ',', '', 'g')::float
WHEN split_part(frm, ' to ', 2) <> ''
THEN regexp_REPLACE(regexp_REPLACE(regexp_REPLACE(split_part(gwolofs.abbr_street( regexp_REPLACE(regexp_REPLACE(split_part(frm, ' to ', 2), '\(.*\)', '', 'g'), '[Bb]etween ', '', 'g')), ' m ', 1), 'a point ', '', 'g'), 'A point', '', 'g'), ',', '', 'g')::float
THEN regexp_REPLACE(regexp_REPLACE(regexp_REPLACE(split_part(gis.abbr_street( regexp_REPLACE(regexp_REPLACE(split_part(frm, ' to ', 2), '\(.*\)', '', 'g'), '[Bb]etween ', '', 'g')), ' m ', 1), 'a point ', '', 'g'), 'A point', '', 'g'), ',', '', 'g')::float
END
)
ELSE NULL
Expand All @@ -246,9 +246,9 @@ DECLARE
ELSE
(
CASE WHEN btwn2_orig LIKE '% m %'
OR gwolofs.abbr_street(t) LIKE '% m %'
OR gis.abbr_street(t) LIKE '% m %'
THEN
regexp_REPLACE(regexp_REPLACE(regexp_REPLACE(split_part(gwolofs.abbr_street(t), ' m ', 1), 'a point ', '', 'g'), 'A point', '', 'g'), ',', '', 'g')::float
regexp_REPLACE(regexp_REPLACE(regexp_REPLACE(split_part(gis.abbr_street(t), ' m ', 1), 'a point ', '', 'g'), 'A point', '', 'g'), ',', '', 'g')::float
ELSE NULL
END
)
Expand All @@ -262,13 +262,13 @@ DECLARE
-- the difference between the two is that one of the cases has a 'of' to describe the second road that intersects with "street"/"highway2"
btwn2_check text := CASE WHEN t IS NULL THEN
(CASE WHEN split_part(frm, ' and ', 2) <> ''
THEN gwolofs.abbr_street(regexp_REPLACE(regexp_REPLACE(split_part(frm, ' and ', 2), '[Bb]etween ', '', 'g'), 'A point', '', 'g'))
THEN gis.abbr_street(regexp_REPLACE(regexp_REPLACE(split_part(frm, ' and ', 2), '[Bb]etween ', '', 'g'), 'A point', '', 'g'))
WHEN split_part(frm, ' to ', 2) <> ''
THEN gwolofs.abbr_street(regexp_REPLACE(regexp_REPLACE(split_part(frm, ' to ', 2), '[Bb]etween ', '', 'g'), 'A point', '', 'g'))
THEN gis.abbr_street(regexp_REPLACE(regexp_REPLACE(split_part(frm, ' to ', 2), '[Bb]etween ', '', 'g'), 'A point', '', 'g'))
END)

ELSE
gwolofs.abbr_street(t)
gis.abbr_street(t)
END ;


Expand All @@ -277,8 +277,8 @@ DECLARE
-- for case one
-- i.e. Watson road from St. Mark's Road to a point 100 metres north
-- we want the btwn2 to be St. Mark's Road (which is also btwn1)
THEN TRIM(gwolofs.abbr_street(btwn1))
ELSE TRIM(gwolofs.abbr_street(regexp_replace(btwn2_orig , 'a point', '', 'g')))
THEN TRIM(gis.abbr_street(btwn1))
ELSE TRIM(gis.abbr_street(regexp_replace(btwn2_orig , 'a point', '', 'g')))
END
);

Expand All @@ -287,7 +287,7 @@ RAISE NOTICE 'btwn1: %, btwn2: %, btwn2_check: %, highway2: %, metres_btwn1: %,
btwn1, btwn2, btwn2_check, highway2, metres_btwn1, metres_btwn2, direction_btwn1, direction_btwn2;

RETURN ROW(_bylaw_id, highway2, btwn1, direction_btwn1, metres_btwn1, btwn2, direction_btwn2, metres_btwn2,
btwn2_orig, btwn2_check)::gwolofs.cleaned_bylaws_text ;
btwn2_orig, btwn2_check)::gis.cleaned_bylaws_text ;

END;
$$;
Expand All @@ -296,9 +296,9 @@ $$;
--For testing purposes only
DO $$
DECLARE
return_test gwolofs.cleaned_bylaws_text; --the table
return_test gis.cleaned_bylaws_text; --the table
BEGIN
return_test := gwolofs._clean_bylaws_text(123::int, 'Chesham Drive'::text, 'The west end of Chesham Drive and Heathrow Drive'::text, NULL::text); --the function
return_test := gis._clean_bylaws_text(123::int, 'Chesham Drive'::text, 'The west end of Chesham Drive and Heathrow Drive'::text, NULL::text); --the function
RAISE NOTICE 'Testing 123';
END;
$$ LANGUAGE 'plpgsql';
6 changes: 3 additions & 3 deletions gis/text_to_centreline/sql/function-get_entire_length.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
DROP FUNCTION IF EXISTS gwolofs._get_entire_length (text);
CREATE OR REPLACE FUNCTION gwolofs._get_entire_length(highway2_before_editing text)
DROP FUNCTION IF EXISTS gis._get_entire_length (text);
CREATE OR REPLACE FUNCTION gis._get_entire_length(highway2_before_editing text)
RETURNS TABLE (
centreline_id integer,
linear_name_full text,
Expand Down Expand Up @@ -40,6 +40,6 @@ RAISE NOTICE 'Entire segment found for %', highway2_before_editing;
END;
$BODY$;

COMMENT ON FUNCTION gwolofs._get_entire_length(text) IS '
COMMENT ON FUNCTION gis._get_entire_length(text) IS '
For bylaws with ''Entire Length'',
get all the individual line_geom that constitute the whole road segment from gis_core.centreline_latest table.';
12 changes: 6 additions & 6 deletions gis/text_to_centreline/sql/function-get_intersection_geom.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
DROP FUNCTION IF EXISTS gwolofs._get_intersection_geom (
DROP FUNCTION IF EXISTS gis._get_intersection_geom (
text, text, text, double precision, integer
);
CREATE OR REPLACE FUNCTION gwolofs._get_intersection_geom(
CREATE OR REPLACE FUNCTION gis._get_intersection_geom(
highway2 text, btwn text, direction text, metres float, not_int_id int,
OUT oid_geom geometry,
OUT oid_geom_translated geometry,
Expand All @@ -20,8 +20,8 @@ oid_geom_test geometry;

BEGIN
int_arr := (CASE WHEN TRIM(highway2) = TRIM(btwn)
THEN (gwolofs._get_intersection_id_highway_equals_btwn(highway2, btwn, not_int_id))
ELSE (gwolofs._get_intersection_id(highway2, btwn, not_int_id))
THEN (gis._get_intersection_id_highway_equals_btwn(highway2, btwn, not_int_id))
ELSE (gis._get_intersection_id(highway2, btwn, not_int_id))
END);

oid_int := int_arr[1];
Expand All @@ -37,7 +37,7 @@ oid_geom_test := (
oid_geom_translated := (
CASE WHEN direction IS NOT NULL OR metres IS NOT NULL
THEN (SELECT *
FROM gwolofs._translate_intersection_point(oid_geom_test, metres, direction) translated_geom)
FROM gis._translate_intersection_point(oid_geom_test, metres, direction) translated_geom)
ELSE NULL
END
);
Expand All @@ -53,7 +53,7 @@ oid_int, ST_AsText(oid_geom), ST_AsText(oid_geom_translated), direction, metres:
END;
$BODY$;

COMMENT ON FUNCTION gwolofs._get_intersection_geom(
COMMENT ON FUNCTION gis._get_intersection_geom(
text, text, text, float, int
) IS '
Input values of the names of two intersections, direction (may be NULL), number of units the intersection should be translated,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
--USING centrelines aka GIS network
DROP FUNCTION IF EXISTS gwolofs._get_lines_btwn_interxn;
DROP FUNCTION IF EXISTS gis._get_lines_btwn_interxn;

CREATE OR REPLACE FUNCTION gwolofs._get_lines_btwn_interxn(
CREATE OR REPLACE FUNCTION gis._get_lines_btwn_interxn(
_highway2 text,
_int_start integer,
_int_end integer
Expand Down Expand Up @@ -44,7 +44,7 @@ WITH results AS (
_int_start::bigint, _int_end::bigint, FALSE
) AS dijkstra
--or do pgr_dijkstra('SELECT id, source::int, target::int,
--CASE lf_name WHEN '''|| _highway2 ||''' THEN (0.3*cost)::float ELSE cost END AS cost from gwolofs.centreline_routing_undirected_lfname'::text, ... )
--CASE lf_name WHEN '''|| _highway2 ||''' THEN (0.3*cost)::float ELSE cost END AS cost from gis.centreline_routing_undirected_lfname'::text, ... )
)
SELECT
results._int_start,
Expand Down
Loading

0 comments on commit eaf4872

Please sign in to comment.