PostGIS – Fix PolyhedralSurface Geometry Type Not Supported in GeoJSON

3dcesiumgeojsonpostgis

I am trying to make a 3D web application which should be able to render 3D buildings (I will be using Cesium, but that is not that important for now).

I basically have a database consisting of the 2D geometry of the buildings and the height, amongst other things. In that way I should be able make simple 3D building blocks (LoD1). I am using PostGIS (PostGIS 2.2.0 with SFCGAL extension) to extrude (st_extrude) the 2D geometry to a 3D geometry. No problem so far…

The problem I am facing now is that st_extrude gives me a polyhedral surface. However, I would like to convert my 3D geometry to GeoJSON (which can easily be loaded into my Cesium viewer). St_AsGeoJSON gives me an error saying that 'PolyhedralSurface' geometry type is not supported.

Do you guys know if I can work around this problem? Are there any similar functions in PostGIS like st_extrude which will not leave me with a polyhedral surface?

I'm looking into using st_Dump to try and transform my polyhedral surface into a multipolygon, because I will be able to make a GeoJSON type with a multipolygon.

As far as I can tell by looking at the documentation, using st_dump will give me six "facets" (say my building is a standard cube). Does someone know if I will be able to leave out the side-facets of my cube and just keep the top and bottom? Will I be able to go to a multipolygon from there? Just an idea I had today…

Best Answer

Well if you want to have just top and bottom, ST_Extrude is overkill. You can just use a combination of ST_Force3D(ST_Translate(..)

http://postgis.net/docs/manual-2.2/ST_Force_3D.html , http://postgis.net/docs/manual-2.2/ST_Translate.html

The SFCGAL guys (Oslandia) also use Cesium as well, so you might want to check out their offerings in this department.

https://github.com/Oslandia/cesium-buildings

I use X3D for my 3d rendering of polyhedral surfaces and TINS, but not sure if Cesium has a mapping for that.

http://postgis.net/docs/manual-2.2/ST_AsX3D.html