Skip to content

Commit

Permalink
Merge branch 'v0.5.0' into issue-199
Browse files Browse the repository at this point in the history
  • Loading branch information
ARolek committed Dec 6, 2017
2 parents 91c79d1 + 9e36574 commit 0fdc75e
Show file tree
Hide file tree
Showing 11 changed files with 159 additions and 64 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 0.5.0 (2017-12-XX)
- Added: Command line `cache seed` and `cache purge` commands
- Added: More robust command line interface
- Fixed: Possible Panic if a feature without an ID is added before a feature with an ID; when constructing Layers (#195)

Breaking changes:
- To use tegola as a web server, use the command `tegola serve --config=/path/to/config.toml`

## 0.4.2 (2017-11-28)
- Fixed: Performance affected by unused log statements (#197, @remster)

Expand Down Expand Up @@ -70,4 +78,4 @@
- Added: concurrent layer fetching from data providers.
- Added: remote config loading over http(s).

## v0.1.0 (2016-07-29)
## v0.1.0 (2016-07-29)
68 changes: 37 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,41 @@ Tegola is a vector tile server delivering [Mapbox Vector Tiles](https://github.c

## 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 .
- [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.
- Cache seeding to fill the cache prior to web requests.
- Parallelized tile serving and geometry processing.
- Support for Web Mercator (3857) and WGS84 (4326) projections.

## Running Tegola
## Usage
```
tegola is a vector tile server
Version: v0.5.0
Usage:
tegola [command]
Available Commands:
cache Manipulate the tile cache
help Help about any command
serve Use tegola as a tile server
version Print the version number of tegola
Flags:
--config string path to config file (default "config.toml")
-h, --help help for tegola
Use "tegola [command] --help" for more information about a command.
```

## Running tegola as a vector tile server
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 sever --config=/path/to/config.toml
```

## Server Endpoints
Expand Down Expand Up @@ -74,14 +96,12 @@ Return [TileJSON](https://github.com/mapbox/tilejson-spec) details about the map

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 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 to bind the web server to. defaults ":8080"

Expand Down Expand Up @@ -116,9 +136,9 @@ max_connections = "50" # The max connections to maintain in the connection
fields = [ "class", "name" ] # Additional fields to include in the select statement.

[[providers.layers]]
name = "rivers" # will be encoded as the layer name in the tile
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
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 = """
Expand All @@ -140,7 +160,7 @@ name = "zoning" # used in the URL to reference this
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]]
Expand All @@ -155,43 +175,29 @@ The following tokens are supported in custom SQL queries for the PostGIS data pr
- `!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 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 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.
- `{{.Z}}` : The Zoom level.
- `{{.X}}` : The X Coordinate.
- `{{.Y}}` : The Y Coordinate.

## Debugging

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

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

- `LAYER_SQL`: print layer SQL as they are parsed from the config file.
- `EXECUTE_SQL`: print SQL that is executed for each tile request and the number of items it returns or an error.

#### Usage

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

The following environment variables can be use to control various runtime options:

`TEGOLA_OPTIONS` specify a set of options comma (or space) seperated options.

- `DontSimplifyGeo` to turn off simplification for all layers.
- `SimplifyMaxZoom={{int}}` to set the max zoom that simplification will apply to. (14 is default)


#### Usage

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

### Client side
## Client side debugging
When debugging client side, it's often helpful to to see an outline of a tile along with it's Z/X/Y values. To encode a debug layer into every tile add the query string variable `debug=true` to the URL template being used to request tiles. For example:

```
Expand Down
14 changes: 0 additions & 14 deletions debug/log/log.go

This file was deleted.

8 changes: 0 additions & 8 deletions debug/log/noop.go

This file was deleted.

File renamed without changes.
6 changes: 3 additions & 3 deletions mvt/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,10 @@ func (c *cursor) ScalePoint(p tegola.Point) (nx, ny int64) {
}

func (c *cursor) MinMax() (min, max maths.Pt) {
return maths.Pt{0 - tilebuffer, 0 - tilebuffer},
return maths.Pt{X: 0 - tilebuffer, Y: 0 - tilebuffer},
maths.Pt{
float64(c.extent + tilebuffer),
float64(c.extent + tilebuffer),
X: float64(c.extent + tilebuffer),
Y: float64(c.extent + tilebuffer),
}
}

Expand Down
2 changes: 1 addition & 1 deletion mvt/feature_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestEncodeGeometry(t *testing.T) {
}
*/
testcases := []struct {
desc string `"test":"desc"`
desc string `tbltest:"desc"`
geo basic.Geometry
typ vectorTile.Tile_GeomType
bbox tegola.BoundingBox
Expand Down
6 changes: 2 additions & 4 deletions mvt/layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ func (l *Layer) VTileLayer(ctx context.Context, extent tegola.BoundingBox) (*vec
}

//Version is the version of tile spec this layer is from.
func (*Layer) Version() int {
return 2
}
func (*Layer) Version() int { return 2 }

// Extent defaults to 4096
func (l *Layer) Extent() int {
Expand Down Expand Up @@ -156,7 +154,7 @@ FEATURES_LOOP:
continue
}
for _, cf := range l.features {
if cf.ID != nil {
if cf.ID == nil {
continue
}
// We matched, we skip
Expand Down
105 changes: 105 additions & 0 deletions mvt/layer_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package mvt

import (
"reflect"
"testing"

"context"

"github.com/gdey/tbltest"
"github.com/terranodo/tegola"
"github.com/terranodo/tegola/basic"
"github.com/terranodo/tegola/mvt/vector_tile"
Expand All @@ -23,6 +25,109 @@ func newTileLayer(name string, keys []string, values []*vectorTile.Tile_Value, f
}
}

func TestLayerAddFeatures(t *testing.T) {
type tc struct {
features []Feature
expected []Feature // Nil means that it's the same as the features.
skipped bool
}
fn := func(idx int, tcase tc) {
defer func() {
if r := recover(); r != nil {
t.Errorf("[%v] did not expect AddFeatures to panic: recovered: %v", idx, r)
}
}()
// First create a blank layer to add the features to.
l := new(Layer)
skipped := l.AddFeatures(tcase.features...)
if tcase.skipped != skipped {
t.Errorf("[%v] skipped value; expected: %v got: %v", idx, tcase.skipped, skipped)
}
gotFeatures := l.Features()
expectedFeatures := tcase.expected
if expectedFeatures == nil {
expectedFeatures = tcase.features
}
if len(gotFeatures) != len(expectedFeatures) {
t.Errorf("[%v] number of features incorrect. expected: %v got: %v", idx, len(expectedFeatures), len(gotFeatures))
}
for i := range expectedFeatures {
if !reflect.DeepEqual(expectedFeatures[i], gotFeatures[i]) {
t.Errorf("[%v] expected feature %v to match. expected: %v got: %v", idx, i, expectedFeatures[i], gotFeatures[i])
}
}
}
newID := func(id uint64) *uint64 { return &id }
tbltest.Cases(
// nil id test 1
tc{
features: []Feature{
{
Tags: map[string]interface{}{"btag": "tag"},
Geometry: basic.Point{12.0, 15.0},
},
{
ID: newID(1),
Tags: map[string]interface{}{"atag": "tag"},
Geometry: basic.Point{12.0, 15.0},
},
},
},
// nil id test 2
tc{
features: []Feature{
{
ID: newID(1),
Tags: map[string]interface{}{"atag": "tag"},
Geometry: basic.Point{12.0, 15.0},
},
{
Tags: map[string]interface{}{"btag": "tag"},
Geometry: basic.Point{12.0, 15.0},
},
},
},
// same feature test
tc{
features: []Feature{
{
ID: newID(1),
Tags: map[string]interface{}{"atag": "tag"},
Geometry: basic.Point{12.0, 15.0},
},
{
ID: newID(1),
Tags: map[string]interface{}{"atag": "tag"},
Geometry: basic.Point{12.0, 15.0},
},
},
expected: []Feature{
{
ID: newID(1),
Tags: map[string]interface{}{"atag": "tag"},
Geometry: basic.Point{12.0, 15.0},
},
},
skipped: true,
},
// different feature test
tc{
features: []Feature{
{
ID: newID(1),
Tags: map[string]interface{}{"atag": "tag"},
Geometry: basic.Point{12.0, 15.0},
},
{
ID: newID(2),
Tags: map[string]interface{}{"atag": "tag"},
Geometry: basic.Point{12.0, 15.0},
},
},
},
).Run(fn)
}

func TestLayer(t *testing.T) {
baseBBox := tegola.BoundingBox{
Minx: 0,
Expand Down
2 changes: 1 addition & 1 deletion server/handle_map_capabilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/dimfeld/httptreemux"
"github.com/terranodo/tegola"
"github.com/terranodo/tegola/atlas"
"github.com/terranodo/tegola/tilejson"
"github.com/terranodo/tegola/mapbox/tilejson"
)

type HandleMapCapabilities struct {
Expand Down
2 changes: 1 addition & 1 deletion server/handle_map_capabilities_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"github.com/dimfeld/httptreemux"

"github.com/terranodo/tegola/atlas"
"github.com/terranodo/tegola/mapbox/tilejson"
"github.com/terranodo/tegola/server"
"github.com/terranodo/tegola/tilejson"
)

func TestHandleMapCapabilities(t *testing.T) {
Expand Down

0 comments on commit 0fdc75e

Please sign in to comment.