The SE_MPolyFromBSON() function
The SE_MPolyFromBSON() function takes a bson value with spatial data following the GeoJSON specification and a JSON path in a VARCHAR string, and returns an ST_MultiPolygon object.
Syntax
create function SE_MPolyFromBSON(bson,varchar(255))
returns ST_MultiPolygon
Return type
ST_MultiPolygon
Example
The city engineer wants to know the “MultiPolygon” of a city, an array of one or more Polygons.
The following code inserts one row for GeoJSON geometry type MultiPolygon.
-- 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":"MultiPolygon",
"coordinates" : [[[[0, 0], [10, 0], [10, 10], [0, 10], [0, 0]], [[2, 2], [8, 2], [8, 8], [2, 8], [2, 2]]], [[[22, 22],[[28, 28],[22, 28],[22, 22]]]]
}
}'::json)::bson,
'MultiPolygon');
1 row(s) inserted.
The query selects a multipolygon value from the table by using
SE_MPolyFromBSON.
select pid,se_mpolyfrombson(geometry,'city') from bson_tab where type = 'MultiPolygon' ;
This is the result.
pid 6
(expression) 4326 MULTIPOLYGON (((0 0, 10 0, 10 10, 0 10, 0 0),(2 2, 2 8, 8 8, 8 2, 2 2)),((22 22, 28 22, 28 28, 22 28, 22 22)))
1 row(s) retrieved.