We are working on a project where we want to make a route planner that takes into account the amount of sun on the route. The goal would be to calculate 'solar car' friendly routes. We are using PostGIS, because of the pgRouting extension for the route finding.

We have building polygons with a height attribute available. So far we have not been able to find PostGIS functions that could deal with calculating shadows.

How do you calculate polygon shadows in PostGIS?

Using PostGIS to generate building shades seem to be simply wrong (correct us if we're missing anything). The answer suggests extruding a 3D polyhedral from a 2D surface. That does not seem to generate a shadow. Only if you visualize it in 2D.

This is what we want as result (picture from H2GIS):

enter image description here

  • I believe that this should be approximately possible using st_azimuth, st_extrude and some vector calcs to project the intersection of the building roof area on the ground based on time of day. I don't have a laptop in front on me, but it is an interesting problem and related to some work I am already doing. – John Powell Apr 14 '18 at 19:06
  • 50cm DSM, weeps with jealousy, which country or region, out of interest – John Powell Apr 14 '18 at 19:08
  • The Netherlands. See: pdok.nl/nl/ahn3-downloads (only in Dutch) – LMB Apr 14 '18 at 20:55
  • Have you thought of using Cesium to do the shadows? While I am certain it can be done in Postgis, it might be more natural in Cesium. I guess it depends on how you are presenting it? – John Powell Apr 17 '18 at 15:08
  • @JohnPowellakaBarça, Thanks for the suggestion. Actually we will not be presenting the shadows at all. They will only be used as input for determining the 'cost' i.e. shadowness of a route. – LMB Apr 18 '18 at 7:00

As the earth move you will have to recalculate the shadow each time you seek a route (the shadow move during the day depending of the hour but also is different at the same hour on different day depending on the season..) if you are looking at a somewhat big area and want reasonable accuracy this will be very computational intensive....

(I try something similar, on a laptop with grass a raster (1m cell size, 100 square kilometer area) and the calculation time was so long (for only one specific day and time) that I give up...)

Anyway unless you are looking at a very flat area you will need to factor the ground elevation to get the real height of the roof top (basically you need to create a DSM from a DEM and your building) and be able to calculate the shadow

  • We also have a 50cm cellsize DSM available, so we could also use that. But than the question remains, is there a postgis function to calculate the shadow? Or should we do that in QGIS with a grass or other function? – LMB Apr 12 '18 at 17:27
  • I don't know about postgis but grass has the r.sun (grass.osgeo.org/grass75/manuals/r.sun.html) that can derive shadow map – J.R Apr 13 '18 at 8:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.