Skip to content

Commit 91c8ea1

Browse files
committed
Updating READMEs around ST_AsMVT
1 parent 3af024b commit 91c8ea1

File tree

2 files changed

+100
-113
lines changed

2 files changed

+100
-113
lines changed

README.md

Lines changed: 91 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -101,19 +101,22 @@ Return [TileJSON](https://github.com/mapbox/tilejson-spec) details about the map
101101
Return an auto generated [Mapbox GL Style](https://www.mapbox.com/mapbox-gl-js/style-spec/) for the configured map.
102102

103103
## Configuration
104+
104105
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.
105106

106107
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.
107108

109+
### Example config file:
110+
108111
```toml
109112
[webserver]
110113
port = ":9090" # port to bind the web server to. defaults ":8080"
111114
ssl_cert = "fullchain.pem" # ssl cert for serving by https
112115
ssl_key = "privkey.pem" # ssl key for serving by https
113116

114-
[webserver.headers]
115-
Access-Control-Allow-Origin = "*"
116-
Cache-Control = "no-cache, no-store, must-revalidate"
117+
[webserver.headers]
118+
Access-Control-Allow-Origin = "*"
119+
Cache-Control = "no-cache, no-store, must-revalidate"
117120

118121
[cache] # configure a tile cache
119122
type = "file" # a file cache will cache to the local file system
@@ -130,97 +133,98 @@ user = "tegola" # postgis database user (required)
130133
password = "" # postgis database password (required)
131134
srid = 3857 # The default srid for this provider. Defaults to WebMercator (3857) (optional)
132135
max_connections = 50 # The max connections to maintain in the connection pool. Default is 100. (optional)
133-
ssl_mode = "prefer" # PostgreSQL SSL mode*. Default is "disable". (optional)
134-
135-
[[providers.layers]]
136-
name = "landuse" # will be encoded as the layer name in the tile
137-
tablename = "gis.zoning_base_3857" # sql or tablename are required
138-
geometry_fieldname = "geom" # geom field. default is geom
139-
id_fieldname = "gid" # geom id field. default is gid
140-
srid = 4326 # the srid of table's geo data. Defaults to WebMercator (3857)
141-
142-
[[providers.layers]]
143-
name = "roads" # will be encoded as the layer name in the tile
144-
tablename = "gis.zoning_base_3857" # sql or tablename are required
145-
geometry_fieldname = "geom" # geom field. default is geom
146-
geometry_type = "linestring" # geometry type. if not set, tables are inspected at startup to try and infer the gemetry type
147-
id_fieldname = "gid" # geom id field. default is gid
148-
fields = [ "class", "name" ] # Additional fields to include in the select statement.
149-
150-
[[providers.layers]]
151-
name = "rivers" # will be encoded as the layer name in the tile
152-
geometry_fieldname = "geom" # geom field. default is geom
153-
id_fieldname = "gid" # geom id field. default is gid
154-
# Custom sql to be used for this layer. Note: that the geometery field is wraped
155-
# in a ST_AsBinary() and the use of the !BBOX! token
156-
sql = "SELECT gid, ST_AsBinary(geom) AS geom FROM gis.rivers WHERE geom && !BBOX!"
157-
158-
[[providers.layers]]
159-
name = "buildings" # will be encoded as the layer name in the tile
160-
geometry_fieldname = "geom" # geom field. default is geom
161-
id_fieldname = "gid" # geom id field. default is gid
162-
# Custom sql to be used for this layer as a sub query. ST_AsBinary and
163-
# !BBOX! filter are applied automatically.
164-
sql = "(SELECT gid, geom, type FROM buildings WHERE scalerank = !ZOOM! LIMIT 1000) AS sub"
165-
166-
# register mvt data providers
167-
# note mvt data providers can not be conflated with any other providers of any type in a map.
168-
# thus a map may only contain a single mvt_provider.
169-
[[mvt_providers]]
170-
name = "test_postgis" # provider name is referenced from map layers (required)
171-
type = "postgis" # the type of data provider must be "postgis" for this data provider (required)
172-
host = "localhost" # PostGIS database host (required)
173-
port = 5432 # PostGIS database port (required)
174-
database = "tegola" # PostGIS database name (required)
175-
user = "tegola" # PostGIS database user (required)
176-
password = "" # PostGIS database password (required
177-
178-
[[mvt_providers.layers]]
179-
name = "landuse"
180-
# MVT data provider must use SQL statements
181-
# this table uses "geom" for the geometry_fieldname and "gid" for the id_fieldname so they don't need to be configured
182-
sql = "SELECT ST_AsMVTGeom(geom,!BBOX!) AS geom, gid FROM gis.landuse WHERE geom && !BBOX!"
136+
ssl_mode = "prefer" # PostgreSQL SSL mode*. Default is "disable". (optional)
137+
138+
[[providers.layers]]
139+
name = "landuse" # will be encoded as the layer name in the tile
140+
tablename = "gis.zoning_base_3857" # sql or tablename are required
141+
geometry_fieldname = "geom" # geom field. default is geom
142+
id_fieldname = "gid" # geom id field. default is gid
143+
srid = 4326 # the srid of table's geo data. Defaults to WebMercator (3857)
144+
145+
[[providers.layers]]
146+
name = "roads" # will be encoded as the layer name in the tile
147+
tablename = "gis.zoning_base_3857" # sql or tablename are required
148+
geometry_fieldname = "geom" # geom field. default is geom
149+
geometry_type = "linestring" # geometry type. if not set, tables are inspected at startup to try and infer the gemetry type
150+
id_fieldname = "gid" # geom id field. default is gid
151+
fields = [ "class", "name" ] # Additional fields to include in the select statement.
152+
153+
[[providers.layers]]
154+
name = "rivers" # will be encoded as the layer name in the tile
155+
geometry_fieldname = "geom" # geom field. default is geom
156+
id_fieldname = "gid" # geom id field. default is gid
157+
# Custom sql to be used for this layer. Note: that the geometery field is wraped
158+
# in a ST_AsBinary() and the use of the !BBOX! token
159+
sql = "SELECT gid, ST_AsBinary(geom) AS geom FROM gis.rivers WHERE geom && !BBOX!"
160+
161+
[[providers.layers]]
162+
name = "buildings" # will be encoded as the layer name in the tile
163+
geometry_fieldname = "geom" # geom field. default is geom
164+
id_fieldname = "gid" # geom id field. default is gid
165+
# Custom sql to be used for this layer as a sub query. ST_AsBinary and
166+
# !BBOX! filter are applied automatically.
167+
sql = "(SELECT gid, geom, type FROM buildings WHERE scalerank = !ZOOM! LIMIT 1000) AS sub"
183168

184169
# maps are made up of layers
185170
[[maps]]
186-
name = "zoning" # used in the URL to reference this map (/maps/:map_name)
171+
name = "zoning" # used in the URL to reference this map (/maps/zoning)
187172

188-
[[maps.layers]]
189-
name = "landuse" # name is optional. If it's not defined the name of the ProviderLayer will be used.
173+
[[maps.layers]]
174+
name = "landuse" # name is optional. If it's not defined the name of the ProviderLayer will be used.
190175
# It can also be used to group multiple ProviderLayers under the same namespace.
191-
provider_layer = "test_postgis.landuse" # must match a data provider layer
192-
min_zoom = 12 # minimum zoom level to include this layer
193-
max_zoom = 16 # maximum zoom level to include this layer
194-
195-
[maps.layers.default_tags] # table of default tags to encode in the tile. SQL statements will override
196-
class = "park"
176+
provider_layer = "test_postgis.landuse" # must match a data provider layer
177+
min_zoom = 12 # minimum zoom level to include this layer
178+
max_zoom = 16 # maximum zoom level to include this layer
179+
180+
[maps.layers.default_tags] # table of default tags to encode in the tile. SQL statements will override
181+
class = "park"
182+
183+
[[maps.layers]]
184+
name = "rivers" # name is optional. If it's not defined the name of the ProviderLayer will be used.
185+
# It can also be used to group multiple ProviderLayers under the same namespace.
186+
provider_layer = "test_postgis.rivers" # must match a data provider layer
187+
dont_simplify = true # optionally, turn off simplification for this layer. Default is false.
188+
dont_clip = true # optionally, turn off clipping for this layer. Default is false.
189+
min_zoom = 10 # minimum zoom level to include this layer
190+
max_zoom = 18 # maximum zoom level to include this layer
191+
```
197192

198-
[[maps.layers]]
199-
name = "rivers" # name is optional. If it's not defined the name of the ProviderLayer will be used.
200-
# It can also be used to group multiple ProviderLayers under the same namespace.
201-
provider_layer = "test_postgis.rivers" # must match a data provider layer
202-
dont_simplify = true # optionally, turn off simplification for this layer. Default is false.
203-
dont_clip = true # optionally, turn off clipping for this layer. Default is false.
204-
min_zoom = 10 # minimum zoom level to include this layer
205-
max_zoom = 18 # maximum zoom level to include this layer
193+
\* more on PostgreSQL SSL mode [here](https://www.postgresql.org/docs/9.2/static/libpq-ssl.html). The `postgis` config also supports "ssl_cert" and "ssl_key" options are required, corresponding semantically with "PGSSLKEY" and "PGSSLCERT". These options do not check for environment variables automatically. See the section [below](#environment-variables) on injecting environment variables into the config.
206194

195+
### Example config using Postres 12 / PostGIS 3.0 ST_AsMVT():
207196

208-
# note that this map is only using mvt_test_postgis provider.
209-
# it can not conflate any other providers
210-
[[maps]]
211-
name = "landuse_mvt"
197+
```toml
198+
# register a MVT data provider. MVT data providers have the prefix "mvt_" in their type
199+
# note mvt data providers can not be conflated with any other providers of any type in a map
200+
# thus a map may only contain a single mvt provider.
201+
[[providers]]
202+
name = "my_postgis" # provider name is referenced from map layers (required).
203+
type = "mvt_postgis" # the type of data provider must be "mvt_postgis" for this data provider (required)
204+
host = "localhost" # PostGIS database host (required)
205+
port = 5432 # PostGIS database port (required)
206+
database = "tegola" # PostGIS database name (required)
207+
user = "tegola" # PostGIS database user (required)
208+
password = "" # PostGIS database password (required
212209

213-
[[maps.layers]]
214-
name = "landuse"
215-
provider_layer = "mvt_test_postgis.landuse" # note the mvt data provider name is prefixed with `mvt_`
216-
min_zoom = 12 # minimum zoom level to include this layer
217-
max_zoom = 16 # maximum zoom level to include this layer
210+
[[providers.layers]]
211+
name = "landuse"
212+
# MVT data provider must use SQL statements
213+
# this table uses "geom" for the geometry_fieldname and "gid" for the id_fieldname so they don't need to be configured
214+
# Wrapping the geom with ST_AsMVTGeom is required.
215+
sql = "SELECT ST_AsMVTGeom(geom,!BBOX!) AS geom, gid FROM gis.landuse WHERE geom && !BBOX!"
218216

217+
# maps are made up of layers
218+
[[maps]]
219+
name = "zoning" # used in the URL to reference this map (/maps/zoning)
219220

221+
[[maps.layers]]
222+
name = "landuse" # name is optional. If it's not defined the name of the ProviderLayer will be used.
223+
provider_layer = "my_postgis.landuse" # must match a data provider layer
224+
min_zoom = 10 # minimum zoom level to include this layer
225+
max_zoom = 16 # maximum zoom level to include this layer
220226
```
221227

222-
\* more on PostgreSQL SSL mode [here](https://www.postgresql.org/docs/9.2/static/libpq-ssl.html). The `postgis` config also supports "ssl_cert" and "ssl_key" options are required, corresponding semantically with "PGSSLKEY" and "PGSSLCERT". These options do not check for environment variables automatically. See the section [below](#environment-variables) on injecting environment variables into the config.
223-
224228
## Environment Variables
225229

226230
#### Config TOML
@@ -241,7 +245,8 @@ srid = 3857
241245
max_connections = "${POSTGIS_MAX_CONN}"
242246
```
243247

244-
#### SQL Debugging
248+
## SQL Debugging
249+
245250
The following environment variables can be used for debugging:
246251

247252
`TEGOLA_SQL_DEBUG` specify the type of SQL debug information to output. Currently support two values:
@@ -262,7 +267,6 @@ The following environment variables can be used to control various runtime optio
262267
- `DontSimplifyGeo` to turn off simplification for all layers.
263268
- `SimplifyMaxZoom={{int}}` to set the max zoom that simplification will apply to. (14 is default)
264269

265-
266270
## Client side debugging
267271

268272
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:
@@ -279,12 +283,10 @@ The requested tile will be encode a layer with the `name` value set to `debug` a
279283

280284
## Building from source
281285

282-
Tegola is written in [Go](https://golang.org/) and requires Go 1.x to compile from source. (We support the three newest versions of Go.) 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:
283-
286+
Tegola is written in [Go](https://golang.org/) and requires Go 1.14 to compile from source. (We support the two newest versions of Go.) To build tegola from source, make sure you have Go installed and have cloned the repository. Navigate to the repository then run the following command:
284287

285288
```bash
286-
cd cmd/tegola/
287-
go build
289+
cd cmd/tegola/ && go build -mod vendor
288290
```
289291

290292
You will now have a binary named `tegola` in the current directory which is [ready for running](#running-tegola).
@@ -307,7 +309,9 @@ go build -tags 'noRedisCache noGpkgProvider noViewer'
307309
```
308310

309311
## License
312+
310313
See [license](LICENSE.md) file in repo.
311314

312315
## Looking for a vector tile style editor?
316+
313317
Once you have tegola running you're likely going to want to work on your map's cartography. Give [fresco](https://github.com/go-spatial/fresco) a try!

mvtprovider/postgis/README.md

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ password = "" # PostGIS database password (required)
1818

1919
### Connection Properties
2020

21-
- `name` (string): [Required] provider name is referenced from map layers. please note that when referencing an mvt_provider form a map layer the provider name must be prexied with `mvt_`. See example config below.
21+
- `name` (string): [Required] provider name is referenced from map layers.
2222
- `type` (string): [Required] the type of data provider. must be "postgis" to use this data provider
2323
- `host` (string): [Required] PostGIS database host
2424
- `port` (int): [Required] PostGIS database port (required)
@@ -35,7 +35,9 @@ In addition to the connection configuration above, Provider Layers need to be co
3535
```toml
3636
[[providers.layers]]
3737
name = "landuse"
38+
# MVT data provider must use SQL statements
3839
# this table uses "geom" for the geometry_fieldname and "gid" for the id_fieldname so they don't need to be configured
40+
# Wrapping the geom with ST_AsMVTGeom is required.
3941
sql = "SELECT ST_AsMVTGeom(geom,!BBOX!) AS geom, gid FROM gis.landuse WHERE geom && !BBOX!"
4042
```
4143

@@ -59,11 +61,7 @@ sql = "SELECT ST_AsMVTGeom(geom,!BBOX!) AS geom, gid FROM gis.landuse WHERE geom
5961
- `!GEOM_FIELD!` - [Optional] the geom field name
6062
- `!GEOM_TYPE!` - [Optional] the geom type if defined otherwise ""
6163

62-
## Example mvt_provider and map config
63-
64-
**Important**: When referencing the `provider` in the `map` section of the config, you MUST prepend `mvt_` to the `provider_layer` value. This indicates to tegola that the provider is an MVT provider so tegola knows which provider section to perform the lookup.
65-
66-
Example:
64+
## Example mvt_postgis and map config
6765

6866
```toml
6967
[[providers]]
@@ -83,26 +81,11 @@ password = ""
8381
name = "cities"
8482
center = [-90.2,38.6,3.0] # where to center of the map (lon, lat, zoom)
8583

86-
[[maps.layers]]
87-
name = "landuse"
88-
provider_layer = "test_postgis.landuse"
89-
min_zoom = 0
90-
max_zoom = 14
91-
```
92-
93-
## Environment Variable support
94-
95-
Helpful debugging environment variables:
96-
97-
- `TEGOLA_SQL_DEBUG`: specify the type of SQL debug information to output. Supports the following values:
98-
- `LAYER_SQL`: print layer SQL as they’re parsed from the config file.
99-
- `EXECUTE_SQL`: print SQL that is executed for each tile request and the number of items it returns or an error.
100-
- `LAYER_SQL:EXECUTE_SQL`: print `LAYER_SQL` and `EXECUTE_SQL`.
101-
102-
Example:
103-
104-
```
105-
$ TEGOLA_SQL_DEBUG=LAYER_SQL tegola serve --config=/path/to/conf.toml
84+
[[maps.layers]]
85+
name = "landuse"
86+
provider_layer = "test_postgis.landuse"
87+
min_zoom = 0
88+
max_zoom = 14
10689
```
10790

10891
## Testing

0 commit comments

Comments
 (0)