We will be using the point cloud from the previous example to serve in X3D format. PostGIS documentation on X3D includes an example of using the ST_AsX3D function to output the formatted X3D code:
COPY(WITH pts AS (SELECT PC_Explode(pa) AS pt FROM chp07.giraffe) SELECT ' <X3D xmlns="http://www.web3d.org/specifications/x3d-namespace" showStat="false" showLog="false" x="0px" y="0px" width="800px" height="600px"> <Scene> <Transform> <Shape>' || ST_AsX3D(ST_Union(pt::geometry)) ||'</Shape> </Transform> </Scene> </X3D>' FROM pts) TO STDOUT WITH CSV;
We included the copy to STDOUT WITH CSV to make a dump in raw code. The user is able to save this query as an SQL script file and execute it from the console in order to dump the result into a file. For instance:
$ psql -U me -d postgis-cookbook -h localhost -f "x3d_query.sql" > result.html