I want to save LineString like the below in Postgresql
{"type": "FeatureCollection", "features": [{"type": "Feature", "properties": {"style": {"color": "#19f3e7", "weight": 2}}, "geometry": {"type": "LineString", "coordinates": [[50.998085021972656, 35.83528137207031, 1000.0, 1682083948.0], [50.99810028076172, 35.83527374267578, 1000.0, 1682083948.0], [50.998023986816406, 35.835289001464844, 1000.0, 1682083948.0]]}}]}
[50.998085021972656, 35.83528137207031, 1682083948.0]
means we are in this point [50.998085021972656, 35.83528137207031]
at timestamp 1682083948.0
. I know postgis can save linestring like below :
LINESTRING(77.29 29.07,77.42 29.26,77.27 29.31,77.29 29.07)
but there is no way to save timestamp in this kind of column. is there anyway to save timestamp alongside lat and lon in postgres or anyother type of data in postgres or not ?
2
Answers
Thanks to @jim-jones's hint I could find the more straightforward solutions :
CREATE TABLE geotb (location_d geometry(LINESTRINGzm))
andCREATE TABLE geotb (location_d json)
the cost of solution 2 is saving a big Json in db but can be used directly in Kepler, solution2 saves points as binary type(with higher perfomance) and we will be able to manipulate it by means of PostGIS functions and routines
You can add the
EPOCH
of your time stamp to the coordinate pairs using theZ
dimension, e.g.POINT Z
:To convert the epoch back to timestamp ..
To convert the geometry to GeoJSON
.. and this creates your FeatureCollection:
Demo:
db<>fiddle