mirror of
https://github.com/xbgmsharp/postgsail.git
synced 2025-09-17 11:17:46 +00:00
Add API endpoint api.timelapse_fn
This commit is contained in:
@@ -567,53 +567,47 @@ COMMENT ON TRIGGER
|
|||||||
|
|
||||||
---------------------------------------------------------------------------
|
---------------------------------------------------------------------------
|
||||||
-- Functions API schema
|
-- Functions API schema
|
||||||
-- Export a log entry to geojson
|
-- Timelapse - replay logs
|
||||||
DROP FUNCTION IF EXISTS api.export_logbook_geojson_point_fn;
|
DROP FUNCTION IF EXISTS api.timelapse_fn;
|
||||||
CREATE OR REPLACE FUNCTION api.export_logbook_geojson_point_fn(IN _id INTEGER, OUT geojson JSON) RETURNS JSON AS $export_logbook_geojson_point$
|
CREATE OR REPLACE FUNCTION api.timelapse_fn(
|
||||||
|
IN start_log INTEGER DEFAULT NULL,
|
||||||
|
IN end_log INTEGER DEFAULT NULL,
|
||||||
|
IN start_date TEXT DEFAULT NULL,
|
||||||
|
IN end_date TEXT DEFAULT NULL,
|
||||||
|
OUT geojson JSON) RETURNS JSON AS $timelapse$
|
||||||
DECLARE
|
DECLARE
|
||||||
logbook_rec record;
|
tmp_geojson jsonb := '{}';
|
||||||
|
_geojson jsonb;
|
||||||
BEGIN
|
BEGIN
|
||||||
-- If _id is is not NULL and > 0
|
-- TODO using jsonb pgsql function instead of python
|
||||||
SELECT * INTO logbook_rec
|
IF start_log IS NOT NULL AND public.isnumeric(start_log::text) AND public.isnumeric(end_log::text) THEN
|
||||||
FROM api.logbook WHERE id = _id;
|
SELECT jsonb_agg(track_geojson->'features') INTO tmp_geojson
|
||||||
|
FROM api.logbook
|
||||||
WITH log AS (
|
WHERE id >= start_log
|
||||||
SELECT m.time as time, m.latitude as lat, m.longitude as lng, m.courseOverGroundTrue as cog
|
AND id <= end_log;
|
||||||
FROM api.metrics m
|
--raise WARNING 'by log tmp_geojson %' , tmp_geojson;
|
||||||
WHERE m.latitude IS NOT null
|
ELSIF start_date IS NOT NULL AND public.isdate(start_date::text) AND public.isdate(end_date::text) THEN
|
||||||
AND m.longitude IS NOT null
|
SELECT jsonb_agg(track_geojson->'features') INTO tmp_geojson
|
||||||
AND m.time >= logbook_rec._from_time::timestamp without time zone
|
FROM api.logbook
|
||||||
AND m.time <= logbook_rec._to_time::timestamp without time zone
|
WHERE _from_time >= start_log::TIMESTAMP WITHOUT TIME ZONE
|
||||||
GROUP by m.time,m.latitude,m.longitude,m.courseOverGroundTrue
|
AND _to_time <= end_date::TIMESTAMP WITHOUT TIME ZONE + interval '23 hours 59 minutes';
|
||||||
ORDER BY m.time ASC)
|
--raise WARNING 'by date tmp_geojson %' , tmp_geojson;
|
||||||
|
ELSE
|
||||||
|
SELECT jsonb_agg(track_geojson->'features') INTO tmp_geojson
|
||||||
|
FROM api.logbook;
|
||||||
|
--raise WARNING 'all result tmp_geojson %' , tmp_geojson;
|
||||||
|
END IF;
|
||||||
|
--raise WARNING 'result _geojson %' , _geojson;
|
||||||
|
_geojson := public.geojson_py_fn(tmp_geojson);
|
||||||
SELECT json_build_object(
|
SELECT json_build_object(
|
||||||
'type', 'FeatureCollection',
|
'type', 'FeatureCollection',
|
||||||
'crs', json_build_object(
|
'features', _geojson) INTO geojson;
|
||||||
'type', 'name',
|
|
||||||
'properties', json_build_object(
|
|
||||||
'name', 'EPSG:4326'
|
|
||||||
)
|
|
||||||
),
|
|
||||||
'features', json_agg(
|
|
||||||
json_build_object(
|
|
||||||
'type', 'Feature',
|
|
||||||
-- 'id', {id}, -- the GeoJson spec includes an 'id' field, but it is optional, replace {id} with your id field
|
|
||||||
'geometry', ST_AsGeoJSON(st_makepoint(lng,lat))::json,
|
|
||||||
'properties', json_build_object(
|
|
||||||
-- list of fields
|
|
||||||
'field1', time,
|
|
||||||
'field2', cog
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
) INTO geojson
|
|
||||||
FROM log;
|
|
||||||
END;
|
END;
|
||||||
$export_logbook_geojson_point$ LANGUAGE plpgsql;
|
$timelapse$ LANGUAGE plpgsql;
|
||||||
-- Description
|
-- Description
|
||||||
COMMENT ON FUNCTION
|
COMMENT ON FUNCTION
|
||||||
api.export_logbook_geojson_point_fn
|
api.timelapse_fn
|
||||||
IS 'Export a log entry to geojson feature point with Time and courseOverGroundTrue properties';
|
IS 'Export to geojson feature point with Time and courseOverGroundTrue properties';
|
||||||
|
|
||||||
-- Export a log entry to geojson
|
-- Export a log entry to geojson
|
||||||
DROP FUNCTION IF EXISTS api.export_logbook_geojson_linestring_fn;
|
DROP FUNCTION IF EXISTS api.export_logbook_geojson_linestring_fn;
|
||||||
|
Reference in New Issue
Block a user