The SE_LineFromBSON() function

The SE_LineFromBson() function takes a bson value with spatial data following the GeoJSON specification and a JSON path in a VARCHAR string, and returns an ST_LineString object.

Syntax

create function SE_LineFromBSON(bson,varchar(255))
returns ST_LineString

Return type

ST_LineString

Example

The city engineer wants to know the “LineString” of a city, an array of 2 or more positions.

The following code inserts one row for GeoJSON geometry type LineString.
-- create a table of bson value containing GeoJson spatial values under the city tag
create table bson_tab (pid serial, geometry bson, type varchar(16));
Table created.

insert into bson_tab values(0, ('{
		"city":{
			"type":"LineString",
			"coordinates" : [[1, 0], [3, 2], [4, 5]]
		}
	 }'::json)::bson,
	'LineString');
1 row(s) inserted.
The query selects a linestring value from the table by using SE_LineFromBSON.
select pid,se_linefrombson(geometry,'city') from bson_tab where type = 'LineString' ;

This is the result.

pid           2
(expression)  4326 LINESTRING (1 0, 3 2, 4 5) 

1 row(s) retrieved.

Copyright© 2019 HCL Technologies Limited