mbt

package
v0.0.9-a Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2016 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Diglet is a set of geospatial tools focused around rendering large feature sets efficiently.

Index

Constants

This section is empty.

Variables

View Source
var (
	CsvExt     = "csv"
	GeojsonExt = "geojson"
)
View Source
var Cmd = cli.Command{
	Name:        "mbt",
	Aliases:     []string{"build"},
	Usage:       "Builds an mbtiles database from the input data source",
	Description: "Builds an mbtiles database from the given format",
	ArgsUsage:   "input_source",
	Action: func(c *cli.Context) {

		out := c.String("output")
		desc := c.String("desc")
		layer := c.String("layer-name")
		zmin := uint(c.Int("min"))
		zmax := uint(c.Int("max"))
		extent := uint(c.Int("extent"))
		upsert := c.Bool("upsert")
		force := c.Bool("force")

		if len(c.Args()) == 0 || out == "" {
			util.Die(c, "input_source & --out required")
		} else if zmax < zmin || zmin < 0 || zmax > 23 {
			util.Die(c, "--max > --min, --min > 0 --max < 24 not satisfied")
		}

		source, err := getSource(c)
		util.Check(err)
		if force {
			os.Remove(out)
		}
		tiles, err := InitTiles(out, upsert, desc, extent)
		util.Check(err)
		err = tiles.Build(source, layer, zmin, zmax)
		util.Check(err)

		file, _ := os.Open(out)
		defer file.Close()
		stat, _ := file.Stat()
		exp := float64(stat.Size()) / float64(1<<20)
		util.Info("%s was successfully caught!", out)
		util.Info("Diglet gained %f MB of EXP!", exp)
	},
	Flags: []cli.Flag{
		cli.StringFlag{
			Name:  "o, output",
			Usage: "REQUIRED: Path to write mbtiles to",
		},
		cli.StringFlag{
			Name:  "input-type",
			Value: "sniff",
			Usage: "Type of input files, 'sniff' will pick type based on the extension",
		},
		cli.BoolFlag{
			Name:  "f, force",
			Usage: "Remove the existing .mbtiles file before running.",
		},
		cli.BoolFlag{
			Name:  "u, upsert",
			Usage: "Upsert into mbtiles instead of replacing.",
		},
		cli.StringFlag{
			Name:  "layer-name",
			Value: "features",
			Usage: "Name of the layer for the features to be added to",
		},
		cli.StringFlag{
			Name:  "desc, description",
			Value: "Generated from Diglet",
			Usage: "Value inserted into the description entry of the mbtiles",
		},
		cli.IntFlag{
			Name:  "extent",
			Value: 4096,
			Usage: "Extent of tiles to be built. Default is 4096",
		},
		cli.IntFlag{
			Name:  "max, max-zoom",
			Value: 10,
			Usage: "Maximum zoom level to build tiles for",
		},
		cli.IntFlag{
			Name:  "min, min-zoom",
			Value: 5,
			Usage: "Minimum zoom level to build tiles from",
		},
		cli.StringFlag{
			Name: "filter",
			Usage: "Only include fields keys in this comma delimited list.\t" +
				"EXAMPLE --filter name,date,case_number,id\t" +
				"NOTE all fields are lowercased and non-word chars replaced with '_'",
		},
		cli.StringFlag{
			Name:  "csv-lat",
			Usage: "Column containing a single longitude point",
		},
		cli.StringFlag{
			Name:  "csv-lon",
			Usage: "Column containing a single longitude point",
		},
		cli.StringFlag{
			Name: "csv-shape",
			Usage: "Column containing shape in geojson-like 'coordinates' form.\t" +
				"Does not support multi-geometries",
		},
		cli.StringFlag{
			Name:  "csv-delimiter",
			Value: ",",
		},
	},
}

Functions

This section is empty.

Types

type Coordinate

type Coordinate struct {
	Lat, Lon float64
}

func CoordinateFromString

func CoordinateFromString(raw string) (c Coordinate, err error)

[lon, lat]

type CsvSource

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

func NewCsvSource

func NewCsvSource(path string, filter []string, delimiter string, fields GeoFields) *CsvSource

func (*CsvSource) Publish

func (c *CsvSource) Publish(workers int) (features chan *Feature, err error)

type Feature

type Feature struct {
	Id         *uint64
	Geometry   []*Shape
	Type       string
	Properties map[string]interface{}
}

func MakeFeature

func MakeFeature(length int) *Feature

func NewFeature

func NewFeature(geometryType string, geometry ...*Shape) *Feature

func (*Feature) AddShape

func (f *Feature) AddShape(s *Shape)

func (*Feature) Center

func (f *Feature) Center() (avg Coordinate)

func (*Feature) SetF64Id

func (f *Feature) SetF64Id(id float64)

func (*Feature) ToMvtAdapter

func (f *Feature) ToMvtAdapter(tile ts.Tile) (adapter *mvt.Feature)

func (*Feature) ToTiledShapes

func (f *Feature) ToTiledShapes(tile ts.Tile) (shps []*mvt.Shape)

type FeatureSource

type FeatureSource interface {
	Publish(workers int) (chan *Feature, error)
}

type GeoFields

type GeoFields map[string]string

func (GeoFields) HasCoordinates

func (g GeoFields) HasCoordinates() bool

func (GeoFields) HasShape

func (g GeoFields) HasShape() bool

func (GeoFields) Validate

func (g GeoFields) Validate() bool

type GeojsonSource

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

func NewGeojsonSource

func NewGeojsonSource(path string, filter []string) *GeojsonSource

func (*GeojsonSource) Publish

func (gj *GeojsonSource) Publish(workers int) (features chan *Feature, err error)

type Shape

type Shape struct {
	Coordinates []Coordinate
}

func MakeShape

func MakeShape(length int) *Shape

func NewShape

func NewShape(coords ...Coordinate) *Shape

func ShapeFromString

func ShapeFromString(raw string) (shp *Shape, err error)

[[lon,lat]...]

func (*Shape) AddCoordinate

func (s *Shape) AddCoordinate(c Coordinate)

func (*Shape) Append

func (s *Shape) Append(c Coordinate)

func (*Shape) IsClockwise

func (s *Shape) IsClockwise() bool

func (*Shape) Reverse

func (s *Shape) Reverse()

func (*Shape) ToTileShape

func (s *Shape) ToTileShape(tile ts.Tile) (shp *mvt.Shape)

Unexported b/c the PointXY are still absolute, MVT needs relative

type Tiles

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

func InitTiles

func InitTiles(mbtpath string, upsert bool, desc string, extent uint) (tiles Tiles, err error)

func (Tiles) Build

func (t Tiles) Build(source FeatureSource, layerName string, zmin, zmax uint) (err error)

Directories

Path Synopsis
mvt
vector_tile
Package vector_tile provides the go code needed to read and write Mapbox vector tiles (https://github.com/mapbox/vector-tile-spec).
Package vector_tile provides the go code needed to read and write Mapbox vector tiles (https://github.com/mapbox/vector-tile-spec).
package tile_system is a collection of conversion utilities to go between geo/pixel/tile/quadkey space This package uses WGS84 coordinates and a mercator projection
package tile_system is a collection of conversion utilities to go between geo/pixel/tile/quadkey space This package uses WGS84 coordinates and a mercator projection

Jump to

Keyboard shortcuts

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