slippy

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2024 License: MIT Imports: 6 Imported by: 26

Documentation

Index

Constants

View Source
const (
	// DefaultTileSize is the tile size used if the given tile size is 0.
	DefaultTileSize = 256
	// Lat4326Max is the maximum degree for latitude on an SRID 4326 map
	Lat4326Max = 85.05112
	// Lon4326Max is the maximum degree for longitude on an SRID 4326 map
	Lon4326Max = 180
)
View Source
const MaxZoom = 22

MaxZoom is the lowest zoom (furthest in)

View Source
const MvtTileDim = 4096.0

MvtTileDim is the number of pixels in a tile

Variables

View Source
var (
	ErrNilBounds = errors.New("slippy: Bounds cannot be nil")
)

Functions

func Degree2Radians

func Degree2Radians(degree float64) float64

Degree2Radians converts degrees to radians

func Extent

func Extent(g TileGridder, t Tile) (*geom.Extent, error)

func MvtPixelRationForZoom

func MvtPixelRationForZoom(g TileGridder, zoom Zoom) float64

MvtPixelRationForZoom returns the ratio of pixels to projected units at the given zoom. This assumes an MVT tile is being used.

func PixelRatioForZoom

func PixelRatioForZoom(g TileGridder, zoom Zoom, tileDim uint64) float64

PixelRatioForZoom returns the ratio of pixels to projected units at the given zoom. Multiply this value by the pixel count in tile.buffer to get the expected conversion.

if zoom is larger the MaxZoom, it will be set to MaxZoom if tileDim is 0, it will be set to MvtTileDim

func PtFromLatLon

func PtFromLatLon(lat, lon float64) geom.Point

func Radians2Degree

func Radians2Degree(radians float64) float64

Radians2Degree converts radians to degrees

func RangeFamilyAt

func RangeFamilyAt(tile Tile, zoom Zoom, yield func(Tile) bool)

RangeFamilyAt returns an iterator function that will call the yield function with every related tile at the requested zoom. This will include the provided tile itself. (if the same zoom is provided). The parent (overlapping tile at a lower zoom level), or children (overlapping tiles at a higher zoom level).

Types

type Grid

type Grid struct {
	Srid proj.EPSGCode
	// contains filtered or unexported fields
}

func (Grid) FromNative

func (g Grid) FromNative(z Zoom, pt geom.Point) (tile Tile, err error)

func (Grid) SRID

func (g Grid) SRID() proj.EPSGCode

func (Grid) Size

func (g Grid) Size(z Zoom) (Tile, bool)

func (Grid) ToNative

func (g Grid) ToNative(tile Tile) (pt geom.Point, err error)

type Grid4326

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

func (Grid4326) FromNative

func (g Grid4326) FromNative(z Zoom, pt geom.Point) (tile Tile, err error)

FromNative will convert a pt in 3857 coordinates and a zoom to a Tile coordinate

func (Grid4326) SRID

func (Grid4326) SRID() proj.EPSGCode

func (Grid4326) Size

func (Grid4326) Size(z Zoom) (Tile, bool)

func (Grid4326) TileSize

func (g Grid4326) TileSize() uint32

func (Grid4326) ToNative

func (g Grid4326) ToNative(tile Tile) (pt geom.Point, err error)

type Tile

type Tile struct {
	// zoom
	Z Zoom
	// column
	X uint
	// row
	Y uint
}

Tile describes a slippy tile.

func FromBounds

func FromBounds(g TileGridder, bounds geom.PtMinMaxer, z Zoom) ([]Tile, error)

FromBounds returns a list of tiles that make up the bound given. The bounds should be defined as the following lng/lat points [4]float64{west,south,east,north}

The only errors this generates are if the bounds is nil, or any errors grid returns from
transformation the bounds points.

func NewTileMinMaxer

func NewTileMinMaxer(g TileGridder, ext geom.MinMaxer) (Tile, error)

func (Tile) Equal

func (tile Tile) Equal(other Tile) bool

Equal tests for equality

func (Tile) FamilyAt

func (tile Tile) FamilyAt(zoom Zoom) func(yield func(Tile) bool)

FamilyAt returns an iterator function that will call the yield function with every related tile at the requested zoom. This will include the provided tile itself. (if the same zoom is provided). The parent (overlapping tile at a lower zoom level), or children (overlapping tiles at a higher zoom level).

	This function is structured so that it can take advantage of go1.23's Range Funcs. e.g.:
    for tile := range aTile.FamilyAt(10) {
       fmt.Printf("got tile: %v\n",tile)
    }

func (Tile) Less

func (tile Tile) Less(other Tile) bool

Less weather the `other` tile is less than the tile, by first checking the zoom, then the x coordinate, and finally the y coordinate.

func (Tile) String

func (tile Tile) String() string

func (Tile) ZXY

func (tile Tile) ZXY() (Zoom, uint, uint)

type TileGridder

type TileGridder interface {
	// SRID returns the SRID of the coordinate system of the
	// implementer. The geometries returned by the other methods
	// will be in these coordinates.
	SRID() proj.EPSGCode

	// Size returns a tile where the X and Y are the size of that zoom's
	// tile grid. AKA:
	//	Tile{z, MaxX + 1, MaxY + 1
	Size(z Zoom) (Tile, bool)

	// FromNative converts from a point (in the Grid's coordinates system) and zoom
	// to a tile.
	FromNative(z Zoom, pt geom.Point) (tile Tile, err error)

	// ToNative returns the tiles upper left point. ok will be false if
	// the tile is not valid. A note on implementation is that this method
	// should be able to take tiles with x and y values 1 higher than the max,
	// this is to fetch the bottom right corner of the grid
	ToNative(Tile) (pt geom.Point, err error)
}

TileGridder contains the tile layout, including ability to get WGS84 coordinates for tile extents

func NewGrid

func NewGrid(srid proj.EPSGCode, tileSize uint32) TileGridder

NewGrid will return a grid for the requested EPSGCode. if tileSize is zero, then the DefaultTileSize is used

type Zoom

type Zoom uint

Zoom represents a zoom level; this usually goes from 0 to 22

func (Zoom) N

func (z Zoom) N() float64

func (Zoom) TileSize

func (z Zoom) TileSize() Tile

Jump to

Keyboard shortcuts

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