# Using postgis to generate building shades

I am currently working on a solar potential estimation tool for existing buildings. The idea is to use buildings (=Polygon) shape, their height, and create the resulting shade at a given hour. I am only going to do the test for a few position of the sun. I know about the grass function r.sun.mask but it is overpowered for what I am trying to do.

For now I only want to get the shade when the sun is south, at 18° in the sky. The building should therefore cast a shadow about three times its height.

What I am trying to get:

I have been looking for a while but I did not find any tool in postgis to do this. I was thinking about buffering and then cutting the polygon but could not make it work. Do you know any tool or have any idea how to do it?

Simplest way to do this is with an

ST_Extrude(geom,x-direction,y-direction,0)

You will have to calculate the extrude factor yourself of course and it assumes your whole polygon is the same height.(in your example, extrude would be like: `ST_Extrude(geom, 0, 3.0*height, 0)` )

Here is the manual on ST_Extrude. Keep in mind that you need postgis with SFCGAL for this, check the installation docs on how to get this if you don't already have it.

• The output shape is the one I want, however the Polyhedral Surface cannot be intersected with a Polygon. I tried the ST_Force2D on the polyhedral and then intersect it with my polygon but it does not work. Is there another function with a more practical output format, or a way to convert this polyhedral surface to polygon? Jun 2, 2017 at 14:12
• Yes, you can dump it to normal polygons. Example: `SELECT ST_AsText((ST_Dump(ST_Extrude(ST_MakeEnvelope(10,10,100,100,28992),0,8,0))).geom)`
– tilt
Jun 2, 2017 at 14:17

It might be worth considering exporting from QGIS to Blender as this would allow you to place the sun as a light and animate through the day and through the year. I did find a workflow here that looks relevant.