9 Replies Latest reply on Aug 5, 2015 11:56 AM by Bill Lyons

# Day and night change on map

Hi,

Does anyone know is it possible to make kind of that

Map of day night

animation in tableau's maps? I need one pattern of moving areas for 24 hours, want to put on that animation my data with hourly sales in different countries.

Maybe there is some way to to control the shades of background depending on variables?

• ###### 1. Re: Day and night change on map

Hello Andrew Zmeul,

After seeing noahsalvaterra.0's Build Your Own World Map, I think all things may be possible.

Check it out.

http://drawingwithnumbers.artisart.org/author/noah/

Patrick

• ###### 2. Re: Day and night change on map

Thanks for the shout out Patrick.

Yes, this could definitely be done, in a few ways at least. You could pad the **** out of your data and brute force it with polygons very much the way I did with my maps. In your case you'd need to either build a dynamic model of the position of the earth relative to the sun that included the spin, tilt if you're ambitious, the wobble a way that matches up with the calendar. I guess we have a few reference points to line this up with, i.e. solstices and equinoxes, but still I think it might be tricky to get this right on. Then you could figure out the half of the earth that was on the sunny side, or more importantly the great circle which is the boundary between day and night (assuming the equatorial bulge is negligible for this). Unwinding that circle onto Tableau's map would be one of the simpler pieces. I'd probably create polygons in thin vertical slices so I didn't run into trouble when they jump from one side of the planet to the other. If you've got it right then these slices should match up and change shape seasonally in the right way I don't think it would be very accurate if you only did 24 hours.

I probably wouldn't do it that way though. Instead I'd ping Allan Walker and see if he has a solution for this which would live totally in the background. Possibly on a WMS server? If you wanted this animation to work on server, then you could drive a date-time parameter through the javascript API. Can you build a dynamic background map that would also accept this parameter? Not sure if this is even a viable solution, but if it isn't maybe Allan has another trick up his sleeve.

I can't think of an easy way if that is what you're asking, but I think it would be a sort of cool feature, so if you submit it as an idea let me know so I can vote for it.

N.

• ###### 3. Re: Day and night change on map

Yes, it can be done, but it will require a LOT of complex math. There is no simple one-click solution. It will require a formula to calculate the latitude for the terminator at each longitude point (at intervals such as 1 second, 1 minute, 10 minutes, or whatever resolution seems appropriate) for the particular date-time. Then, it is just a matter of using that set of coordinates to plot a polygon using the methods I describe at Mapping polygons and points together dual axis.

I like a challenge, so I am willing to tackle the math if you are sure you are willing to use the results using the described method. It will likely take a few days, since I do this in my "spare" time.

• ###### 4. Re: Day and night change on map

FYI - I almost have this finished. I just need to clean it up and document it, and expect to publish it later this morning.

• ###### 5. Re: Day and night change on map

Success! Check out the attached workbook. It uses formulas from Solar Time | PVEducation to calculate the coordinates of the terminator (sunrise or sunset) based on day and time. You can test it with manually entered dates and times, or set it to automatic (be sure to set your [Time Zone Offset] appropriately).

This was a fun challenge!

EDIT 6/11/2015 3:33PM PDT - Attachment replaced which fixes a bug on the day of an Equinox, and includes a nicer dashboard.

• ###### 6. Re: Day and night change on map

Bill,

I have no words to describe the awesome that this is.

Amazing work!

Regards,

Rody

• ###### 7. Re: Day and night change on map

hi Bill,

This is absolutely amazing!

I did actually see this question a few weeks back, and have been having a play (20 mins here and there) trying to play with various solutions (purely for fun!)...and failing miserably!! I started messing about with sin curves, in an attempt to get the general idea, but hadn't even got to the stage of thinking how I'd get the sin curve to reflect the part of the earth in shadow, let alone making it dynamic!...As someone who has tried, and failed, I appreciate what a great piece of work this is...and the extra bit on the paramterisation of live/set time are lovely touches

...this goes straight into my, 'What you can do with Tableau' deck (which I use when I'm loosing the room!! )

Sir my cap it tipped!!

• ###### 8. Re: Day and night change on map

Thanks so much! That is very high praise from a fellow Ambassador!

• ###### 9. Re: Day and night change on map

Please see my new and much improved version at Day-night map with twilight and marks.