Search code examples
geocodinggoogle-earthgoogle-earth-plugingeo

How to determine sunset/sunrise including terrain shadows.


In Google Earth you can use the "Sunlight" layer to view shadows cast by the terrain at any given DateTime: https://i.sstatic.net/YFGMj.png

However, I have not been able to find any way to access the sunlight/luminosity/shadow/etc values from the API.

I'm looking for a way to supply Lat, Long and DateTime to determine if an area is in sunlight (taking terrain shadows in to account, there are countless services that will provide simple Sunrise and Sunset times, but these do not consider terrain). This can be done manually with Google Earth, but I'm looking for a programatic method.

Thanks for any thoughts, ideas, leads...


Solution

  • I am not sure about determining whether an AOI in in the sun or shade at a certain time, however you can set the SUN to be on or off in the API by using

    GESun.setVisibility

    Edit:

    Using the GE-plugin, create a LookAt with your desired AOI lat/long where the view is directly above looking straight down. Depending on the size of you actual AOI I would keep the view as low to the ground as possible.

    Then capture a screenshot/image - I do not think this is possible through GE (if anyone knows a way I would like to find out), so maybe use javascript to take it - I found this Q on SO that provides some insight.

    Take a screenshot with GESun.setVisibility set ON and then another with it OFF

    Compare the two images for darkness/lightness or something and determine if your AOI is in the shade or not. You might find it better to surround your AOI in a Polygon of some sort in order to help your program distinguish it from the rest of the image - depending on the height the LookAt was taken from etc etc....

    I do not have any ideas on how to compare the images, but yet again another search on SO resulted in this (I would presume finding the values of COLOR_BLACK in PHP ImageMagick) and this (Color Buckets idea). Depending on your method of choice, it might help to alter your images to black/white before doing the comparing.