globe

package module
v0.0.0-...-d41128b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 9, 2024 License: ISC Imports: 4 Imported by: 7

README

globe

Globe wireframe visualizations in Golang backed by pinhole.

go.dev Reference Build status

Getting Started

Install globe with

$ go get -u github.com/mmcloughlin/globe

Start with a blank globe with a graticule at 10 degree intervals.

g := globe.New()
g.DrawGraticule(10.0)
g.SavePNG("graticule.png", 400)

Add some land boundaries and center it on a point. Alternatively DrawCountryBoundaries will give you countries.

g := globe.New()
g.DrawGraticule(10.0)
g.DrawLandBoundaries()
g.CenterOn(51.453349, -2.588323)
g.SavePNG("land.png", 400)

Here's all the Starbucks locations. Note color.NRGBA recommended to avoid artifacts.

shops, err := LoadCoffeeShops("./starbucks.json")
if err != nil {
	log.Fatal(err)
}

green := color.NRGBA{0x00, 0x64, 0x3c, 192}
g := globe.New()
g.DrawGraticule(10.0)
for _, s := range shops {
	g.DrawDot(s.Lat, s.Lng, 0.05, globe.Color(green))
}
g.CenterOn(40.645423, -73.903879)
err = g.SavePNG("starbucks.png", 400)
if err != nil {
	log.Fatal(err)
}

You can also do lines along great circles.

g := globe.New()
g.DrawGraticule(10.0)
g.DrawLandBoundaries()
g.DrawLine(
	51.453349, -2.588323,
	40.645423, -73.903879,
	globe.Color(color.NRGBA{255, 0, 0, 255}),
)
g.CenterOn(50.244440, -37.207949)
g.SavePNG("line.png", 400)

Also rectangles.

g := globe.New()
g.DrawGraticule(10.0)
g.DrawLandBoundaries()
g.DrawRect(
	41.897209, 12.500285,
	55.782693, 37.615993,
	globe.Color(color.NRGBA{255, 0, 0, 255}),
)
g.CenterOn(48, 25)
g.SavePNG("rect.png", 400)

See examples and package documentation for more.

License

globe is available under the ISC License.

Documentation

Overview

Package globe builds 3D visualizations on the earth.

Index

Constants

This section is empty.

Variables

View Source
var DefaultStyle = Style{
	GraticuleColor: color.Gray{192},
	LineColor:      color.Gray{32},
	DotColor:       color.NRGBA{255, 0, 0, 255},
	Background:     color.White,
	LineWidth:      0.1,
	Scale:          0.7,
}

DefaultStyle specifies out-of-the box style options.

Functions

This section is empty.

Types

type Globe

type Globe struct {
	// contains filtered or unexported fields
}

Globe is a globe visualization.

func New

func New() *Globe

New constructs an empty globe with the default style.

func (*Globe) CenterOn

func (g *Globe) CenterOn(lat, lng float64)

CenterOn rotates the globe to center on (lat, lng).

func (*Globe) DrawCountryBoundaries

func (g *Globe) DrawCountryBoundaries(style ...Option)

DrawCountryBoundaries draws country boundaries on the globe. Uses the default LineColor unless overridden by style Options.

func (*Globe) DrawDot

func (g *Globe) DrawDot(lat, lng float64, radius float64, style ...Option)

DrawDot draws a dot at (lat, lng) with the given radius. Uses the default DotColor unless overridden by style Options.

func (*Globe) DrawGraticule

func (g *Globe) DrawGraticule(interval float64, style ...Option)

DrawGraticule draws a latitude/longitude grid at the given interval. Uses the default GraticuleColor unless overridden by style Options.

func (*Globe) DrawLandBoundaries

func (g *Globe) DrawLandBoundaries(style ...Option)

DrawLandBoundaries draws land boundaries on the globe. Uses the default LineColor unless overridden by style Options.

func (*Globe) DrawLine

func (g *Globe) DrawLine(lat1, lng1, lat2, lng2 float64, style ...Option)

DrawLine draws a line between (lat1, lng1) and (lat2, lng2) along the great circle. Uses the default LineColor unless overridden by style Options.

func (*Globe) DrawMeridian

func (g *Globe) DrawMeridian(lng float64, style ...Option)

DrawMeridian draws the meridian at longitude lng. Uses the default GraticuleColor unless overridden by style Options.

func (*Globe) DrawMeridians

func (g *Globe) DrawMeridians(interval float64, style ...Option)

DrawMeridians draws meridians at the given interval. Uses the default GraticuleColor unless overridden by style Options.

func (*Globe) DrawParallel

func (g *Globe) DrawParallel(lat float64, style ...Option)

DrawParallel draws the parallel of latitude lat. Uses the default GraticuleColor unless overridden by style Options.

func (*Globe) DrawParallels

func (g *Globe) DrawParallels(interval float64, style ...Option)

DrawParallels draws parallels at the given interval. Uses the default GraticuleColor unless overridden by style Options.

func (*Globe) DrawRect

func (g *Globe) DrawRect(minlat, minlng, maxlat, maxlng float64, style ...Option)

DrawRect draws the rectangle with the given corners. Sides are drawn along great circles, as in DrawLine. Uses the default LineColor unless overridden by style Options.

func (*Globe) Image

func (g *Globe) Image(side int) *image.RGBA

Image renders an image object for the visualization with dimensions (side, side).

func (*Globe) SavePNG

func (g *Globe) SavePNG(filename string, side int) error

SavePNG writes the visualization to filename in PNG format with dimensions (side, side).

type Option

type Option func(*Globe)

Option is a function that stylizes a globe.

func Color

func Color(c color.Color) Option

Color uses the given color.

type Style

type Style struct {
	GraticuleColor color.Color
	LineColor      color.Color
	DotColor       color.Color
	Background     color.Color
	LineWidth      float64
	Scale          float64
}

Style encapsulates globe display options.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL