Skip to content

Commit

Permalink
Merge pull request #177 from terranodo/v0.4.0
Browse files Browse the repository at this point in the history
V0.4.0
  • Loading branch information
ARolek authored Nov 12, 2017
2 parents 9cab707 + 02f695d commit 53fdf40
Show file tree
Hide file tree
Showing 283 changed files with 49,654 additions and 2,214 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.DS_Store
.idea
24 changes: 21 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
language: go

go:
- 1.9.x
- 1.8.x
- 1.7.x

notifications:
slack:
secure: TzRnZdJ1dhQJg9nby2oJ6qFj9Bl20VJ2aJXmXwADsj2ck/UGsFWpYNnqZVWvZomCZEJinFpA/h2TG1odEzg1BpCT0+rLIGQDAhIMVuici+nIs+DyPQmL2owG1LZ6/hzX09Y1mIZci0nmnI1wousfM8WDPRq5NSOsBeAMlixGR4g4lF8cp/R0B6CtcewtQx4RicdPJtopHDwXm5KI1/7euFcJwu15FWwWoUp6mOw+r44T1Md+qbqDKBbLSy+YvMkPcxI7HeECa7OP9OjkeUfU0BoMP6qqo9QTVX5v6lOHxA+FhueyyPrSTtNV377tilDy88kytqu6w8gcrxZOddj7nFbv6ErjfVaMfeepzk/HH2bzlLevvL+ukeJKrBNdmPuDRU3BqG5ygrdGAQUNpM7VSXLDcGrM2+ocVn/HO1NyXWwpejq7Gq0HWhNkYPHG5c7+khkQkRGJtg0wp9R3qXDAcRHLR+CHh89g5Blz4Wo6R/Q48MLJycbH/W56zsoe0xQ5Ww2eti16uSFE4kkiPt99uewWkPSfEZn4pyk+xCwDxgNDNu/BaV+Mjm4JTL1GjWalto+NLK7NsEg+6sEYok0CHkUb8MQV++r1KVfIaxC3zVuojIiOSB9/+JPtPd9w2iuVOlz0rrbXfKkkSf5wcmOguqk3aAfAgmcjAV9p1kI9pSc=
env:
global:
- RUN_POSTGIS_TESTS=yes
- PGUSER=postgres

services:
- postgresql

addons:
postgresql: "9.4"
apt:
packages:
- postgresql-9.4-postgis-2.3

install:
- bash ci/build_bindata.sh
- bash ci/config_postgis.sh

before_deploy:
- go get github.com/mitchellh/gox
Expand Down Expand Up @@ -39,3 +55,5 @@ deploy:
notifications:
email:
on_success: never
slack:
secure: TzRnZdJ1dhQJg9nby2oJ6qFj9Bl20VJ2aJXmXwADsj2ck/UGsFWpYNnqZVWvZomCZEJinFpA/h2TG1odEzg1BpCT0+rLIGQDAhIMVuici+nIs+DyPQmL2owG1LZ6/hzX09Y1mIZci0nmnI1wousfM8WDPRq5NSOsBeAMlixGR4g4lF8cp/R0B6CtcewtQx4RicdPJtopHDwXm5KI1/7euFcJwu15FWwWoUp6mOw+r44T1Md+qbqDKBbLSy+YvMkPcxI7HeECa7OP9OjkeUfU0BoMP6qqo9QTVX5v6lOHxA+FhueyyPrSTtNV377tilDy88kytqu6w8gcrxZOddj7nFbv6ErjfVaMfeepzk/HH2bzlLevvL+ukeJKrBNdmPuDRU3BqG5ygrdGAQUNpM7VSXLDcGrM2+ocVn/HO1NyXWwpejq7Gq0HWhNkYPHG5c7+khkQkRGJtg0wp9R3qXDAcRHLR+CHh89g5Blz4Wo6R/Q48MLJycbH/W56zsoe0xQ5Ww2eti16uSFE4kkiPt99uewWkPSfEZn4pyk+xCwDxgNDNu/BaV+Mjm4JTL1GjWalto+NLK7NsEg+6sEYok0CHkUb8MQV++r1KVfIaxC3zVuojIiOSB9/+JPtPd9w2iuVOlz0rrbXfKkkSf5wcmOguqk3aAfAgmcjAV9p1kI9pSc=
173 changes: 98 additions & 75 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,138 +1,166 @@
# Tegola

[![Build Status](https://travis-ci.org/terranodo/tegola.svg?branch=master)](https://travis-ci.org/terranodo/tegola)
[![Report Card](https://goreportcard.com/badge/github.com/terranodo/tegola)](https://goreportcard.com/report/github.com/terranodo/tegola)
[![Report Card](https://goreportcard.com/badge/github.com/terranodo/tegola)](https://goreportcard.com/badge/github.com/terranodo/tegola)
[![Godoc](http://img.shields.io/badge/godoc-reference-blue.svg?style=flat)](https://godoc.org/github.com/terranodo/tegola)
[![license](http://img.shields.io/badge/license-MIT-red.svg?style=flat)](https://github.com/terranodo/tegola/blob/master/LICENSE.md)

Tegola is a high performance vector tile server delivering [Mapbox Vector Tiles](https://github.com/mapbox/vector-tile-spec) leveraging PostGIS as the data provider.
Tegola is a vector tile server delivering [Mapbox Vector Tiles](https://github.com/mapbox/vector-tile-spec) leveraging PostGIS as the data provider.

## Near term goals
- [X] Support for transcoding WKB to MVT.
- [x] Support for `/z/x/y` web mapping URL scheme.
- [x] Support for PostGIS data provider.
## Features
- Native geometry processing (simplification, clipping, make valid, intersection, contains, scaling, translation)
- [Mapbox Vector Tile v2 specification](https://github.com/mapbox/vector-tile-spec) compliant .
- Embedded viewer with auto generated style for quick data visualization and inspection.
- Support for PostGIS as a data provider. Extensible to support additional data providers.
- Local filesystem caching. Extensible design to support additional cache backends.
- Parallelized tile serving and geometry processing.
- Support for Web Mercator (3857) and WGS84 (4326) projections.

## Running Tegola
1. Download the appropriate binary of tegola for your platform via the [release page](https://github.com/terranodo/tegola/releases).
2. Setup your config file and run. Tegola expects a `config.toml` to be in the same directory as the binary. You can set a different location for the `config.toml` using a command flag:

```
./tegola --config=/path/to/config.toml
./tegola -config=/path/to/config.toml
```

## URL Scheme
Tegola uses the following URL scheme:
## Server Endpoints

```
/
```

The server root will display a built in viewer with an auto generated style. For example:

![tegola built in viewer](https://raw.githubusercontent.com/terranodo/tegola/v0.4.0/docs/screenshots/built-in-viewer.png "tegola built in viewer")


```
/maps/:map_name/:z/:x/:y
```

Return vector tiles for a map. The URI supports the following variables:

- `:map_name` is the name of the map as defined in the `config.toml` file.
- `:z` is the zoom level of the map.
- `:x` is the row of the tile at the zoom level.
- `:y` is the column of the tile at the zoom level.

### Additional endpoints

```
/maps/:map_name/:layer_name/:z/:x/:y
```

Return vector tiles for a map layer. The URI supports the same variables as the map URI with the additional variable:

- `:layer_name` is the name of the map layer as defined in the `config.toml` file.


```
/capabilities
```
Will return a JSON encoded list of the server's configured maps and layers with various attributes. An example response:

```json
{
"maps": [{
"name": "zoning",
"uri": "/maps/zoning",
"layers": [{
"name": "landuse",
"minZoom": 12,
"maxZoom": 16
}]
}]
}
Return a JSON encoded list of the server's configured maps and layers with various attributes.

```
/capabilities/:map_name
```

Return [TileJSON](https://github.com/mapbox/tilejson-spec) details about the map.

```
/capabilities/:map_name/style.json
```

Return an auto generated [Mapbox GL Style](https://www.mapbox.com/mapbox-gl-js/style-spec/) for the configured map.


## Configuration
The tegola config file uses the [TOML](https://github.com/toml-lang/toml) format. The following example shows how to configure a PostGIS data provider with two layers. The first layer includes a `tablename`, `geometry_field` and an `id_field`. The second layer uses a custom `sql` statement instead of the `tablename` property.

Under the `maps` section, map layers are associated with dataprovider layers and their `min_zoom` and `max_zoom` values are defined. Optionally, `custom_tags` can be setup which will be encoded into the layer. If the same tags are returned from a data provider, the data provider's values will take precedence.
Under the `maps` section, map layers are associated with data provider layers and their `min_zoom` and `max_zoom` values are defined. Optionally, `default_tags` can be setup which will be encoded into the layer. If the same tags are returned from a data provider, the data provider's values will take precedence.

```toml

[webserver]
port = ":9090"
port = ":9090" # port to bind the web server to. defaults ":8080"

[cache] # configure a tile cache
type = "file" # a file cache will cache to the local file system
basepath = "/tmp/tegola" # where to write the file cache

# register data providers
[[providers]]
name = "test_postgis" # provider name is referenced from map layers
type = "postgis" # the type of data provider. currently only supports postgis
host = "localhost" # postgis database host
port = 5432 # postgis database port
database = "tegola" # postgis database name
user = "tegola" # postgis database user
password = "" # postgis database password
srid = 3857 # The default srid for this provider. If not provided it will be WebMercator (3857)
name = "test_postgis" # provider name is referenced from map layers (required)
type = "postgis" # the type of data provider. currently only supports postgis (required)
host = "localhost" # postgis database host (required)
port = 5432 # postgis database port (required)
database = "tegola" # postgis database name (required)
user = "tegola" # postgis database user (required)
password = "" # postgis database password (required)
srid = 3857 # The default srid for this provider. Defaults to WebMercator (3857) (optional)
max_connections = "50" # The max connections to maintain in the connection pool. Default is 100. (optional)

[[providers.layers]]
name = "landuse" # will be encoded as the layer name in the tile
tablename = "gis.zoning_base_3857" # sql or table_name are required
geometry_fieldname = "geom" # geom field. default is geom
id_fieldname = "gid" # geom id field. default is gid
srid = 4326 # the srid of table's geo data.

name = "landuse" # will be encoded as the layer name in the tile
tablename = "gis.zoning_base_3857" # sql or table_name are required
geometry_fieldname = "geom" # geom field. default is geom
id_fieldname = "gid" # geom id field. default is gid
srid = 4326 # the srid of table's geo data. Defaults to WebMercator (3857)

[[providers.layers]]
name = "roads" # will be encoded as the layer name in the tile
tablename = "gis.zoning_base_3857" # sql or table_name are required
geometry_fieldname = "geom" # geom field. default is geom
id_fieldname = "gid" # geom id field. default is gid
name = "roads" # will be encoded as the layer name in the tile
tablename = "gis.zoning_base_3857" # sql or table_name are required
geometry_fieldname = "geom" # geom field. default is geom
id_fieldname = "gid" # geom id field. default is gid
fields = [ "class", "name" ] # Additional fields to include in the select statement.
srid = 3857 # the srid of table's geo data. Don't need to specify this as it will inherit this from the provider.

[[providers.layers]]
name = "rivers" # will be encoded as the layer name in the tile
geometry_fieldname = "geom" # geom field. default is geom
id_fieldname = "gid" # geom id field. default is gid
# Custom sql to be used for this layer. Note: that the geometry field is wraped
geometry_fieldname = "geom" # geom field. default is geom
id_fieldname = "gid" # geom id field. default is gid
# Custom sql to be used for this layer. Note: that the geometery field is wraped
# in a ST_AsBinary, as tegola only understand wkb.
sql = """
SELECT
gid,
ST_AsBinary(geom) AS geom
FROM
gis.rivers
WHERE
geom && !BBOX!
SELECT
gid,
ST_AsBinary(geom) AS geom
FROM
gis.rivers
WHERE
geom && !BBOX!
"""

# maps are made up of layers
[[maps]]
name = "zoning" # used in the URL to reference this map (/maps/:map_name)
name = "zoning" # used in the URL to reference this map (/maps/:map_name)

[[maps.layers]]
provider_layer = "test_postgis.landuse" # must match a data provider layer
min_zoom = 12 # minimum zoom level to include this layer
max_zoom = 16 # maximum zoom level to include this layer
provider_layer = "test_postgis.landuse" # must match a data provider layer
min_zoom = 12 # minimum zoom level to include this layer
max_zoom = 16 # maximum zoom level to include this layer

[maps.layers.default_tags] # table of default tags to encode in the tile. SQL statements will override
[maps.layers.default_tags] # table of default tags to encode in the tile. SQL statements will override
class = "park"

[[maps.layers]]
provider_layer = "test_postgis.rivers" # must match a data provider layer
min_zoom = 10 # minimum zoom level to include this layer
max_zoom = 18 # maximum zoom level to include this layer
provider_layer = "test_postgis.rivers" # must match a data provider layer
min_zoom = 10 # minimum zoom level to include this layer
max_zoom = 18 # maximum zoom level to include this layer
```

### Supported PostGIS SQL tokens
The following tokens are supported in custom SQL queries for the PostGIS data provider:

```
- `!BBOX!` - [required] Will convert the z/x/y values into a bounding box to query the feature table with.
- `!ZOOM!` - [optional] Pass in the zoom value for the request. Useful for filtering feature results by zoom.

## Command flags
Tegola currently supports the following command flags:
## Command line flags
Tegola supports the following command flags:

- `config` - Location of config file in TOML format. Can be absolute, relative or remote over http(s).
- `port` - Port for the webserver to bind to. i.e. :8080
- `log-file` - Path to write webserver access logs
- `log-file` - Path to write webserver tile request logs
- `log-format` - The format that the logger will log with. Available fields:
- `{{.Time}}` : The current Date Time in RFC 2822 format.
- `{{.RequestIP}}` : The IP address of the the requester.
Expand All @@ -143,7 +171,7 @@ Tegola currently supports the following command flags:
## Debugging

### Environment Variables
The following environment variables can be used for debugging the tegola server:
The following environment variables can be used for debugging:

`SQL_DEBUG` specify the type of SQL debug information to output. Currently support two values:

Expand All @@ -153,7 +181,7 @@ The following environment variables can be used for debugging the tegola server:
#### Usage

```bash
$ SQL_DEBUG=LAYER_SQL tegola --config=/path/to/conf.toml
$ SQL_DEBUG=LAYER_SQL tegola -config=/path/to/conf.toml
```

### Client side
Expand All @@ -171,19 +199,14 @@ The requested tile will be encode a layer with the `name` value set to `debug` a

## Building from source

Tegola is written in [Go](https://golang.org/) and requires Go 1.7+ to compile from source. To build tegola from source, make sure you have Go installed and have cloned the repository to your `$GOPATH` or `$GOROOT`. Navigate to the repository then run the following commands:
Tegola is written in [Go](https://golang.org/) and requires Go 1.8+ to compile from source. To build tegola from source, make sure you have Go installed and have cloned the repository to your `$GOPATH`. Navigate to the repository then run the following commands:

```bash
cd cmd/tegola/
go build -o tegola *.go
go build -o tegola
```

You will now have a binary named `tegola` in the current directory which is [ready for running](#running-tegola).


## Specifications
- [Well Known Binary (WKB)](http://edndoc.esri.com/arcsde/9.1/general_topics/wkb_representation.htm)
- [Mapbox Vector Tile (MVT) 2.1](https://github.com/mapbox/vector-tile-spec/tree/master/2.1)

## License
See [license](LICENSE.md) file in repo.
83 changes: 83 additions & 0 deletions basic/clone.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package basic

import "github.com/terranodo/tegola"

// ClonePoint will return a basic.Point for given tegola.Point.
func ClonePoint(pt tegola.Point) Point {
return Point{pt.X(), pt.Y()}
}

// ClonePoint will return a basic.Point3 for given tegola.Point3.
func ClonePoint3(pt tegola.Point3) Point3 {
return Point3{pt.X(), pt.Y(), pt.Z()}
}

// CloneMultiPoint will return a basic.MultiPoint for the given tegol.MultiPoint
func CloneMultiPoint(mpt tegola.MultiPoint) MultiPoint {
var bmpt MultiPoint
for _, pt := range mpt.Points() {
bmpt = append(bmpt, ClonePoint(pt))
}
return bmpt
}

/*
// CloneMultiPoint3 will return a basic.MultiPoint3 for the given tegol.MultiPoint3
func CloneMultiPoint3(mpt tegola.MultiPoint3) MultiPoint3 {
var bmpt MultiPoint3
for _, pt := range mpt.Points() {
bmpt = append(bmpt, ClonePoint3(pt))
}
return bmpt
}
*/

// CloneLine will return a basic.Line for a given tegola.LineString
func CloneLine(line tegola.LineString) (l Line) {
for _, pt := range line.Subpoints() {
l = append(l, Point{pt.X(), pt.Y()})
}
return l
}

// CloneMultiLine will return a basic.MultiLine for a given togola.MultiLine
func CloneMultiLine(mline tegola.MultiLine) (ml MultiLine) {
for _, ln := range mline.Lines() {
ml = append(ml, CloneLine(ln))
}
return ml
}

// ClonePolygon will return a basic.Polygon for a given tegola.Polygon
func ClonePolygon(polygon tegola.Polygon) (ply Polygon) {
for _, ln := range polygon.Sublines() {
ply = append(ply, CloneLine(ln))
}
return ply
}

// CloneMultiPolygon will return a basic.MultiPolygon for a given tegola.MultiPolygon.
func CloneMultiPolygon(mpolygon tegola.MultiPolygon) (mply MultiPolygon) {
for _, ply := range mpolygon.Polygons() {
mply = append(mply, ClonePolygon(ply))
}
return mply
}

func Clone(geo tegola.Geometry) Geometry {
switch g := geo.(type) {
case tegola.Point:
return ClonePoint(g)
case tegola.MultiPoint:
return CloneMultiPoint(g)
case tegola.LineString:
return CloneLine(g)
case tegola.MultiLine:
return CloneMultiLine(g)
case tegola.Polygon:
return ClonePolygon(g)
case tegola.MultiPolygon:
return CloneMultiPolygon(g)
}
return nil
}
Loading

0 comments on commit 53fdf40

Please sign in to comment.