map180

package module
v0.0.0-...-9dfd58c Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2016 License: Apache-2.0 Imports: 9 Imported by: 0

README

map180

map180 is a Go (golang) library for drawing SVG maps with markers on EPSG:3857.

  • It handles maps that cross the 180 meridian
  • Allows high zoom level data in a specified region.
  • Land and lake layer queries are cached for speed.

Once you have a database with the map data loaded (see below) drawing a map is as simple as:

wm, err = map180.Init(db, `public.map180_layers`, map180.Region(`newzealand`), 256000000)
b, err := wm.SVG(...)

See the Go docs for further details.

Database

Postgres 9.* with Postgis 2.*

Using the Assembled Data

  • Create the tables (and associated indexed) public.map180_layers and public.map180_labels. See etc/nz_map180_layer.ddl
  • Load the data e.g., for the fits db: psql -h 127.0.0.1 fits postgres -f data/new_zealand_map_layers.ddl

If necessary change the schema, table, and user access as required. They can be specificed in map180.Init()

Assembing Data

The goal is to end up with land and lakes multi polygon on EPSG:3857 entered into public.map180_layers and labels in public.map180_labels. The zoom region should include data for your region of interest at higher zoom levels.

The assembled New Zealand data set (data/new_zealand_map_layers.ddl) was made from shape files that where loaded into the DB and then cut and transformed into public.map180_layers and public.map180_layers.

The files etc/load-nz-shp.sh and etc/nz_map180_layer.ddl document the process of creating public.map180_layers. This was then dumped using:

pg_dump -h 127.0.0.1 --table=public.map180_layers --table=public.map180_labels --data-only -U postgres  fits -f data/new_zealand_map_layers.ddl

The assembled New Zealand data set uses data sourced from:

Documentation

Overview

map180 draws SVG maps on EPSG3857. It handles maps that cross the 180 meridian and allows high zoom level data in a specified region. Land and lake layer queries are cached for speed.

Index

Constants

View Source
const (
	Width3857 = 40075016.6855785
)

Variables

This section is empty.

Functions

func BboxToWKTPolygon

func BboxToWKTPolygon(boundingBox string) (p string, err error)

func SVGTriangle

func SVGTriangle(m Marker, b *bytes.Buffer)

SVGTriangle is an SVGMarker func.

func ValidBbox

func ValidBbox(boundingBox string) error

ValidBbox returns a nil error for a valid boundingBox. Valid options are one of:

  • an empty string: ""
  • a string definition of a bounding box using ',' separated longitude latitude (float) on EPSG4327. This should be lower left and upper right corners. It may cross 180. Longitude can be -180 to 180 or 0 to 360. Latitude must be <= 85.0 && >= -85.0 Examples: "165,-48,179,-34" // New Zealand "165,-48,-175,-34" // New Zealand and Chathams "165,-48,185,-34" // New Zealand and Chathams

Types

type Map180

type Map180 struct {
}

func Init

func Init(d *sql.DB, region Region, cacheBytes int64) (*Map180, error)

Init returns an initialised Map180. d must have access to the map180 tables in the public schema. cacheBytes is the size of the memory cache for land and lake layers. region must be a valid Region.

Example:

wm, err = map180.Init(db, map180.Region(`newzealand`), 256000000)

func (*Map180) Map

func (w *Map180) Map(boundingBox string, width int, pts Points, insetBbox string, buf *bytes.Buffer) (err error)

Map draws an SVG image to buf for the bbox regions. The returned map uses EPSG3857. Width is the SVG image width in pixels (height is calculated). pts haz X Y and values initialised for later drawing. The SVG in buf is not closed. See ValidBbox for boundingBox options.

func (*Map180) MapRaw

func (w *Map180) MapRaw(boundingBox string, width int) (mr Raw, err error)

MapRaw returns a Raw struct which can be used for drawing SVG maps e.g.,

raw, err := wm.MapRaw(bbox, width)
b := bytes.Buffer
b.WriteString(`<?xml version="1.0"?>`)
b.WriteString(fmt.Sprintf("<svg  viewBox=\"0 0 %d %d\"  xmlns=\"http://www.w3.org/2000/svg\">",
raw.Width, raw.Height))
b.WriteString(fmt.Sprintf("<rect x=\"0\" y=\"0\" width=\"%d\" height=\"%d\" style=\"fill: azure\"/>", raw.Width, raw.Height))
b.WriteString(fmt.Sprintf("<path style=\"fill: wheat; stroke-width: 1; stroke-linejoin: round; stroke: lightslategrey\" d=\"%s\"/>", raw.Land))
b.WriteString(fmt.Sprintf("<path style=\"fill: azure; stroke-width: 1; stroke-linejoin: round; stroke: lightslategrey\" d=\"%s\"/>", raw.Lakes))
b.WriteString("</svg>")

The other properties can be used to scale and translate for drawing on the map e.g.,

    type point struct {
	latitude, longitude float64
	x, y                float64
    }

    // create pts []point with x,y, set to EPSG3857 and latitude longitude EPSG4326
    // range of pts ...

    switch raw.CrossesCentral && p.longitude > -180.0 && p.longitude < 0.0 {
	case true:
		p.x = (p.x + map180.Width3857 - raw.LLX) * raw.DX
		p.y = (p.y - math.Abs(raw.YShift)) * raw.DX
	case false:
		p.x = (p.x - math.Abs(raw.XShift)) * raw.DX
		p.y = (p.y - math.Abs(raw.YShift)) * raw.DX
    }

    // draw p on SVG.

func (*Map180) SVG

func (w *Map180) SVG(boundingBox string, width int, markers []Marker, insetBbox string) (buf bytes.Buffer, err error)

SVG draws an SVG image showing a map of markers. The returned map uses EPSG3857. Width is the SVG image width in pixels (height is calculated). If boundingBox is the empty string then the map bounds are calculated from the markers. See ValidBbox for boundingBox options.

type Marker

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

func NewMarker

func NewMarker(longitude, latitude float64, id, label, shortLabel string) Marker

NewMarker returns a Marker to be drawn at longitude, latitude (EPSG:4327). Latitude must be in the range -85 to 85 otherwise the Marker will not be drawn. Defaults to a red triangle size 10.

func (*Marker) SetSVGMarker

func (m *Marker) SetSVGMarker(f SVGMarker)

SetSVGMarker sets the SVGMarker func that will be used to draw the marker.

func (*Marker) SetSize

func (m *Marker) SetSize(size int)

func (*Marker) SetSvgColour

func (m *Marker) SetSvgColour(colour string)

type Point

type Point struct {
	Longitude, Latitude float64

	Value                 float64 // Points can be sorted by Value.
	Stroke, Fill, Opacity string  // Optional for any later drawing funcs
	Size                  int     // Optional for any later drawing funcs
	// contains filtered or unexported fields
}

func (*Point) X

func (p *Point) X() int

Returns the SVG x coord for p. Map() must be called to set this value.

func (*Point) Y

func (p *Point) Y() int

Returns the SVG y coord for p. Map() must be called to set this value.

type Points

type Points []Point

func (Points) Len

func (p Points) Len() int

func (Points) Less

func (p Points) Less(i, j int) bool

func (Points) Swap

func (p Points) Swap(i, j int)

type Raw

type Raw struct {
	Land, Lakes    string  // land or lake polygons as strings for use in the d property of an SVG path.
	Height, Width  int     // the height and width for the map.
	DX             float64 // for scaling.
	XShift, YShift float64 // for translation.
	LLX            float64 // for translation.
	CrossesCentral bool    // true if the map crosses the 180 meridian.
}

type Region

type Region string
const (
	NewZealand Region = "newzealand"
)

type SVGMarker

type SVGMarker func(Marker, *bytes.Buffer)

Directories

Path Synopsis
Package nzmap is for drawing large scale context maps in SVG format of the New Zealand region.
Package nzmap is for drawing large scale context maps in SVG format of the New Zealand region.

Jump to

Keyboard shortcuts

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