-
Notifications
You must be signed in to change notification settings - Fork 0
/
PG_Skyline.sql
68 lines (68 loc) · 2.33 KB
/
PG_Skyline.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
CREATE OR REPLACE FUNCTION pg_skyline(
x1 numeric
, y1 numeric
, inlevel integer DEFAULT 1
, radius integer DEFAULT 1000
, CASEaccuracy integer DEFAULT 300
)
RETURNS SETOF json
LANGUAGE 'plpgsql'
COST 100
VOLATILE PARALLEL SAFE
ROWS 1 AS
$BODY$
BEGIN RETURN QUERY
SELECT json_build_object(
'type'
, 'FeatureCollection'
, 'features'
, json_agg(ST_AsGeoJSON(res.*)::json)
)
FROM (
SELECT ST_Transform(
ST_MakePolygon(
ST_LineFromMultiPoint(
ST_Collect(
ST_EndPoint(
ST_GeometryN(
ST_Difference(g.geom, b.geom),
1
)
)
)
)
),
4326
) AS geom
FROM (
SELECT ST_MakeLine(
ST_Transform(
ST_SetSRID(ST_MakePoint(x1, y1), 4326), 32636),
(gline.gdump).geom
) AS geom
FROM (
SELECT ST_DumpPoints(
ST_Buffer(
ST_Transform(ST_SetSRID(ST_MakePoint(x1, y1), 4326), 32636),
radius,
accuracy
)
) as gdump
) AS gline
) AS g,
(
SELECT ST_Union(geom) as geom
FROM source_data.buildings_kyiv AS bkiev
WHERE ST_Intersects(
ST_Buffer(
ST_Transform(ST_SetSRID(ST_MakePoint(x1, y1), 4326), 32636),
radius,
10
),
bkiev.geom
)
AND floors::int >= inlevel
) AS b
) AS res;
END;
$BODY$;