Code Monkey home page Code Monkey logo

Comments (4)

alex-hhh avatar alex-hhh commented on June 15, 2024

The new weather data provider is DarkSky.net (#33), the JSON response for a weather query also returns the timezone (both named and as an hour offset) for the GPS coordinates -- this could be used to determine the local time and it saves us the trouble of implementing our own timezone mapping service.

from activitylog2.

alex-hhh avatar alex-hhh commented on June 15, 2024

Found this on Google+, but with Google+ going away, it seems prudent to save the comment here. The original link is at:

https://plus.google.com/u/0/+BradFitzpatrick/posts/XVyy1bAzkZd


Fun with rendering timezones. (with #golang , naturally)

Goal: map (lat, long) -> timezone name, with minimal memory footprint. Camlistore needs this, to know the actual time of a photo when EXIF only has local time and GPS, but not timezone (which approximately 0 cameras on the market populate). Without knowing the actual time, it's impossible to sort your photos in the web UI with respect to related foursquare checkins, tweets, etc.

I started going down the route of using S2 geometry to do this properly, but rendering a map and doing a lat-long -> pixel -> color lookup works well enough.

But keeping a 10800 x 5400 pixel image is 111 MB of memory uncompressed for our "lookup table". Or storing 9 bits per pixel (tricky) is still ~65 MB of memory. We can do better.

Most the world isn't interesting. We only need to keep memory resident for the tricky areas.

How to find the tricky areas?

  • get timezone data files from http://efele.net/maps/tz/world/

  • parse them with http://github.com/jonas-p/go-shp

  • render the polygons with +Nigel Tao's http://godoc.org/code.google.com/p/freetype-go/freetype/raster and its MonochromePainter so there are hard-edges. the color is the RGBA CRC32 of the timezone name ("America/Los_Angeles") with the alpha set to 0xff. There are no conflicts in the 408 zones.

  • cut up the world into 100x100 pixels, then 50x50, then 25x25, then 10x10, looking for regions that are all the same color (or ocean, which doesn't count). note that region is all one zone.

  • Instead, store in memory only the pixel data for the tricky borders

Now, instead of 111 MB of pixel data to keep around in memory, I can keep 280 KB of pixel data and about a half MB of hashmap data for the 28722 regions of various sizes.

Zoom in on this image to see more detail.

/cc +Mathieu Lonjaret, +Brett Slatkin

Edit: now available at https://github.com/bradfitz/latlong

from activitylog2.

alex-hhh avatar alex-hhh commented on June 15, 2024

NOTE: the linked commits are intended for issue #7

from activitylog2.

alex-hhh avatar alex-hhh commented on June 15, 2024

This was implemented, see referenced commit.

from activitylog2.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.