carto

package
v0.2.12 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2021 License: BSD-2-Clause, GPL-3.0 Imports: 16 Imported by: 2

README

carto

Go language GIS map drawing library

Documentation

Overview

Package carto is a Go language map drawing library

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Degrees2meters

func Degrees2meters(lon, lat float64) (x, y float64)

convert from long/lat to google mercator (or EPSG:4326 to EPSG:900913)

func DrawShapes

func DrawShapes(f io.Writer, strokeColor, fillColor []color.NRGBA,
	linewidth, markersize vg.Length, shapes ...geom.Geom) error

Convenience function for making a simple map.

func GetGoogleTileBounds

func GetGoogleTileBounds(zoom, x, y int) (N, S, E, W float64)

Types

type Canvas

type Canvas struct {
	draw.Canvas
	Bounds  *geom.Bounds // geographic boundaries of map
	Polygon geom.Polygon
	// contains filtered or unexported fields
}

Canvas is a canvas for drawing maps.

func NewCanvas

func NewCanvas(N, S, E, W float64, c draw.Canvas) *Canvas

func (*Canvas) Coordinates

func (m *Canvas) Coordinates(p geom.Point) vg.Point

Coordinates transforms geographic coordinates to coordinates on the canvas.

func (*Canvas) DrawVector

func (m *Canvas) DrawVector(g geom.Geom, fillColor color.NRGBA,
	lineStyle draw.LineStyle, markerGlyph draw.GlyphStyle) error

Draw a vector on a raster map when given the geometry, stroke and fill colors, the width of the bounding line, and the markerGlyph, which specifies the shape of the marker (only used for point shapes).

type ColorMap

type ColorMap struct {
	draw.Canvas

	Type          ColorMapType
	CutPercentile float64 // Percentile at which discontinuity occurs for "LinCutoff" type.
	NumDivisions  int     // "Number of tick marks on legend.

	LegendWidth       vg.Length // width of legend in inches
	LegendHeight      vg.Length // height of legend in inches
	LineWidth         vg.Length // width of lines in legend in points
	FontSize          vg.Length // font size in points.
	GradientLineWidth vg.Length // Width of lines that make up legend gradient
	Font              string    // Name of the font to use in legend
	FontColor         color.Color
	EdgeColor         color.Color // Color for legend outline
	BackgroundColor   color.Color

	ColorScheme Colorlist
	// contains filtered or unexported fields
}

func NewColorMap

func NewColorMap(Type ColorMapType) (c *ColorMap)

Initialize new color map.

func (*ColorMap) AddArray

func (c *ColorMap) AddArray(data []float64)

func (*ColorMap) AddArrayServer

func (c *ColorMap) AddArrayServer(datachan chan []float64,
	finished chan int)

func (*ColorMap) AddGeoJSON

func (c *ColorMap) AddGeoJSON(g *GeoJSON, propertyName string)

func (*ColorMap) AddMap

func (c *ColorMap) AddMap(data map[string]float64)

func (*ColorMap) GetColor

func (cm *ColorMap) GetColor(v float64) color.NRGBA

GetColor gets color for input value. Must run c.Set() first.

func (*ColorMap) Legend

func (c *ColorMap) Legend(canvas *draw.Canvas, label string) (err error)

Legend draws a legend to the supplied canvas.

func (*ColorMap) Set

func (c *ColorMap) Set()

Figure out rules for color map

type ColorMapType

type ColorMapType int
const (
	Linear    ColorMapType = iota // Linear color gradient
	LinCutoff                     // linear with a discontinuity at a percentile

)

type Colorlist

type Colorlist struct {
	Val, R, G, B        []float64
	HighLimit, LowLimit color.NRGBA
}
var (
	// optimized olors from http://www.cs.unm.edu/~kmorel/documents/ColorMaps/index.html
	// Originally the 255 values were 221's
	Optimized Colorlist = Colorlist{
		[]float64{-1., -0.9375, -0.875, -0.8125,
			-0.75, -0.6875, -0.625, -0.5625, -0.5, -0.4375, -0.375,
			-0.3125, -0.25, -0.1875, -0.125, -0.0625, 0., 0.0625, 0.125,
			0.1875, 0.25, 0.3125, 0.375, 0.4375, 0.5, 0.5625, 0.625,
			0.6875, 0.75, 0.8125, 0.875, 0.9375, 1.},
		[]float64{59., 68, 77, 87, 98, 108, 119, 130, 141, 152,
			163, 174, 184, 194, 204, 213, 255, 229, 236, 241, 245, 247,
			247, 247, 244, 241, 236, 229, 222, 213, 203, 192, 180},
		[]float64{76., 90, 104, 117, 130, 142, 154, 165, 176,
			185, 194, 201, 208, 213, 217, 219, 255, 216, 211, 204, 196, 187,
			177, 166, 154, 141, 127, 112, 96, 80, 62, 40, 4},
		[]float64{192., 204, 215, 225, 234, 241, 247, 251, 254,
			255, 255, 253, 249, 244, 238, 230, 255, 209, 197, 185, 173, 160,
			148, 135, 123, 111, 99, 88, 77, 66, 56, 47, 38},
		color.NRGBA{70., 6, 16, 255},
		color.NRGBA{27., 34, 85, 255}}
	OptimizedGrey Colorlist = Colorlist{
		[]float64{-1., -0.9375, -0.875, -0.8125,
			-0.75, -0.6875, -0.625, -0.5625, -0.5, -0.4375, -0.375,
			-0.3125, -0.25, -0.1875, -0.125, -0.0625, 0., 0.0625, 0.125,
			0.1875, 0.25, 0.3125, 0.375, 0.4375, 0.5, 0.5625, 0.625,
			0.6875, 0.75, 0.8125, 0.875, 0.9375, 1.},
		[]float64{59., 68, 77, 87, 98, 108, 119, 130, 141, 152, 163, 174,
			184, 194, 204, 213, 221, 229, 236, 241, 245, 247, 247, 247, 244, 241,
			236, 229, 222, 213, 203, 192, 180},
		[]float64{76., 90, 104, 117, 130, 142, 154, 165, 176, 185, 194,
			201, 208, 213, 217, 219, 221, 216, 211, 204, 196, 187, 177, 166,
			154, 141, 127, 112, 96, 80, 62, 40, 4},
		[]float64{192., 204, 215, 225, 234, 241, 247, 251, 254, 255,
			255, 253, 249, 244, 238, 230, 221, 209, 197, 185, 173, 160, 148,
			135, 123, 111, 99, 88, 77, 66, 56, 47, 38},
		color.NRGBA{70., 6, 16, 255},
		color.NRGBA{27., 34, 85, 255}}
	Jet Colorlist = Colorlist{
		[]float64{-1, -0.866666666666667, -0.733333333333333, -0.6,
			-0.466666666666667, -0.333333333333333, -0.2, -0.0666666666666668,
			0.0666666666666665, 0.2, 0.333333333333333, 0.466666666666666, 0.6,
			0.733333333333333, 0.866666666666666, 1},
		[]float64{0, 0, 0, 0, 0, 0, 66, 132, 189, 255, 255, 255,
			255, 255, 189, 132},
		[]float64{0, 0, 66, 132, 189, 255, 255, 255, 255, 255, 189,
			132, 66, 0, 0, 0},
		[]float64{189, 255, 255, 255, 255, 255, 189, 132, 66, 0, 0,
			0, 0, 0, 0, 0},
		color.NRGBA{249., 15, 225, 255},
		color.NRGBA{154., 0, 171, 255}}
	JetPosOnly Colorlist = Colorlist{
		[]float64{-1, 0, 0.0666666666666667, 0.133333333333333, 0.2,
			0.266666666666667, 0.333333333333333, 0.4, 0.466666666666667,
			0.533333333333333, 0.6, 0.666666666666667, 0.733333333333333, 0.8,
			0.866666666666667, 0.933333333333333, 1},
		[]float64{0, 0, 0, 0, 0, 0, 0, 66, 132, 189, 255, 255, 255,
			255, 255, 189, 132},
		[]float64{0, 0, 0, 66, 132, 189, 255, 255, 255, 255, 255, 189,
			132, 66, 0, 0, 0},
		[]float64{189, 189, 255, 255, 255, 255, 255, 189, 132, 66, 0,
			0, 0, 0, 0, 0, 0},
		color.NRGBA{249., 15, 225, 255},
		color.NRGBA{154., 0, 171, 255}}
)

type Crs

type Crs struct {
	Type       string   `json:"type"`
	Properties CrsProps `json:"properties"`
}

Coordinate reference system. Used for GeoJSON

type CrsProps

type CrsProps struct {
	Name string `json:"name"`
}

Coordinate reference system properties.

type DefaultLegendCanvas

type DefaultLegendCanvas struct {
	draw.Canvas
}

DefaultLegendCanvas is a default canvas for drawing legends.

func NewDefaultLegendCanvas

func NewDefaultLegendCanvas() *DefaultLegendCanvas

func (*DefaultLegendCanvas) WriteTo

func (c *DefaultLegendCanvas) WriteTo(w io.Writer) error

type GeoJSON

type GeoJSON struct {
	Type     string            `json:"type"`
	CRS      Crs               `json:"crs"`
	Features []*GeoJSONfeature `json:"features"`
}

func LoadGeoJSON

func LoadGeoJSON(r io.Reader) (*GeoJSON, error)

func (*GeoJSON) GetGeometry

func (g *GeoJSON) GetGeometry() ([]geom.Geom, error)

func (*GeoJSON) GetProperty

func (g *GeoJSON) GetProperty(propertyName string) []float64

func (*GeoJSON) Sum

func (g *GeoJSON) Sum(propertyName string) float64

type GeoJSONfeature

type GeoJSONfeature struct {
	Type       string             `json:"type"`
	Geometry   *geojson.Geometry  `json:"geometry"`
	Properties map[string]float64 `json:"properties"`
}

type MapData

type MapData struct {
	Cmap      *ColorMap
	Shapes    []geom.Geom
	Data      []float64
	DrawEdges bool
	draw.LineStyle
}

func NewMapData

func NewMapData(numShapes int, Type ColorMapType) *MapData

func (*MapData) ToGeoJSON

func (m *MapData) ToGeoJSON(valueName string) (*GeoJSON, error)

Convert map data to GeoJSON, where value name is a name for the data values being output.

func (*MapData) WriteGoogleMapTile

func (m *MapData) WriteGoogleMapTile(w io.Writer, zoom, x, y int) error

type RasterMap

type RasterMap struct {
	Canvas
	I *image.RGBA
}

func NewCanvasFromRaster

func NewCanvasFromRaster(S, W, dy, dx float64, ny, nx int,
	data []float64, cmap *ColorMap,
	flipVertical, flipHorizontal bool) *RasterMap

Make a new raster map from raster data. It is assumed that the outer axis in the data is the Y-axis (north-south) and the inner axis is the X-axis (west-east) (i.e., len(data)==nx*ny && val[j,i] = data[j*nx+i]).

func NewRasterMap

func NewRasterMap(N, S, E, W float64, width int) *RasterMap

func (*RasterMap) WriteTo

func (r *RasterMap) WriteTo(f io.Writer) error

type UnsupportedGeometryError

type UnsupportedGeometryError struct {
	Type reflect.Type
}

func (UnsupportedGeometryError) Error

func (e UnsupportedGeometryError) Error() string

Jump to

Keyboard shortcuts

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