Skip to content

Commit 5a2ed15

Browse files
committed
Inicia api's:. #44
1 parent fbaea25 commit 5a2ed15

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

src/step01geoUriExt-api.sql

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
CREATE EXTENSION IF NOT EXISTS postgis;
2+
CREATE SCHEMA IF NOT EXISTS api;
3+
4+
CREATE or replace FUNCTION api.olc_encode(
5+
uri text
6+
) RETURNS jsonb AS $wrap$
7+
SELECT jsonb_build_object(
8+
'type', 'FeatureCollection',
9+
'features',
10+
(
11+
SELECT jsonb_agg(
12+
ST_AsGeoJSONb(geouri_ext.olc_geom(x),8,0,null,
13+
jsonb_build_object(
14+
'olc', x
15+
)
16+
)::jsonb)
17+
FROM (SELECT geouri_ext.olc_encode(u[1],u[2],u[4]::int)) t(x)
18+
)
19+
)
20+
FROM ( SELECT str_geouri_decode(uri) ) t(u)
21+
$wrap$ LANGUAGE SQL IMMUTABLE;
22+
COMMENT ON FUNCTION api.olc_encode(text)
23+
IS 'Encodes Geo URI to OSMcode. Wrap for osmcode_encode_context(geometry)'
24+
;
25+
-- EXPLAIN ANALYZE SELECT api.olc_encode('geo:olc:-23.550385,-46.633956;u=11');
26+
27+
28+
CREATE or replace FUNCTION api.ghs_encode(
29+
uri text
30+
) RETURNS jsonb AS $wrap$
31+
SELECT jsonb_build_object(
32+
'type', 'FeatureCollection',
33+
'features',
34+
(
35+
SELECT jsonb_agg(
36+
ST_AsGeoJSONb(ST_GeomFromGeoHash(x,u[4]::int),8,0,null,
37+
jsonb_build_object(
38+
'olc', x
39+
)
40+
)::jsonb)
41+
FROM (SELECT ST_GeoHash(ST_SetSRID(ST_Point(u[2],u[1]),4326),u[4]::int)) t(x)
42+
)
43+
)
44+
FROM ( SELECT str_geouri_decode(uri) ) t(u)
45+
$wrap$ LANGUAGE SQL IMMUTABLE;
46+
COMMENT ON FUNCTION api.ghs_encode(text)
47+
IS 'Encodes Geo URI to OSMcode. Wrap for osmcode_encode_context(geometry)'
48+
;
49+
-- EXPLAIN ANALYZE SELECT api.ghs_encode('geo:ghs:-23.550385,-46.633956;u=11');

0 commit comments

Comments
 (0)