The SE_MLineFromBSON() function
The SE_MLineFromBSON() function takes a bson value with spatial data following the GeoJSON specification and a JSON path in a VARCHAR string, and returns an ST_MultiLineString object.
Syntax
create function SE_MLineFromBSON(bson,varchar(255))
returns ST_MultiLineString
Return type
ST_MultiLineString
Example
The city engineer wants to know the “MultiLineString” of a city, an array of one or more LineStrings.
The following code inserts one row for GeoJSON geometry type MultiLineString.
-- 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":"MultiLineString",
"coordinates" : [[[1, 0], [3, 2], [4, 5]], [[11, 10], [13, 12]], [[111, 11], [13, 21]], [[11, 10], [13, 12], [131, 12], [132, 13], [134, 15], [135, 16]]]
}
}'::json)::bson,
'MultiLineString');
1 row(s) inserted.
The query selects a multiline value from the table by using
SE_MLineFromBSON.
select pid,se_mlinefrombson(geometry,'city') from bson_tab where type = 'MultiLineString' ;
This is the result.
pid 5
(expression) 4326 MULTILINESTRING ((1 0, 3 2, 4 5),(11 10, 13 12),(111 11, 13 21),(11 10, 13 12, 131 12, 132 13, 133 14, 134 15, 135 16))
1 row(s) retrieved.