Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
JakobMiksch committed Oct 20, 2024
1 parent c458835 commit 9f43bb8
Showing 1 changed file with 44 additions and 2 deletions.
46 changes: 44 additions & 2 deletions data/query_function.sql
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
CREATE SCHEMA IF NOT EXISTS postgisftw;

DROP FUNCTION IF EXISTS postgisftw.osm_website_clone;
DROP FUNCTION IF EXISTS postgisftw.osm_website_objects_around;

CREATE
OR REPLACE FUNCTION postgisftw.osm_website_clone (
OR REPLACE FUNCTION postgisftw.osm_website_objects_around (
latitude float,
longitude float,
radius int,
Expand Down Expand Up @@ -39,6 +39,48 @@ OR REPLACE FUNCTION postgisftw.osm_website_clone (
AND ST_Covers(ST_MakeEnvelope(min_lon, min_lat, max_lon, max_lat, 4326)::geography, geog)
$$ LANGUAGE sql STABLE PARALLEL SAFE;

DROP FUNCTION IF EXISTS postgisftw.osm_website_objects_enclosing;

CREATE
OR REPLACE FUNCTION postgisftw.osm_website_objects_enclosing (
latitude float,
longitude float,
min_lat float,
min_lon float,
max_lat float,
max_lon float
) RETURNS TABLE (
osm_type char,
osm_id bigint,
tags jsonb,
geom geometry
) AS $$
SELECT
osm_type,
osm_id,
tags,
-- geog::geometry
CASE
WHEN NOT ST_Covers (
ST_MakeEnvelope (min_lon, min_lat, max_lon, max_lat, 4326)::geography,
geog
) THEN NULL::geometry
ELSE geog::geometry
END AS geog
FROM (
SELECT gw.osm_type, gw.osm_id, r.tags, gw.geog AS geog
FROM geom_ways AS gw
JOIN raw_ways AS r ON gw.osm_id = r.id

UNION

SELECT gr.osm_type, gr.osm_id, r.tags, gr.geog AS geog
FROM geom_rels AS gr
JOIN raw_rels AS r ON gr.osm_id = r.id
) AS osm_objects
WHERE ST_Covers(geog, ST_SetSRID(ST_MakePoint(longitude, latitude), 4326)::geography)
$$ LANGUAGE sql STABLE PARALLEL SAFE;

DROP FUNCTION IF EXISTS postgisftw.osm_feature_info_geog;

CREATE
Expand Down

0 comments on commit 9f43bb8

Please sign in to comment.