You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
IS 'Export a log trip entry to GEOJSON format with custom properties for timelapse replay';
921
+
922
+
-- Add export_logbook_metrics_trip_fn, update geojson from trip to geojson
923
+
CREATE OR REPLACEFUNCTIONapi.export_logbook_metrics_trip_fn(_id integer)
924
+
RETURNS jsonb
803
925
LANGUAGE plpgsql
804
926
AS $function$
805
927
DECLARE
@@ -906,7 +1028,7 @@ BEGIN
906
1028
END;
907
1029
$function$
908
1030
;
909
-
COMMENT ON FUNCTION api.export_logbook_geojson_trip_fn IS 'Export a logs entries to GeoJSON format of geometry point';
1031
+
COMMENT ON FUNCTION api.export_logbook_metrics_trip_fn IS 'Export a log entry to an array of GeoJSON feature format of geometry point';
910
1032
911
1033
-- Create api.export_logbook_geojson_point_trip_fn, transform spatiotemporal trip into a geojson with the corresponding properties
912
1034
CREATE OR REPLACEFUNCTIONapi.export_logbook_geojson_point_trip_fn(_id integer)
@@ -2081,6 +2203,44 @@ END;
2081
2203
$$ LANGUAGE plpgsql;
2082
2204
COMMENT ON FUNCTION api.delete_trip_entry_fn IS 'Delete at a specific time a temporal sequence for all trip_* column from a logbook';
2083
2205
2206
+
-- Update export_logbooks_geojson_point_trips_fn, replace timelapse2_fn, Generate the GeoJSON from the time sequence value
2207
+
CREATE OR REPLACEFUNCTIONapi.export_logbooks_geojson_point_trips_fn(
2208
+
start_log integer DEFAULT NULL::integer,
2209
+
end_log integer DEFAULT NULL::integer,
2210
+
start_date text DEFAULT NULL::text,
2211
+
end_date text DEFAULT NULL::text,
2212
+
OUT geojson jsonb
2213
+
) RETURNS jsonb
2214
+
LANGUAGE plpgsql
2215
+
AS $function$
2216
+
DECLARE
2217
+
metrics_geojson jsonb;
2218
+
BEGIN
2219
+
-- Normalize start and end values
2220
+
IF start_log IS NOT NULLAND end_log IS NULL THEN end_log := start_log; END IF;
2221
+
IF start_date IS NOT NULLAND end_date IS NULL THEN end_date := start_date; END IF;
2222
+
2223
+
WITH logbook_data AS (
2224
+
-- get the logbook data, an array for each log
2225
+
SELECTapi.export_logbook_metrics_trip_fn(l.id) AS log_geojson
2226
+
FROMapi.logbook l
2227
+
WHERE (start_log IS NULLORl.id>= start_log) AND
2228
+
(end_log IS NULLORl.id<= end_log) AND
2229
+
(start_date IS NULLORl._from_time>= start_date::TIMESTAMPTZ) AND
2230
+
(end_date IS NULLORl._to_time<= end_date::TIMESTAMPTZ+ interval '23 hours 59 minutes') AND
2231
+
l.tripIS NOT NULL
2232
+
ORDER BYl._from_timeASC
2233
+
)
2234
+
-- Create the GeoJSON response
2235
+
SELECT jsonb_build_object(
2236
+
'type', 'FeatureCollection',
2237
+
'features', jsonb_agg(feature_element)) INTO geojson
2238
+
FROM logbook_data l,
2239
+
LATERAL jsonb_array_elements(l.log_geojson) AS feature_element; -- Flatten the arrays and create a GeoJSON FeatureCollection
2240
+
END;
2241
+
$function$;
2242
+
COMMENT ON FUNCTION api.export_logbooks_geojson_point_trips_fn IS 'Export all selected logs into a geojson `trip` to a geojson as points including properties';
2243
+
2084
2244
-- Update api role SQL connection to 40
2085
2245
ALTER ROLE authenticator WITH NOSUPERUSER NOCREATEDB NOCREATEROLE NOINHERIT NOBYPASSRLS NOREPLICATION CONNECTION LIMIT40 LOGIN;
2086
2246
ALTER ROLE api_anonymous WITH NOSUPERUSER NOCREATEDB NOCREATEROLE NOINHERIT NOBYPASSRLS NOREPLICATION CONNECTION LIMIT40 LOGIN;
@@ -2092,8 +2252,8 @@ GRANT UPDATE (name, _from, _to, notes, trip_notes, trip, trip_cog, trip_sog, tri
2092
2252
GRANTSELECTON TABLE api.log_view TO api_anonymous;
2093
2253
GRANT EXECUTE ON FUNCTION api.export_logbooks_geojson_linestring_trips_fn to api_anonymous;
2094
2254
GRANT EXECUTE ON FUNCTION api.export_logbooks_geojson_point_trips_fn to api_anonymous;
2095
-
--GRANT EXECUTE ON FUNCTION api.logbook_update_geojson_trip_fn to api_anonymous;
2096
2255
GRANT EXECUTE ON FUNCTION api.export_logbook_geojson_trip_fn to api_anonymous;
2256
+
GRANT EXECUTE ON FUNCTION api.export_logbook_metrics_trip_fn to api_anonymous;
2097
2257
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA public TO api_anonymous;
0 commit comments