
Show HN: Globe visualizations in Golang - mmcloughlin
https://github.com/mmcloughlin/globe
======
fogleman
Glad to see more graphics work being done in Go. This is built on `pinhole`,
which is built on `gg`, a 2D rendering library that I wrote. How many layers
deep can we get? :)

[https://github.com/fogleman/gg](https://github.com/fogleman/gg)

~~~
mmcloughlin
Standing on the shoulders of giants :)

gg and pinhole made this easy to write. The globe package really just deals
with mapping (lat, lng) space to cartestian coordinates (and also includes
some land/country datasets).

~~~
tidwall
Looks so good. The detail is just amazing!

This may or may not be useful, but here's a Go package containing a bunch of
city data. It might be a good fit for people using your project.

[https://github.com/tidwall/cities](https://github.com/tidwall/cities)

~~~
mmcloughlin
Oh nice! Should have used this for the cities example here

[https://github.com/mmcloughlin/globe/blob/master/examples/ci...](https://github.com/mmcloughlin/globe/blob/master/examples/cities.go)

In fact I might switch it, since the cities json file I used has some
oddities.

------
warent
It's always nice seeing unique projects in Golang appear like this. Also worth
noting that this includes the ability to upload directly to imgur via the
github.com/mattn/imgur tool. Once thing that I particularly love about Go is
the built-in testing suite which mmcloughlin makes good use of.

The only critique I have here is to see some benchmarks! :)

~~~
mmcloughlin
Thanks! I was really glad to find that imgur tool. I wanted to make sure the
images in the README were kept in sync with the code.

Also credit has to go to
[https://github.com/tidwall/pinhole](https://github.com/tidwall/pinhole) where
all the actual rendering happens!

------
ivanbakel
The map in the readme is puzzling me. It's almost like a riddle: what is there
a lot of in the UK, east America, Portugal, and barely any of in Norway,
Spain, and Belgium? It looks country-related, since you can see the borders
defined pretty well. Is it the Starbucks data? It would explain why Finland
appears to have a few, compared to its neighbours.

~~~
mbel
Judging by used color, the picture might be a result of this demo:
[https://github.com/mmcloughlin/globe/blob/master/examples/ci...](https://github.com/mmcloughlin/globe/blob/master/examples/cities.go)

I have no idea what kind of cities might be listed in 'cities.json'.

~~~
mmcloughlin
Yes, the first image in the README is from cities.go. The data file is too big
so I didn't include it in the repo, but the Makefile will fetch it.

[https://github.com/mmcloughlin/globe/blob/master/examples/Ma...](https://github.com/mmcloughlin/globe/blob/master/examples/Makefile)

It came from this node package

[https://www.npmjs.com/package/cities.json/](https://www.npmjs.com/package/cities.json/)

It looks like the dataset has more cities in some countries than others.

------
sxv
How possible / appropriate would it be to utilize this library to create an
interactive version similar to this example using d3:
[https://www.jasondavies.com/maps/rotate/](https://www.jasondavies.com/maps/rotate/)

~~~
mmcloughlin
Jason Davies has some beautiful maps!

Interactive would be hard. It would be relatively simple to output an animated
gif though, as the pinhole library does here

[https://github.com/tidwall/pinhole/blob/master/examples/eart...](https://github.com/tidwall/pinhole/blob/master/examples/earth.go)

I'm planning to add this feature.

------
goblin89
Does anyone know why isn’t it possible to get the same perspective (preserving
scale, distances, areas) in Google Earth Web?

For example, you wouldn’t be able to get the shapes of continents along with
the size of the whole globe in Google Earth visually match the projection
under “line” example in README.

[0]
[https://earth.google.com/web/@54.45747286,-25.48168721,-8084...](https://earth.google.com/web/@54.45747286,-25.48168721,-8084.09363679a,16700413.46093416d,35y,0h,0t,0r)

~~~
dsl
There are lots of different map projections[1] and coordinate systems[2]. As
the old joke goes, "the best thing about standards is there are so many to
choose from!"

1\.
[https://en.wikipedia.org/wiki/Map_projection](https://en.wikipedia.org/wiki/Map_projection)

2\.
[https://en.wikipedia.org/wiki/Geographic_coordinate_system](https://en.wikipedia.org/wiki/Geographic_coordinate_system)

~~~
goblin89
If you want to map whole planet’s surface onto a plane then sure, there’re
tons of options (Dymaxion projection is my favorite). I can’t understand why
areas and distances would be distorted if user manipulates a 3D globe though;
yet it seems to be the case here.

~~~
dsl
That is exactly the problem. It is easy for programmers to start with a 3D
sphere and start randomly projecting things on to it. However the earth itself
is an ellipsoid that bulges around the equator, so again you have a projection
problem of people trying to put one shape onto a different shape.

------
Scirra_Tom
This looks really cool! One comment, in this picture:
[https://camo.githubusercontent.com/16434461a69346de4ee07b950...](https://camo.githubusercontent.com/16434461a69346de4ee07b950f8c9e3f7ec733b5/687474703a2f2f692e696d6775722e636f6d2f4b4a66496c396c2e706e67)

The left and right side of the rectangle are correctly bent around the shape
of the globe. However, the top and bottom sides of the rectangle are not. Is
this intention (or am I being stupid?)

~~~
panic
The red lines are the shortest paths between the corners of the rectangle, not
lines of constant latitude (which would follow the latitude lines drawn on the
globe).

------
graetzer
Looks really cool! How many points can one draw with this before it becomes
too slow? I did a similar looking 3D globe animation with WebGL once and the
total number of points was quite an issue

[http://jsfiddle.net/go2t1r4q/2/](http://jsfiddle.net/go2t1r4q/2/)

------
elcapitan
Looks great!

Was there a particular reason why you chose Go to implement this? (strong side
of the language or sth like that)

~~~
mmcloughlin
Thanks!

I guess I wanted to use it to visualize data coming from other Go projects I
was working on, so it made sense. A tiny example of this is
[https://github.com/mmcloughlin/spherand](https://github.com/mmcloughlin/spherand)
which correctly generates random points on a sphere. I also had seen pinhole
([https://github.com/tidwall/pinhole](https://github.com/tidwall/pinhole)) and
thought it would be fun to play around with.

------
AYBABTME
That's pretty cool! It would be nice if the API allowed writing to io.Writer
instead of taking filenames.

~~~
mmcloughlin
If you'd like to output to an arbitrary writer, you can use the Image method.

[https://godoc.org/github.com/mmcloughlin/globe#Globe.Image](https://godoc.org/github.com/mmcloughlin/globe#Globe.Image)

This can be passed to an image encoder like

[https://golang.org/pkg/image/png/#Encode](https://golang.org/pkg/image/png/#Encode)
[https://golang.org/pkg/image/gif/#Encode](https://golang.org/pkg/image/gif/#Encode)
[https://golang.org/pkg/image/jpeg/#Encode](https://golang.org/pkg/image/jpeg/#Encode)

These functions take io.Writer objects. SavePNG was provided for convenience.

------
gravypod
Are there any provisions for drawing a color mesh on something like this?

Thanks!

------
newtem0
I need to learn go

~~~
kmicklas
No you don't, it has no benefits relative to languages in its space of
competition (Rust, D, various JVM/.NET languages, Haskell, ML, Nim, etc.).

~~~
xyproto
Team friendlyness, simplicity, readability, tooling, native compilation, built
in syntax for concurrency and really fast compilation times for large
projects.

~~~
Dzugaru
Few of these, honestly, benefit one man side projects. If you want to learn Go
(for whatever reason) its fine, but otherwise I personally would prefer more
expressive and less dogmatic language.

~~~
detaro
Who said they wanted to learn it for "one man side projects"?

~~~
Dzugaru
This is what OP project is, no?

Two people see cool sideproject in Go, his thoughts "damn this looks good, I
need to learn Go", my thoughts "Whyyy you do this in Go and not D? Simplistic
Go has no strong sides here! Why nobody promotes my favourite language with
things like this, it deserves hype no less!"

~~~
hactually
I guess it's because no one is writing anything "cool" in D?

Simplistic Go has a lot going for it - focussing on knocking out cool projects
rather than the minutiae of build/package/dependency systems is one of them.

~~~
Dzugaru
Its because D has way less developers, support and, consequently, way less
hype, than a language backed by one of the biggest world corporations in
existence.

Anyway, care to elaborate whats wrong with excellent build/package/dependency
system in D called Dub? Never had any problems with it.

~~~
hactually
[https://www.google.com.au/search?q=D+Dub](https://www.google.com.au/search?q=D+Dub)

I gave up after the Urban dictionary link. I assume you're trolling?

~~~
Dzugaru
Try googling "go" instead of "golang" then. Try "dlang dub" after that.
Thanks.

