GeoServer User Manual
Release 2.15.1
GeoServer
April 29, 2019
Contents
1
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
3
3
3
4
6
Installation
2.1 Windows installer . . . . . .
2.2 Windows binary . . . . . . .
2.3 Mac OS X installer . . . . . .
2.4 Mac OS X binary . . . . . . .
2.5 Linux binary . . . . . . . . .
2.6 Web archive . . . . . . . . . .
2.7 Upgrading existing versions
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
9
9
15
17
19
21
22
23
3
Getting started
3.1 Using the web administration interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.2 Publishing a shapefile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3.3 Publishing a PostGIS table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
25
25
28
33
4
Web administration interface
4.1 About & Status . . . . .
4.2 Data . . . . . . . . . . .
4.3 Services . . . . . . . . .
4.4 Settings . . . . . . . . .
4.5 Tile Caching . . . . . . .
4.6 Security . . . . . . . . .
4.7 Demos . . . . . . . . . .
4.8 Tools . . . . . . . . . . .
4.9 Extensions . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
41
41
42
42
42
43
43
43
43
44
Data management
5.1 Data settings . . . . .
5.2 Vector data . . . . . .
5.3 Raster data . . . . . .
5.4 Databases . . . . . . .
5.5 Cascaded service data
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
45
. 45
. 77
. 86
. 133
. 176
2
5
Introduction
1.1 Overview . . . .
1.2 History . . . . . .
1.3 Getting involved
1.4 License . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
i
5.6
6
Application schemas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 185
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
261
261
268
453
460
560
701
809
Services
7.1 Web Map Service (WMS) . . . . . .
7.2 Web Feature Service (WFS) . . . . .
7.3 Web Coverage Service (WCS) . . . .
7.4 Web Processing Service (WPS) . . .
7.5 Catalog Services for the Web (CSW)
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
1063
1063
1156
1178
1186
1216
Filtering
8.1 Supported filter languages
8.2 Filter Encoding Reference .
8.3 ECQL Reference . . . . . .
8.4 Filter functions . . . . . . .
8.5 Filter Function Reference .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
1227
1227
1228
1233
1238
1240
Server configuration
9.1 Status . . . . . . . . . . . . . . . . . . .
9.2 Contact Information . . . . . . . . . . .
9.3 Global Settings . . . . . . . . . . . . . .
9.4 Image Processing . . . . . . . . . . . . .
9.5 Raster Access . . . . . . . . . . . . . . .
9.6 REST Configuration . . . . . . . . . . .
9.7 Advanced log configuration . . . . . .
9.8 Coordinate Reference System Handling
9.9 Virtual Services . . . . . . . . . . . . . .
9.10 Demos . . . . . . . . . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
1249
1249
1252
1254
1259
1261
1263
1263
1265
1275
1277
10 GeoServer data directory
10.1 Data directory default location . . . . . . . .
10.2 Setting the data directory location . . . . . .
10.3 Structure of the data directory . . . . . . . .
10.4 Migrating a data directory between versions
10.5 Parameterize catalog settings . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
1285
1285
1286
1289
1292
1293
11 Running in a production environment
11.1 Java Considerations . . . . . . . . . . . . . . .
11.2 Container Considerations . . . . . . . . . . . .
11.3 Configuration Considerations . . . . . . . . .
11.4 Data Considerations . . . . . . . . . . . . . . .
11.5 Linux init scripts . . . . . . . . . . . . . . . . .
11.6 Other Considerations . . . . . . . . . . . . . .
11.7 Troubleshooting . . . . . . . . . . . . . . . . .
11.8 Make cluster nodes identifiable from the GUI
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
1295
1295
1299
1301
1304
1306
1306
1307
1313
7
8
9
Styling
6.1 Styles . . . . . . . . . . . . . . . . .
6.2 SLD Styling . . . . . . . . . . . . .
6.3 Generating SLD styles with QGIS
6.4 CSS Styling . . . . . . . . . . . . .
6.5 YSLD Styling . . . . . . . . . . . .
6.6 MBStyle Styling . . . . . . . . . . .
6.7 Styling Workshop . . . . . . . . .
12 REST
ii
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
1315
12.1 API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1315
12.2 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1317
13 Security
13.1 Security settings .
13.2 Role system . . . .
13.3 Authentication . .
13.4 Passwords . . . . .
13.5 Root account . . .
13.6 Service Security . .
13.7 Layer security . . .
13.8 REST Security . . .
13.9 Disabling security
13.10 Tutorials . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
1385
1385
1416
1429
1439
1442
1442
1445
1451
1453
1453
14 GeoWebCache
14.1 GeoWebCache settings . .
14.2 Using GeoWebCache . . .
14.3 Configuration . . . . . . .
14.4 Seeding and refreshing .
14.5 HTTP Response Headers
14.6 GeoWebCache REST API
14.7 Troubleshooting . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
1493
1493
1511
1514
1519
1520
1523
1534
15 Extensions
15.1 Control flow module . . . . . . . . . . . . . . . . . . . . .
15.2 DXF OutputFormat for WFS and WPS PPIO . . . . . . .
15.3 Excel WFS Output Format . . . . . . . . . . . . . . . . . .
15.4 GRIB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
15.5 Imagemap . . . . . . . . . . . . . . . . . . . . . . . . . . .
15.6 Importer . . . . . . . . . . . . . . . . . . . . . . . . . . . .
15.7 INSPIRE . . . . . . . . . . . . . . . . . . . . . . . . . . . .
15.8 JP2K Plugin . . . . . . . . . . . . . . . . . . . . . . . . . .
15.9 libjpeg-turbo Map Encoder Extension . . . . . . . . . . .
15.10 Monitoring . . . . . . . . . . . . . . . . . . . . . . . . . .
15.11 NetCDF . . . . . . . . . . . . . . . . . . . . . . . . . . . .
15.12 NetCDF Output Format . . . . . . . . . . . . . . . . . . .
15.13 OGR based WFS Output Format . . . . . . . . . . . . . .
15.14 OGR based WPS Output Format . . . . . . . . . . . . . .
15.15 GeoServer Printing Module . . . . . . . . . . . . . . . . .
15.16 Cross-layer filtering . . . . . . . . . . . . . . . . . . . . .
15.17 Vector Tiles . . . . . . . . . . . . . . . . . . . . . . . . . .
15.18 XSLT WFS output format module . . . . . . . . . . . . .
15.19 Web Coverage Service 2.0 Earth Observation extensions
15.20 MongoDB Data Store . . . . . . . . . . . . . . . . . . . .
15.21 SLD REST Service . . . . . . . . . . . . . . . . . . . . . .
15.22 Geofence Plugin . . . . . . . . . . . . . . . . . . . . . . .
15.23 Geofence Internal Server . . . . . . . . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
1539
1539
1543
1546
1547
1548
1549
1587
1592
1593
1595
1608
1616
1619
1622
1623
1649
1654
1660
1664
1674
1675
1685
1691
16 Community modules
16.1 Key authentication module . . . . . . . . . . . .
16.2 Authentication with OAuth2 . . . . . . . . . . .
16.3 Authentication with Keycloak . . . . . . . . . .
16.4 DDS/BIL(World Wind Data Formats) Extension
16.5 Scripting . . . . . . . . . . . . . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
1705
1705
1714
1733
1737
1741
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
iii
16.6
16.7
16.8
16.9
16.10
16.11
16.12
16.13
16.14
16.15
16.16
16.17
16.18
16.19
16.20
16.21
16.22
16.23
16.24
16.25
16.26
16.27
16.28
16.29
16.30
16.31
16.32
16.33
16.34
16.35
SpatiaLite . . . . . . . . . . . . . . . . . . . . . . . . . . .
Dynamic colormap generation . . . . . . . . . . . . . . .
JDBCConfig . . . . . . . . . . . . . . . . . . . . . . . . . .
MBTiles Extension . . . . . . . . . . . . . . . . . . . . . .
GeoPackage Extension . . . . . . . . . . . . . . . . . . . .
PGRaster . . . . . . . . . . . . . . . . . . . . . . . . . . .
WPS download community module . . . . . . . . . . . .
JMS based Clustering . . . . . . . . . . . . . . . . . . . .
SOLR data store . . . . . . . . . . . . . . . . . . . . . . .
GeoMesa data store . . . . . . . . . . . . . . . . . . . . .
GWC Distributed Caching community module . . . . .
GDAL based WCS Output Format . . . . . . . . . . . . .
GWC S3 BlobStore plugin . . . . . . . . . . . . . . . . . .
GWC SQLite Plugin . . . . . . . . . . . . . . . . . . . . .
Parameters Extractor . . . . . . . . . . . . . . . . . . . . .
WPS Remote community module . . . . . . . . . . . . .
JDBCStore . . . . . . . . . . . . . . . . . . . . . . . . . . .
ncWMS WMS extensions support . . . . . . . . . . . . .
Backup and Restore Documentation . . . . . . . . . . . .
OneLogin Authentication Filter . . . . . . . . . . . . . .
WMTS Multidimensional . . . . . . . . . . . . . . . . . .
Notification community module Plugin Documentation
OpenSearch for EO . . . . . . . . . . . . . . . . . . . . . .
S3 Support for GeoTiff . . . . . . . . . . . . . . . . . . . .
Status Monitoring . . . . . . . . . . . . . . . . . . . . . .
NSG Profile . . . . . . . . . . . . . . . . . . . . . . . . . .
GHRSST NetCDF output . . . . . . . . . . . . . . . . . .
Monitoring Hibernate storage . . . . . . . . . . . . . . .
Geoserver Task Manager . . . . . . . . . . . . . . . . . .
Quality of Service and Experience Module (QoSE) . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
1762
1764
1768
1770
1772
1775
1777
1792
1806
1813
1814
1814
1818
1821
1825
1829
1876
1879
1885
1903
1905
1917
1921
1933
1934
1938
1940
1943
1946
1969
17 Tutorials
17.1 Freemarker Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . .
17.2 GeoRSS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
17.3 GetFeatureInfo Templates . . . . . . . . . . . . . . . . . . . . . . . . . .
17.4 Paletted Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
17.5 Serving Static Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
17.6 WMS Reflector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
17.7 WMS Animator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
17.8 CQL and ECQL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
17.9 Using the ImageMosaic plugin for raster time-series data . . . . . . . .
17.10 Using the ImageMosaic plugin for raster with time and elevation data
17.11 Using the ImageMosaic plugin with footprint mangement . . . . . . .
17.12 Building and using an image pyramid . . . . . . . . . . . . . . . . . . .
17.13 Storing a coverage in a JDBC database . . . . . . . . . . . . . . . . . . .
17.14 Using the GeoTools feature-pregeneralized module . . . . . . . . . . .
17.15 Setting up a JNDI connection pool with Tomcat . . . . . . . . . . . . .
17.16 geoserver on JBoss . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
1975
1975
1977
1981
1986
1994
1994
1997
2001
2006
2018
2021
2030
2033
2040
2048
2053
Python Module Index
iv
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
2055
GeoServer User Manual, Release 2.15.1
GeoServer is an open source software server written in Java that allows users to share and edit geospatial data. Designed for interoperability, it publishes data from any major spatial data source using open
standards.
This User Manual is a comprehensive guide to all aspects of using GeoServer. Whether you are a novice or
a veteran user of this software, we hope that this documentation will be a helpful reference.
Introduction Learn about GeoServer.
Installation Install GeoServer for your platform.
Getting started Tutorials to help you get started with GeoServer.
Web administration interface Navigate the GeoServer graphical interface.
Data management Load and publish data from a variety of sources.
Styling Styling and visualization for published layers in GeoServer.
Services OGC services, the primary method of publishing data in GeoServer.
Filtering Filter your requests and responses to increase efficiency.
Server configuration Configuration options for GeoServer administrators.
GeoServer data directory Settings and configuration files for GeoServer.
Running in a production environment Best practices for using GeoServer.
REST Interact programmatically with GeoServer without using the graphical interface.
Security Secure and restrict access to data and services.
GeoWebCache Accelerate your GeoServer with tile caching.
Extensions Add extra functionality to GeoServer with extensions.
Community modules Add cutting-edge functionality to GeoServer with community modules.
Tutorials Other tips and tricks for getting the most out of your GeoServer instance.
Contents
1
GeoServer User Manual, Release 2.15.1
2
Contents
CHAPTER
1
Introduction
This section gives an overview of GeoServer the project, its background, and what it can do for you.
For those who wish to get started with GeoServer right away, feel free to skip to the Installation section.
1.1 Overview
GeoServer is an open source software server written in Java that allows users to share and edit geospatial data. Designed for interoperability, it publishes data from any major spatial data source using open
standards.
Being a community-driven project, GeoServer is developed, tested, and supported by a diverse group of
individuals and organizations from around the world.
GeoServer is the reference implementation of the Open Geospatial Consortium (OGC) Web Feature Service
(WFS) and Web Coverage Service (WCS) standards, as well as a high performance certified compliant Web
Map Service (WMS). GeoServer forms a core component of the Geospatial Web.
1.2 History
GeoServer was started in 2001 by The Open Planning Project (TOPP), a non-profit technology incubator
based in New York. TOPP was creating a suite of tools to enable open democracy and to help make government more transparent. The first of these was GeoServer, which came out of a recognition that a suite of
tools to enable citizen involvement in government and urban planning would be greatly enhanced by the
ability to share spatial data.
The GeoServer founders envisioned a Geospatial Web, analogous to the World Wide Web. With the World
Wide Web, one can search for and download text. With the Geospatial Web, one can search for and download spatial data. Data providers would be able to publish their data straight to this web, and users could
directly access it, as opposed to the now indirect and cumbersome methods of sharing data that exist today.
3
GeoServer User Manual, Release 2.15.1
Those involved with GeoServer founded the GeoTools project, an open source GIS Java toolkit. Through
GeoTools, support for shapefiles, Oracle databases, ArcSDE integration, and much more was added.
Around the same time as GeoServer was founded, The OpenGIS Consortium (now the Open Geospatial
Consortium) was working on the Web Feature Service standard. It specifies a protocol to make spatial data
directly available on the web, using GML (Geographic Markup Language), an interoperable data format. A
Web Map Service was also created, a protocol for creating and displaying map images created from spatial
data.
Other projects became interrelated. Refractions Research created PostGIS, a free and open spatial database,
which enabled GeoServer to connect to a free database. Also, MetaCarta originally created OpenLayers, an
open source browser-based map viewing utility. Together, these tools have all enhanced the functionality
of GeoServer.
GeoServer can now read data from over a dozen spatial data sources and output to many different formats.
Now in its second decade, GeoServer is continuing on its mission to make spatial data more accessible to
all.
1.3 Getting involved
GeoServer exists because of the efforts of people like you.
There are many ways that you can help out with the GeoServer project. GeoServer fully embraces an open
source development model that does not see a split between user and developer, producer and consumer,
but instead sees everyone as a valuable contributor.
1.3.1 Development
Helping to develop GeoServer is the obvious way to help out. Developers usually start with bug fixes and
other small patches, and then move into larger contributions as they learn the system. Our developers are
more than happy to help out as you learn and get acquainted. We try our hardest to keep our code clean
and well documented.
You can find the project on GitHub. As part of the GitHub model, anyone can submit patches as pull
requests, which will be evaluated by the team. To learn more about contributing to the GeoServer codebase,
we highly recommend joining the GeoServer developers mailing list. See details below.
1.3.2 Documentation
Another crucial way to help out is with documentation. Whether it’s adding tutorials or just correcting
mistakes, every contribution serves to make the project more healthy. And the best part is that you do not
need to be a developer in order to contribute.
Our official documentation is contained as part of our official code repository. As part of the GitHub model,
anyone can submit patches as pull requests, which will be evaluated by the team.
To learn more about contributing to the GeoServer codebase, we highly recommend joining the GeoServer
developers mailing list (see details below). For typos and other small changes, please see our Documentation Guide for how to make quick fixes.
1.3.3 Mailing lists
GeoServer maintains two email lists:
4
Chapter 1. Introduction
GeoServer User Manual, Release 2.15.1
• GeoServer Users
• GeoServer Developers
The Users list is mainly for those who have questions relating to the use of GeoServer, and the Developers
list is for more code-specific and roadmap-based discussions. If you see a question asked on these lists that
you know the answer to, please respond!
These lists are publicly available and are a great resource for those who are new to GeoServer, who need a
question answered, or who are interested in contributing code.
1.3.4 IRC
Users can join the IRC channel, #geoserver, on the Freenode network, in order to collaborate in real time.
GeoServer developers occasionally will be in this channel as well.
1.3.5 Bug tracking
If you have a problem when working with GeoServer, then please let us know through the mailing lists.
GeoServer uses JIRA , a bug tracking website, to manage issue reports. In order to submit an issue, you’ll
need to create an account first.
Everyone is encouraged to submit patches and, if possible, fix issues as well. We welcome patches through
JIRA, or pull requests to GitHub.
Responsible Disclosure
Warning: If you encounter a security vulnerability in GeoServer please take care to report the issue in
a responsible fashion:
• Keep exploit details out of issue report (send to developer/PSC privately – just like you would do
for sensitive sample data)
• Mark the issue as a vulnerability.
• Be prepared to work with Project Steering Committee (PSC) members on a solution
Keep in mind PSC members are volunteers and an extensive fix may require fundraising / resources
If you are not in position to communicate in public please consider commercial support, contacting a PSC
member, or reaching us via the Open Source Geospatial Foundation at info@osgeo.org.
1.3.6 Translation
We would like GeoServer available in as many languages as possible. The two areas of GeoServer to translate are the text that appears in the Web administration interface and this documentation. If you are interested
in helping with this task, please let us know via the mailing lists.
1.3.7 Suggest improvements
If you have suggestions as to how we can make GeoServer better, we would love to hear them. You can
contact us through the mailing lists or submit a feature request through JIRA.
1.3. Getting involved
5
GeoServer User Manual, Release 2.15.1
1.3.8 Spread the word
A further way to help out the GeoServer project is to spread the word. Word-of-mouth information sharing
is more powerful than any marketing, and the more people who use our software, the better it will become.
1.3.9 Fund improvements
A final way to help out is to push for GeoServer to be used in your own organization. A number of commercial organizations offer support for GeoServer, and any improvements made due to that funding will
benefit the entire GeoServer community.
1.4 License
For complete license details review LICENSE.txt.
GeoServer is free software and is licensed under the GNU General Public License:
GeoServer, open geospatial information server
Copyright (C) 2014-2016 Open Source Geospatial Foundation.
Copyright (C) 2001-2014 OpenPlans
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version (collectively, "GPL").
As an exception to the terms of the GPL, you may copy, modify,
propagate, and distribute a work formed by combining GeoServer with the
EMF, XSD and OSHI Libraries, or a work derivative of such a combination, even if
such copying, modification, propagation, or distribution would otherwise
violate the terms of the GPL. Nothing in this exception exempts you from
complying with the GPL in all respects for all of the code used other
than the EMF, XSD and OSHI Libraries. You may include this exception and its grant
of permissions when you distribute GeoServer. Inclusion of this notice
with such a distribution constitutes a grant of such permissions. If
you do not wish to grant these permissions, remove this paragraph from
your distribution. "GeoServer" means the GeoServer software licensed
under version 2 or any later version of the GPL, or a work based on such
software and licensed under the GPL. "EMF, XSD and OSHI Libraries" means
Eclipse Modeling Framework Project and XML Schema Definition software
distributed by the Eclipse Foundation and the OSHI library, all licensed
under the Eclipse Public License Version 1.0 ("EPL"), or a work based on
such software and licensed under the EPL.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335
USA
This product includes software developed by the Apache Software Foundation (http://www.apache.org/)
licensed under the Apache License Version 2.0 and Apache License Version 1.1.
6
Chapter 1. Introduction
GeoServer User Manual, Release 2.15.1
This product includes software developed by the Eclipse Software Foundation under the Eclipse
Public License.
1.4. License
7
GeoServer User Manual, Release 2.15.1
8
Chapter 1. Introduction
CHAPTER
2
Installation
There are many ways to install GeoServer on your system. This section will discuss the various installation
paths available.
If using Windows or OS X, we recommend using the installers.
Note: To run GeoServer as part of an existing servlet container such as Tomcat, please see the Web archive
section.
Warning: GeoServer requires a Java 8 environment (JRE) to be installed on your system. This must be
done prior to installation.
2.1 Windows installer
The Windows installer provides an easy way to set up GeoServer on your system, as it requires no configuration files to be edited or command line settings.
1. Make sure you have a Java Runtime Environment (JRE) installed on your system. GeoServer requires
a Java 8 environment. The Oracle JRE is preferred, but OpenJDK has been known to work adequately.
You can download JRE 8 from Oracle.
Note: Java 9 is not currently supported.
Note: For more information about Java and GeoServer, please see the section on Java Considerations.
2. Navigate to the GeoServer Download page.
9
GeoServer User Manual, Release 2.15.1
3. Select the version of GeoServer that you wish to download. If you’re not sure, select Stable.
4. Click the link for the Windows installer.
Fig. 2.1: Downloading the Windows installer
5. After downloading, double-click the file to launch.
6. At the Welcome screen, click Next.
Fig. 2.2: Welcome screen
7. Read the License and click I Agree.
8. Select the directory of the installation, then click Next.
9. Select the Start Menu directory name and location, then click Next.
10. Enter the path to a valid Java Runtime Environment (JRE). GeoServer requires a valid JRE in order
to run, so this step is required. The installer will inspect your system and attempt to automatically
populate this box with a JRE if it is found, but otherwise you will have to enter this path manually.
When finished, click Next.
Note: A typical path on Windows would be C:\Program Files\Java\jre8.
Note: Don’t include the \bin in the JRE path. So if java.exe is located at C:\Program Files
(x86)\Java\jre8\bin\java.exe, set the path to be C:\Program Files (x86)\Java\jre8.
10
Chapter 2. Installation
GeoServer User Manual, Release 2.15.1
Fig. 2.3: GeoServer license
Fig. 2.4: GeoServer install directory
2.1. Windows installer
11
GeoServer User Manual, Release 2.15.1
Fig. 2.5: Start menu location
Note: For more information about Java and GeoServer, please see the section on Java Considerations.
Fig. 2.6: Selecting a valid JRE
11. Enter the path to your GeoServer data directory or select the default. If this is your first time using
GeoServer, select the Default data directory. When finished, click Next.
12. Enter the username and password for administration of GeoServer. GeoServer’s Web administration
interface requires authentication for management, and what is entered here will become those administrator credentials. The defaults are admin / geoserver. It is recommended to change these from the
defaults. When finished, click Next.
13. Enter the port that GeoServer will respond on. This affects the location of the GeoServer Web administration interface, as well as the endpoints of the GeoServer services such as Web Map Service (WMS)
and Web Feature Service (WFS). The default port is 8080, though any valid and unused port will work.
When finished, click Next.
12
Chapter 2. Installation
GeoServer User Manual, Release 2.15.1
Fig. 2.7: Setting a GeoServer data directory
Fig. 2.8: Setting the username and password for GeoServer administration
2.1. Windows installer
13
GeoServer User Manual, Release 2.15.1
Fig. 2.9: Setting the GeoServer port
14. Select whether GeoServer should be run manually or installed as a service. When run manually,
GeoServer is run like a standard application under the current user. When installed as a service,
GeoServer is integrated into Windows Services, and thus is easier to administer. If running on a
server, or to manage GeoServer as a service, select Install as a service. Otherwise, select Run manually.
When finished, click Next.
Fig. 2.10: Installing GeoServer as a service
15. Review your selections and click the Back button if any changes need to be made. Otherwise, click
Install.
16. GeoServer will install on your system. When finished, click Finish to close the installer.
17. If you installed GeoServer as a service, it is already running. Otherwise, you can start GeoServer by
going to the Start Menu, and clicking Start GeoServer in the GeoServer folder.
18. Navigate to http://localhost:8080/geoserver (or wherever you installed GeoServer) to access the GeoServer Web administration interface.
14
Chapter 2. Installation
GeoServer User Manual, Release 2.15.1
Fig. 2.11: Verifying settings
If you see the GeoServer logo, then GeoServer is successfully installed.
Fig. 2.12: GeoServer installed and running successfully
2.1.1 Uninstallation
GeoServer can be uninstalled in two ways: by running the uninstall.exe file in the directory where
GeoServer was installed, or by standard Windows program removal.
2.2 Windows binary
Note: For the wizard-based installer on Windows, please see the section on the Windows installer. For
installing on Windows with an existing application server such as Tomcat, please see the Web archive section.
2.2. Windows binary
15
GeoServer User Manual, Release 2.15.1
An alternate way of installing GeoServer on Windows is to use the platform-independent binary. This
version is a GeoServer web application bundled inside Jetty, a lightweight and portable application server.
It has the advantages of working very similarly across all operating systems and is very simple to set up.
2.2.1 Installation
1. Make sure you have a Java Runtime Environment (JRE) installed on your system. GeoServer requires
a Java 8 environment. The Oracle JRE is preferred, but OpenJDK has been known to work adequately.
You can download JRE 8 from Oracle.
Note: Java 9 is not currently supported.
Note: For more information about Java and GeoServer, please see the section on Java Considerations.
2. Navigate to the GeoServer Download page.
3. Select the version of GeoServer that you wish to download. If you’re not sure, select Stable.
4. Select Platform Independent Binary on the download page.
5. Download the archive and unpack to the directory where you would like the program to be located.
Note: A suggested location would be C:\Program Files\GeoServer.
Setting environment variables
You will need to set the JAVA_HOME environment variable if it is not already set. This is the path to your
JRE such that %JAVA_HOME%\bin\java.exe exists.
1. Navigate to Control Panel → System → Advanced → Environment Variables.
2. Under System variables click New.
3. For Variable name enter JAVA_HOME. For Variable value enter the path to your JDK/JRE.
4. Click OK three times.
Note: You may also want to set the GEOSERVER_HOME variable, which is the directory where GeoServer
is installed, and the GEOSERVER_DATA_DIR variable, which is the location of the GeoServer data directory
(which by default is %GEOSERVER_HOME\data_dir). The latter is mandatory if you wish to use a data
directory other than the default location. The procedure for setting these variables is identical to setting the
JAVA_HOME variable.
2.2.2 Running
Note: This can be done either via Windows Explorer or the command line.
1. Navigate to the bin directory inside the location where GeoServer is installed.
16
Chapter 2. Installation
GeoServer User Manual, Release 2.15.1
2. Run startup.bat. A command-line window will appear and persist. This window contains diagnostic and troubleshooting information. This window must be left open, otherwise GeoServer will
shut down.
3. Navigate to http://localhost:8080/geoserver (or wherever you installed GeoServer) to access the GeoServer Web administration interface.
If you see the GeoServer logo, then GeoServer is successfully installed.
Fig. 2.13: GeoServer installed and running successfully
2.2.3 Stopping
To shut down GeoServer, either close the persistent command-line window, or run the shutdown.bat file
inside the bin directory.
2.2.4 Uninstallation
1. Stop GeoServer (if it is running).
2. Delete the directory where GeoServer is installed.
2.3 Mac OS X installer
The Mac OS X installer provides an easy way to set up GeoServer on your system, as it requires no configuration files to be edited or command line settings.
1. Make sure you have a Java Runtime Environment (JRE) installed on your system. GeoServer requires
a Java 8 environment, and the JRE supplied by OS X is not sufficient. For more information, please
see the instructions for installing Oracle Java on OS X.
Note: Java 9 is not currently supported.
2.3. Mac OS X installer
17
GeoServer User Manual, Release 2.15.1
Note: For more information about Java and GeoServer, please see the section on Java Considerations.
2. Navigate to the GeoServer Download page.
3. Select the version of GeoServer that you wish to download. If you’re not sure, select Stable.
4. Click the link for the Mac OS X installer to begin the download.
5. When downloaded, double click on the file to open it.
6. Drag the GeoServer icon to the Applications folder.
Fig. 2.14: Drag the GeoServer icon to Applications to install
7. Navigate to your Applications folder and double click the GeoServer icon.
8. In the resulting GeoServer console window, start GeoServer by going to Server → Start.
Fig. 2.15: Starting GeoServer
9. The console window will be populated with log entries showing the GeoServer loading process.
Once GeoServer is completely started, a browser window will open at http://localhost:8080/
geoserver, which is the Web administration interface for GeoServer.
Warning: If you encounter the following error during startup, you may have some
invalid JAI jars from the default Mac Java install:
java.lang.NoClassDefFoundError: Could not initialize class javax.media.
,→jai.JAI
18
Chapter 2. Installation
GeoServer User Manual, Release 2.15.1
To fix this error, locate your Java extensions folder (Usually /System/Library/Java/
Extensions and/or ~/Library/Java/Extensions), and delete the following jars:
jai_codec-1.1.3.jar
jai_core-1.1.3.jar
jai_imageio-1.1.jar
If you have upgraded your OS from an older version, you may not have permission to
delete these jars. In this case, you will first need to disable System Integrity Protection.
2.4 Mac OS X binary
Note: For the installer on OS X, please see the section on the Mac OS X installer. For installing on OS X
with an existing application server such as Tomcat, please see the Web archive section.
An alternate way of installing GeoServer on OS X is to use the platform-independent binary. This version
is a GeoServer web application bundled inside Jetty, a lightweight and portable application server. It has
the advantages of working very similarly across all operating systems and is very simple to set up.
2.4.1 Installation
1. Make sure you have a Java Runtime Environment (JRE) installed on your system. GeoServer requires
a Java 8 environment, and the JRE supplied by OS X is not sufficient. For more information, please
see the instructions for installing Oracle Java on OS X.
Note: Java 9 is not currently supported.
Note: For more information about Java and GeoServer, please see the section on Java Considerations.
2. Navigate to the GeoServer Download page.
3. Select the version of GeoServer that you wish to download. If you’re not sure, select Stable.
4. Select Platform Independent Binary on the download page.
5. Download the archive and unpack to the directory where you would like the program to be located.
Note: A suggested location would be /usr/local/geoserver.
6. Add an environment variable to save the location of GeoServer by typing the following command:
echo "export GEOSERVER_HOME=/usr/local/geoserver" >> ~/.profile
. ~/.profile
7. Make yourself the owner of the geoserver folder, by typing the following command:
sudo chown -R /usr/local/geoserver/
2.4. Mac OS X binary
19
GeoServer User Manual, Release 2.15.1
where USER_NAME is your user name
8. Start GeoServer by changing into the directory geoserver/bin and executing the startup.sh
script:
cd geoserver/bin
sh startup.sh
Warning: If you encounter the following error during startup, you may have some
invalid JAI jars from the default Mac Java install:
java.lang.NoClassDefFoundError: Could not initialize class javax.media.
,→jai.JAI
To fix this error, locate your Java extensions folder (Usually /System/Library/Java/
Extensions and/or ~/Library/Java/Extensions), and delete the following jars:
jai_codec-1.1.3.jar
jai_core-1.1.3.jar
jai_imageio-1.1.jar
If you have upgraded your OS from an older version, you may not have permission to
delete these jars. In this case, you will first need to disable System Integrity Protection.
9. In a web browser, navigate to http://localhost:8080/geoserver.
If you see the GeoServer logo, then GeoServer is successfully installed.
Fig. 2.16: GeoServer installed and running successfully
To shut down GeoServer, either close the persistent command-line window, or run the shutdown.sh file
inside the bin directory.
2.4.2 Uninstallation
1. Stop GeoServer (if it is running).
2. Delete the directory where GeoServer is installed.
20
Chapter 2. Installation
GeoServer User Manual, Release 2.15.1
2.5 Linux binary
Note: For installing on Linux with an existing application server such as Tomcat, please see the Web archive
section.
The platform-independent binary is a GeoServer web application bundled inside Jetty, a lightweight and
portable application server. It has the advantages of working very similarly across all operating systems
and is very simple to set up.
2.5.1 Installation
1. Make sure you have a Java Runtime Environment (JRE) installed on your system. GeoServer requires
a Java 8 environment. The Oracle JRE is preferred, but OpenJDK has been known to work adequately.
You can download JRE 8 from Oracle.
Note: Java 9 is not currently supported.
2. Select the version of GeoServer that you wish to download. If you’re not sure, select Stable.
3. Select Platform Independent Binary on the download page.
4. Download the archive and unpack to the directory where you would like the program to be located.
Note: A suggested location would be /usr/share/geoserver.
5. Add an environment variable to save the location of GeoServer by typing the following command:
echo "export GEOSERVER_HOME=/usr/share/geoserver" >> ~/.profile
. ~/.profile
6. Make yourself the owner of the geoserver folder. Type the following command in the terminal
window, replacing USER_NAME with your own username :
sudo chown -R USER_NAME /usr/share/geoserver/
7. Start GeoServer by changing into the directory geoserver/bin and executing the startup.sh
script:
cd geoserver/bin
sh startup.sh
8. In a web browser, navigate to http://localhost:8080/geoserver.
If you see the GeoServer logo, then GeoServer is successfully installed.
To shut down GeoServer, either close the persistent command-line window, or run the shutdown.sh file
inside the bin directory.
2.5. Linux binary
21
GeoServer User Manual, Release 2.15.1
Fig. 2.17: GeoServer installed and running successfully
2.5.2 Uninstallation
1. Stop GeoServer (if it is running).
2. Delete the directory where GeoServer is installed.
2.6 Web archive
GeoServer is packaged as a standalone servlet for use with existing application servers such as Apache
Tomcat and Jetty.
Note: GeoServer has been mostly tested using Tomcat, and so is the recommended application server.
GeoServer requires a newer version of Tomcat (7.0.65 or later) that implements Servlet 3 and annotation
processing. Other application servers have been known to work, but are not guaranteed.
2.6.1 Installation
1. Make sure you have a Java Runtime Environment (JRE) installed on your system. GeoServer requires
a Java 8 environment. The Oracle JRE is preferred, but OpenJDK has been known to work adequately.
You can download JRE 8 from Oracle.
Note: Java 9 is not currently supported.
Note: For more information about Java and GeoServer, please see the section on Java Considerations.
2. Navigate to the GeoServer Download page.
3. Select Web Archive on the download page.
4. Download and unpack the archive.
22
Chapter 2. Installation
GeoServer User Manual, Release 2.15.1
5. Deploy the web archive as you would normally. Often, all that is necessary is to copy the geoserver.
war file to the application server’s webapps directory, and the application will be deployed.
Note: A restart of your application server may be necessary.
2.6.2 Running
Use your container application’s method of starting and stopping webapps to run GeoServer.
To access the Web administration interface, open a browser and navigate to http://SERVER/geoserver
. For example, with Tomcat running on port 8080 on localhost, the URL would be http://
localhost:8080/geoserver.
2.6.3 Uninstallation
1. Stop the container application.
2. Remove the GeoServer webapp from the container application’s webapps directory. This will usually
include the geoserver.war file as well as a geoserver directory.
2.7 Upgrading existing versions
Warning: Be aware that some upgrades are not reversible, meaning that the data directory may be
changed so that it is no longer compatible with older versions of GeoServer. See Migrating a data directory
between versions for more details.
The general GeoServer upgrade process is as follows:
1. Back up the current data directory. This can involve simply copying the directory to an additional
place.
2. Make sure that the current data directory is external to the application (not located inside the application file structure).
3. Uninstall the old version and install the new version.
Note: Alternately, you can install the new version directly over top of the old version.
4. Make sure that the new version continues to point to the same data directory used by the previous
version.
2.7.1 Notes on upgrading specific versions
GeoJSON encoding (GeoServer 2.6 and newer)
As of GeoServer 2.6, the GeoJSON produced by the WFS service no longer uses a nonstandard encoding for the CRS. To reenable this behavior for compatibility purposes, set
2.7. Upgrading existing versions
23
GeoServer User Manual, Release 2.15.1
GEOSERVER_GEOJSON_LEGACY_CRS=true as a system property, context parameter, or environment
variable.
JTS Type Bindings (GeoServer 2.14 and newer)
As of GeoServer 2.14, the output produced by REST featuretype and structured coverage requests using
a different package name (org.locationtech instead of com.vividsolutions) for geometry type
bindings, due to the upgrade to JTS (Java Topology Suite) 1.16.0. For example:
Before:
...
geom01truecom.vividsolutions.jts.geom.Point
...
After:
...
geom01trueorg.locationtech.jts.geom.Point
...
Any REST clients which rely on this binding information should be updated to support the new names.
24
Chapter 2. Installation
CHAPTER
3
Getting started
This section contains short tutorials for common tasks in GeoServer to get new users using the system
quickly.
3.1 Using the web administration interface
GeoServer has a browser-based web administration interface application used to configure all aspects of
GeoServer, from adding and publishing data to changing service settings.
The web admin interface is accessed via a web browser at:
http://:/geoserver
For a default installation on a server the link is:
http://localhost:8080/geoserver
When the application starts, it displays the Welcome page.
Fig. 3.1: Welcome Page
25
GeoServer User Manual, Release 2.15.1
3.1.1 Logging In
In order to change any server settings or configure data, a user must first be authenticated.
1. Navigate to the upper right of the web interface to log into GeoServer. The default administration
credentials are:
• User name: admin
• Password: geoserver
Note: These can be changed in the Security section.
Fig. 3.2: Login
2. Once logged in, the Welcome screen changes to show the available admin functions. These are primarily shown in the menus on the left side of the page.
Fig. 3.3: Additional options when logged in
3.1.2 Layer Preview
The Layer Preview page allows you to quickly view the output of published layers.
1. Click the Layer Preview link on the menu to go to this page.
2. From here, you can find the layer you’d like to preview and click a link for an output format. Click
the OpenLayers link for a given layer and the view will display.
3. To sort a column alphabetically, click the column header.
26
Chapter 3. Getting started
GeoServer User Manual, Release 2.15.1
Fig. 3.4: Unsorted (left) and sorted (right) columns
3.1. Using the web administration interface
27
GeoServer User Manual, Release 2.15.1
4. Searching can be used to filter the number of items displayed. This is useful for working with data
types that contain a large number of items. To search data type items, enter the search string in the
search box and click Enter. GeoServer will search the data type for items that match your query, and
display a list view showing the search results.
Fig. 3.5: Search results for the query “top” on the Workspace page
Note: Sorting and searching apply to all data configuration pages.
Note: For more information, please see the Layer Preview section.
3.2 Publishing a shapefile
This tutorial walks through the steps of publishing a Shapefile with GeoServer.
Note: This tutorial assumes that GeoServer is running at http://localhost:8080/geoserver.
3.2.1 Data preparation
First let’s gather that the data that we’ll be publishing.
1. Download the file nyc_roads.zip. This archive contains a shapefile of roads from New York City
that will be used during in this tutorial.
2. Unzip the nyc_roads.zip into a new directory named nyc_roads. The archive contains the following four files:
nyc_roads.shp
nyc_roads.shx
nyc_roads.dbf
nyc_roads.prj
3. Move
the
nyc_roads
directory
into
/data,
where
is the root of the GeoServer data directory. If no changes have been
made to the GeoServer file structure, the path is geoserver/data_dir/data/nyc_roads.
3.2.2 Creating a new workspace
The next step is to create a workspace for the shapefile. A workspace is a container used to group similar
layers together.
28
Chapter 3. Getting started
GeoServer User Manual, Release 2.15.1
Note: This step is optional if you’d like to use an existing workspace. Usually, a workspace is created for
each project, which can include stores and layers that are related to each other.
1. In a web browser, navigate to http://localhost:8080/geoserver.
2. Log into GeoServer as described in the Logging In section.
3. Navigate to Data → Workspaces.
Fig. 3.6: Workspaces page
4. Click the Add new workspace button.
5. You will be prompted to enter a workspace Name and Namespace URI.
Fig. 3.7: Configure a new workspace
6. Enter the Name as nyc and the Namespace URI as http://geoserver.org/nyc.
Note: A workspace name is a identifier describing your project. It must not exceed ten characters
or contain spaces. A Namespace URI (Uniform Resource Identifier) can usually be a URL associated
with your project with an added trailing identifier indicating the workspace. The Namespace URI
filed does not need to resolve to an actual valid web address.
3.2. Publishing a shapefile
29
GeoServer User Manual, Release 2.15.1
Fig. 3.8: nyc workspace
7. Click the Submit button. The nyc workspace will be added to the Workspaces list.
3.2.3 Create a store
Once the workspace is created, we are ready to add a new store. The store tells GeoServer how to connect
to the shapefile.
1. Navigate to Data→Stores.
2. You should see a list of stores, including the type of store and the workspace that the store belongs to.
3. In order to add the shapefile, you need to create a new store. Click the Add new Store button. You
will be redirected to a list of the data sources supported by GeoServer. Note that the data sources are
extensible, so your list may look slightly different.
Fig. 3.9: Stores
4. Click Shapefile. The New Vector Data Source page will display.
5. Begin by configuring the Basic Store Info.
• Select the workspace nyc from the drop down menu.
• Enter the Data Source Name as NYC Roads
• Enter a brief Description (such as “Roads in New York City”).
30
Chapter 3. Getting started
GeoServer User Manual, Release 2.15.1
6. Under Connection Parameters, browse to the location URL of the shapefile, typically nyc_roads/
nyc_roads.shp.
Fig. 3.10: Basic Store Info and Connection Parameters
7. Click Save. You will be redirected to the New Layer page in order to configure the nyc_roads layer.
3.2.4 Creating a layer
Now that the store is loaded, we can publish the layer.
1. On the New Layer page, click Publish beside the nyc_roads layer name.
Fig. 3.11: New layer
2. The Edit Layer page defines the data and publishing parameters for a layer. Enter a short Title and an
Abstract for the nyc_roads layer.
3. Generate the layer’s bounding boxes by clicking the Compute from data and then Compute from native
bounds links.
4. Click the Publishing tab at the top of the page.
5. We can set the layer’s style here. Under WMS Settings, ensure that the Default Style is set to line.
6. Finalize the layer configuration by scrolling to the bottom of the page and clicking Save.
3.2. Publishing a shapefile
31
GeoServer User Manual, Release 2.15.1
Fig. 3.12: Basic Resource Information
Fig. 3.13: Generating bounding boxes
Fig. 3.14: Select Default Style
32
Chapter 3. Getting started
GeoServer User Manual, Release 2.15.1
3.2.5 Previewing the layer
In order to verify that the nyc_roads layer is published correctly, we can preview the layer.
1. Navigate to the Layer Preview screen and find the nyc:nyc_roads layer.
Fig. 3.15: Layer Preview
2. Click the OpenLayers link in the Common Formats column.
3. An OpenLayers map will load in a new tab and display the shapefile data with the default line style.
You can use this preview map to zoom and pan around the dataset, as well as display the attributes
of features.
Fig. 3.16: Preview map of nyc_roads
3.3 Publishing a PostGIS table
This tutorial walks through the steps of publishing a PostGIS table with GeoServer.
3.3. Publishing a PostGIS table
33
GeoServer User Manual, Release 2.15.1
Note:
This tutorial assumes that PostgreSQL/PostGIS has been previously installed on the system and responding on localhost on port 5432, and also that GeoServer is running at http://
localhost:8080/geoserver.
3.3.1 Data preparation
First let’s gather that the data that we’ll be publishing.
1. Download the file nyc_buildings.zip. It contains a PostGIS dump of a dataset of buildings from
New York City.
2. Create a PostGIS database called nyc. This can be done with the following commands:
createdb nyc
psql -d nyc -c 'CREATE EXTENSION postgis'
Note: You may need to supply a user name and password with these commands.
3. Extract nyc_buildings.sql from nyc_buildings.zip.
4. Import nyc_buildings.sql into the nyc database:
psql -f nyc_buildings.sql nyc
3.3.2 Creating a new workspace
The next step is to create a workspace for the data. A workspace is a container used to group similar layers
together.
Note: This step is optional if you’d like to use an existing workspace. Usually, a workspace is created for
each project, which can include stores and layers that are related to each other.
1. In a web browser, navigate to http://localhost:8080/geoserver.
2. Log into GeoServer as described in the Logging In section.
3. Navigate to Data → Workspaces.
4. Click the Add new workspace button.
5. You will be prompted to enter a workspace Name and Namespace URI.
6. Enter the Name as nyc and the Namespace URI as http://geoserver.org/nyc.
Note: A workspace name is a identifier describing your project. It must not exceed ten characters
or contain spaces. A Namespace URI (Uniform Resource Identifier) can usually be a URL associated
with your project with an added trailing identifier indicating the workspace. The Namespace URI
filed does not need to resolve to an actual valid web address.
7. Click the Submit button. The nyc workspace will be added to the Workspaces list.
34
Chapter 3. Getting started
GeoServer User Manual, Release 2.15.1
Fig. 3.17: Workspaces page
Fig. 3.18: Configure a new workspace
3.3. Publishing a PostGIS table
35
GeoServer User Manual, Release 2.15.1
3.3.3 Creating a store
Once the workspace is created, we are ready to add a new store. The store tells GeoServer how to connect
to the shapefile.
1. Navigate to Data→Stores.
2. You should see a list of stores, including the type of store and the workspace that the store belongs to.
Fig. 3.19: Adding a new data source
3. Create a new store by clicking the PostGIS link.
4. Enter the Basic Store Info:
• Select the nyc Workspace
• Enter the Data Source Name as nyc_buildings
• Add a brief Description
Fig. 3.20: Basic Store Info
5. Specify the PostGIS database Connection Parameters:
36
Chapter 3. Getting started
GeoServer User Manual, Release 2.15.1
Option
dbtype
host
port
database
schema
user
passwd
validate connections
Value
postgis
localhost
5432
nyc
public
postgres
(Password for the postgres user)
(Checked)
Note: Leave all other fields at their default values.
Fig. 3.21: Connection Parameters
6. Click Save.
3.3.4 Creating a layer
Now that the store is loaded, we can publish the layer.
1. Navigate to Data → Layers.
2. Click Add a new resource.
3. From the New Layer chooser menu, select nyc:nyc_buidings.
4. On the resulting layer row, select the layer name nyc_buildings.
5. The Edit Layer page defines the data and publishing parameters for a layer. Enter a short Title and an
Abstract for the nyc_buildings layer.
3.3. Publishing a PostGIS table
37
GeoServer User Manual, Release 2.15.1
Fig. 3.22: Store selection
Fig. 3.23: New layer selection
Fig. 3.24: Basic Resource Info
38
Chapter 3. Getting started
GeoServer User Manual, Release 2.15.1
6. Generate the layer’s bounding boxes by clicking the Compute from data and then Compute from native
bounds links.
Fig. 3.25: Generating bounding boxes
7. Click the Publishing tab at the top of the page.
8. We can set the layer’s style here. Under WMS Settings, ensure that the Default Style is set to polygon.
Fig. 3.26: Select Default Style
9. Finalize the layer configuration by scrolling to the bottom of the page and clicking Save.
3.3.5 Previewing the layer
In order to verify that the nyc_buildings layer is published correctly, we can preview the layer.
1. Navigate to the Layer Preview screen and find the nyc:nyc_buildings layer.
2. Click the OpenLayers link in the Common Formats column.
3. An OpenLayers map will load in a new tab and display the shapefile data with the default line style.
You can use this preview map to zoom and pan around the dataset, as well as display the attributes
of features.
3.3. Publishing a PostGIS table
39
GeoServer User Manual, Release 2.15.1
Fig. 3.27: Preview map of nyc_buildings
40
Chapter 3. Getting started
CHAPTER
4
Web administration interface
The Web administration interface is a web-based tool for configuring all aspects of GeoServer, from adding
data to changing service settings. In a default GeoServer installation, this interface is accessed via a web
browser at http://localhost:8080/geoserver/web. However, this URL may vary depending on
your local installation.
Fig. 4.1: Web admin interface
The following sections detail the menu options available in GeoServer. Unless otherwise specified, you
will need to be logged in with administrative credentials to see these options.
4.1 About & Status
The About & Status section provides access to GeoServer diagnostic and configuration tools, and can be
particularly useful for debugging.
• The Status page shows a summary of server configuration parameters and run-time status.
• The GeoServer Logs page shows the GeoServer log output. This is useful for determining errors without having to leave the browser.
41
GeoServer User Manual, Release 2.15.1
• The Contact Information page sets the public contact information available in the Capabilities document of the WMS server.
• The About GeoServer section provides links to the GeoServer documentation, homepage and bug
tracker. You do not need to be logged into GeoServer to access this page.
4.2 Data
The Data management section contains configuration options for all the different data-related settings.
• The Layer Preview page provides links to layer previews in various output formats, including the common OpenLayers and KML formats. This page helps to visually verify and explore the configuration
of a particular layer. You do not need to be logged into GeoServer to access the Layer Preview.
• The Workspaces page displays a list of workspaces, with the ability to add, edit, and delete. Also shows
which workspace is the default for the server.
• The Stores page displays a list of stores, with the ability to add, edit, and delete. Details include the
workspace associated with the store, the type of store (data format), and whether the store is enabled.
• The Layers page displays a list of layers, with the ability to add, edit, and delete. Details include the
workspace and store associated with the layer, whether the layer is enabled, and the spatial reference
system (SRS) of the layer.
• The Layer Groups page displays a list of layer groups, with the ability to add, edit, and delete. Details
include the associated workspace (if any).
• The Styles page displays a list of styles, with the ability to add, edit, and delete. Details include the
associated workspace (if any).
In each of these pages that contain a table, there are three different ways to locate an object: sorting, searching, and paging. To alphabetically sort a data type, click on the column header. For simple searching, enter
the search criteria in the search box and hit Enter. And to page through the entries (25 at a time), use the
arrow buttons located on the bottom and top of the table.
4.3 Services
The Services section is for configuring the services published by GeoServer.
• The Web Coverage Service (WCS) page manages metadata, resource limits, and SRS availability for
WCS.
• The Web Feature Service (WFS) page manages metadata, feature publishing, service level options, and
data-specific output for WFS.
• The Web Map Service (WMS) page manages metadata, resource limits, SRS availability, and other dataspecific output for WMS.
4.4 Settings
The Settings section contains configuration settings that apply to the entire server.
• The Global Settings page configures messaging, logging, character and proxy settings for the entire
server.
42
Chapter 4. Web administration interface
GeoServer User Manual, Release 2.15.1
• The Image Processing page configures several JAI parameters, used by both WMS and WCS operations.
• The Coverage Access page configures settings related to loading and publishing coverages.
4.5 Tile Caching
The Tile Caching section configures the embedded GeoWebCache.
• The Tile Layers page shows which layers in GeoServer are also available as tiled (cached)layers, with
the ability to add, edit, and delete.
• The Caching Defaults page sets the global options for the caching service.
• The Gridsets page shows all available gridsets for the tile caches, with the ability to add, edit, and
delete.
• The Disk Quota page sets the options for tile cache management on disk, including strategies to reduce
file size when necessary.
• The BlobStores pages manages the different blobstores (tile cache sources) known to the embedded
GeoWebCache.
4.6 Security
The Security section configures the built-in security subsystem.
• The Settings page manages high-level options for the security subsystem.
• The Authentication page manages authentication filters, filter chains, and providers.
• The Passwords page manages the password policies for users and the master (root) account.
• The Users, Groups, Roles page manages the users, groups, and roles, and how they are all associated
with each other. Passwords for user accounts can be changed here.
• The Data page manages the data-level security options, allowing workspaces and layers to be restricted by role.
• The Services page manages the service-level security options, allowing services and operations to be
restricted by role.
4.7 Demos
The Demos section contains links to example WMS, WCS, and WFS requests for GeoServer as well as a listing all SRS info known to GeoServer. In addition, there is a reprojection console for converting coordinates
between spatial reference systems, and a request builder for WCS requests. You do not need to be logged
into GeoServer to access these pages.
4.8 Tools
The Tools section contains administrative tools. By default, the only tool is the Catalog Bulk Load Tool, which
can bulk copy test data into the catalog.
4.5. Tile Caching
43
GeoServer User Manual, Release 2.15.1
4.9 Extensions
GeoServer extensions can add functionality and extra options to the web interface. Details can be found in
the section for each extension.
44
Chapter 4. Web administration interface
CHAPTER
5
Data management
GeoServer connects to and publishes data from a wide variety of sources. This section will discuss how to
use the GeoServer web interface to accomplish most common tasks, along with the different data formats
served by GeoServer.
Note: There are many more data sources available through Extensions and Community modules. If you are
looking for a specific data format and not finding it here, please check those sections.
5.1 Data settings
This section describes how to manage load, manage, and publish data in the GeoServer web interface.
It describes the core configuration data types that GeoServer uses to access and publish geospatial information. Each subsection describes the data type pages which provide add, view, edit, and delete capabilities.
5.1.1 Layer Preview
This page provides layer views in various output formats. A layer must be enabled to be previewed.
Each layer row consists of a type, name, title, and available formats for viewing.
Field Description
Raster (grid)
Polygon
Line
Point
Other Geometry
Layer Group
Cascading WMS
Unknown/Other
45
GeoServer User Manual, Release 2.15.1
Fig. 5.1: Layer Preview Page
Name refers to the Workspace and Layer Name of a layer, while Title refers to the brief description configured in the Edit Layer: Data panel. In the following example, nurc refers to the Workspace, Arc_Sample
refers to the Layer Name and “A sample ArcGrid field” is specified on the Edit Later Data panel.
Fig. 5.2: Single Layer preview row
Output Formats
The Layer Preview page supports a variety of output formats for further use or data sharing. You can
preview all three layer types in the common OpenLayers and KML formats. Similarly, using the “All
formats” menu you can preview all layer types in seven additional output formats—AtomPub, GIF, GeoRss,
JPEG, KML (compressed), PDF, PNG, SVG, and TIFF. Only Vector layers provide the WFS output previews,
including the common GML as well as the CSV, GML3, GeoJSON and shapefile formats. The table below
provides a brief description of all supported output formats, organized by output type (image, text, or
data).
Image Outputs
All image outputs can be initiated from a WMS getMap request on either a raster, vector or coverage data.
WMS are methods that allows visual display of spatial data without necessarily providing access to the
features that comprise those data.
46
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
Format
KML
Description
KML (Keyhole Markup Language) is an XML-based language schema for expressing geographic data in an Earth browser, such as Google Earth or Google Maps. KML uses a tagbased structure with nested elements and attributes. For GeoServer, KML files are distributed
as a KMZ, which is a zipped KML file.
JPEG
WMS output in raster format. The JPEG is a compressed graphic file format, with some loss
of quality due to compression. It is best used for photos and not recommended for exact
reproduction of data.
GIF
WMS output in raster format. The GIF (Graphics Interchange Format) is a bitmap image
format best suited for sharp-edged line art with a limited number of colors. This takes advantage of the format’s lossless compression, which favors flat areas of uniform color with well
defined edges (in contrast to JPEG, which favors smooth gradients and softer images). GIF is
limited to an 8-bit palette, or 256 colors.
SVG
WMS output in vector format. SVG (Scalable Vector Graphics) is a language for modeling
two-dimensional graphics in XML. It differs from the GIF and JPEG in that it uses graphic
objects rather than individual points.
TIFF
WMS output in raster format. TIFF (Tagged Image File Format) is a flexible, adaptable format
for handling multiple data in a single file. GeoTIFF contains geographic data embedded as
tags within the TIFF file.
PNG
WMS output in raster format. The PNG (Portable Network Graphics) file format was created
as the free, open-source successor to the GIF. The PNG file format supports truecolor (16
million colors) while the GIF supports only 256 colors. The PNG file excels when the image
has large, uniformly coloured areas.
OpenLayers
WMS GetMap request outputs a simple OpenLayers preview window. OpenLayers is an open
source JavaScript library for displaying map data in web browsers. The OpenLayers output
has some advanced filters that are not available when using a standalone version of OpenLayers. Further, the generated preview contains a header with easy configuration options for
display. Version 3 of the OpenLayers library is used by default. Version 3 can be disabled
with the ENABLE_OL3 (true/false) format option or system property. For older browsers not
supported by OpenLayers 3, version 2 is used regardless of the setting.
PDF
A PDF (Portable Document Format) encapsulates a complete description of a fixed-layout 2D
document,including any text, fonts, raster images, and 2D vector graphics.
Fig. 5.3: Sample Image Output-an OpenLayers preview of nurc:Pk50095
5.1. Data settings
47
GeoServer User Manual, Release 2.15.1
Text Outputs
Format
Description
AtomPub WMS output of spatial data in XML format. The AtomPub (Atom Publishing Protocol) is an
application-level protocol for publishing and editing Web Resources using HTTP and XML.
Developed as a replacement for the RSS family of standards for content syndication, Atom
allows subscription of geo data.
GeoRss WMS GetMap request output of vector data in XML format. RSS (Rich Site Summary) is an
XML format for delivering regularly changing web content. GeoRss is a standard for encoding
location as part of a RSS feed.supports Layers Preview produces a RSS 2.0 documents, with
GeoRSS Simple geometries using Atom.
GeoJSON JavaScript Object Notation (JSON) is a lightweight data-interchange format based on the
JavaScript programming language. This makes it an ideal interchange format for browser
based applications since it can be parsed directly and easily in to javascript. GeoJSON is a
plain text output format that add geographic types to JSON.
CSV
WFS GetFeature output in comma-delimited text. CSV (Comma Separated Values) files
are text files containing rows of data. Data values in each row are separated by commas.
CSV files also contain a comma-separated header row explaining each row’s value ordering.
GeoServer’s CSVs are fully streaming, with no limitation on the amount of data that can be
outputted.
A fragment of a simple GeoRSS for nurc:Pk50095 using Atom:
Pk50095Feed auto-generated by GeoServer
>
fid--f04ca6b_1226f8d829e_-7ff446.722110379286 13.00635746384126
46.72697223230676 13.308182612644663 46.91359611878293
13.302316867622581 46.90870264238999 12.999446822650462
46.722110379286 13.00635746384126
Data Outputs
All data outputs are initiated from a WFS GetFeature request on vector data.
48
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
Format
Description
GML2/3 GML (Geography Markup Language) is the XML grammar defined by the Open Geospatial
Consortium (OGC) to express geographical features. GML serves as a modeling language for
geographic systems as well as an open interchange format for geographic data sharing. GML2
is the default (Common) output format, while GML3 is available from the “All Formats”
menu.
Shapefile The ESRI Shapefile, or simply a shapefile, is the most commonly used format for exchanging
GIS data. GeoServer outputs shapefiles in zip format, with a directory of .cst, .dbf, .prg, .shp,
and .shx files.
5.1.2 Workspaces
This section describes how to view and configure workspaces. Analogous to a namespace, a workspace is a
container which organizes other items. In GeoServer, a workspace is often used to group similar layers together. Layers may be referred to by their workspace name, colon, layer name (for example topp:states).
Two different layers can have the same name as long as they belong to different workspaces (for example
sf:states and topp:states).
Fig. 5.4: Workspaces page
Edit a Workspace
To view or edit a workspace, click the workspace name. A workspace configuration page will be displayed.
A workspace is defined by a name and a Namespace URI (Uniform Resource Identifier). The workspace
name is limited to ten characters and may not contain space. A URI is similar to a URL, except URIs do not
need to point to a actual location on the web, and only need to be a unique identifier. For a Workspace URI,
we recommend using a URL associated with your project, with perhaps a different trailing identifier. For
example, http://www.openplans.org/topp is the URI for the “topp” workspace.
5.1. Data settings
49
GeoServer User Manual, Release 2.15.1
Fig. 5.5: Workspace named “topp”
Root Directory for REST PathMapper
Fig. 5.6: Workspace Root Directory parameter
This parameter is used by the RESTful API as the Root Directory for uploaded files, following the structure:
${rootDirectory}/workspace/store[/]
Note: This parameter is visible only when the Enabled parameter of the Settings section is checked.
Add a Workspace
The buttons for adding and removing a workspace can be found at the top of the Workspaces view page.
Fig. 5.7: Buttons to add and remove
To add a workspace, select the Add new workspace button. You will be prompted to enter the the workspace
name and URI.
Remove a Workspace
To remove a workspace, select it by clicking the checkbox next to the workspace. Multiple workspaces
can be selected, or all can be selected by clicking the checkbox in the header. Click the Remove selected
workspaces(s) button. You will be asked to confirm or cancel the removal. Clicking OK removes the selected
workspace(s).
50
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
Fig. 5.8: New Workspace page with example
Fig. 5.9: Workspace removal confirmation
5.1. Data settings
51
GeoServer User Manual, Release 2.15.1
Isolated Workspaces
Isolated workspaces content is only visible and queryable in the context of a virtual service bound to the
isolated workspace. This means that isolated workspaces content will not show up in global capabilities
documents and global services cannot query isolated workspaces contents. Is worth mentioning that those
restrictions don’t apply to the REST API.
A workspace can be made isolated by checking the Isolated Workspace checkbox when creating or editing a
workspace.
Fig. 5.10: Making a workspace isolated
An isolated workspace will be able to reuse a namespace already used by another workspace, but its resources (layers, styles, etc . . . ) can only be retrieved when using that workspace virtual services and will
only show up in those virtual services capabilities documents.
It is only possible to create two or more workspaces with the same namespace in GeoServer if only one
of them is non isolated, i.e. isolated workspaces have no restrictions in namespaces usage but two non
isolated workspaces can’t use the same namespace.
The following situation will be valid:
• Prefix: st1 Namespace: http://www.stations.org/1.0 Isolated: false
• Prefix: st2 Namespace: http://www.stations.org/1.0 Isolated: true
• Prefix: st3 Namespace: http://www.stations.org/1.0 Isolated: true
But not the following one:
• Prefix: st1 Namespace: http://www.stations.org/1.0 Isolated: false
• Prefix: st2 Namespace: http://www.stations.org/1.0 Isolated: false
• Prefix: st3 Namespace: http://www.stations.org/1.0 Isolated: true
At most only one non isolated workspace can use a certain namespace.
Consider the following image which shows to workspaces (st1 and st2) that use the same namespace (http:
//www.stations.org/1.0) and several layers contained by them:
Fig. 5.11: Two workspaces using the same namespace, one of them is isolated.
In the example above st2 is the isolated workspace. Consider the following WFS GetFeature requests:
52
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
1. http://localhost:8080/geoserver/ows?service=WFS&version=2.0.0&request=
DescribeFeatureType&typeName=layer2
2. http://localhost:8080/geoserver/st2/ows?service=WFS&version=2.0.0&request=
DescribeFeatureType&typeName=layer2
3. http://localhost:8080/geoserver/ows?service=WFS&version=2.0.0&request=
DescribeFeatureType&typeName=st1:layer2
4. http://localhost:8080/geoserver/st2/ows?service=WFS&version=2.0.0&request=
DescribeFeatureType&typeName=st2:layer2
5. http://localhost:8080/geoserver/ows?service=WFS&version=2.0.0&request=
DescribeFeatureType&typeName=st2:layer2
6. http://localhost:8080/geoserver/ows?service=WFS&version=2.0.0&request=
DescribeFeatureType&typeName=layer5
The first request is targeting WFS global service and requesting layer2, this request will use layer2 contained
by workspace st1. The second request is targeting st2 workspace WFS virtual service, layer2 belonging to
workspace st2 will be used. Request three and four will use layer2 belonging to workspace, respectively,
st1 and st2. The last two requests will fail saying that the feature type was not found, isolated workspaces
content is not visible globally.
The rule of thumb is that resources (layers, styles, etc . . . ) belonging to an isolated workspace can only
be retrieved when using that workspaces virtual services and will only show up in those virtual services
capabilities documents.
5.1.3 Stores
A store connects to a data source that contains raster or vector data. A data source can be a file or group
of files, a table in a database, a single raster file, or a directory (for example, a Vector Product Format
library). The store construct allows connection parameters to be defined once, rather than for each dataset
in a source. As such, it is necessary to register a store before configuring datasets within it.
Fig. 5.12: Stores View
5.1. Data settings
53
GeoServer User Manual, Release 2.15.1
Store types
While there are many potential formats for data sources, there are only four kinds of stores. For raster data,
a store can be a file. For vector data, a store can be a file, database, or server.
Type Icon
Description
raster data in a file
vector data in a file
vector data in a database
vector server (web feature server)
Edit a Store
To view or edit a store, click the store name. A store configuration page will be displayed. The exact
contents of this page depend on the specific format of the store. See the sections Vector data, Raster data,
and Databases for information about specific data formats. The example shows the configuration for the
nurc:ArcGridSample store.
Fig. 5.13: Editing a raster data store
Basic Store Info
The basic information is common for all formats.
• Workspace - the store is assigned to the selected workspace
• Data Source Name - the store name as listed on the view page
• Description - (optional) a description that displays in the administration interface
• Enabled - enables or disables access to the store, along with all datasets defined for it
Connection Parameters
The connection parameters vary depending on data format.
54
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
Add a Store
The buttons for adding and removing a store can be found at the top of the Stores page.
Fig. 5.14: Buttons to add and remove a Store
To add a store, select the Add new Store button. You will be prompted to choose a data source. GeoServer
natively supports many formats (with more available via extensions). Click the appropriate data source to
continue.
Fig. 5.15: Choosing the data source for a new store
The next page configures the store. Since connection parameters differ across data sources, the exact contents of this page depend on the store’s specific format. See the sections Vector data, Raster data, and Databases
for information on specific data formats. The example below shows the ArcGrid raster configuration page.
Remove a Store
To remove a store, click the checkbox next to the store. Multiple stores can be selected, or all can be selected
by clicking the checkbox in the header.
Click the Remove selected Stores button. You will be asked to confirm the removal of the configuration for
the store(s) and all resources defined under them. Clicking OK removes the selected store(s), and returns to
the Stores page.
5.1.4 Layers
In GeoServer, the term “layer” refers to a raster or vector dataset that represents a collection of geographic
features. Vector layers are analogous to “featureTypes” and raster layers are analogous to “coverages”. All
layers have a source of data, known as a Store. The layer is associated with the Workspace in which the
Store is defined.
5.1. Data settings
55
GeoServer User Manual, Release 2.15.1
Fig. 5.16: Configuration page for an ArcGrid raster data source
Fig. 5.17: Stores selected for removal
56
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
Fig. 5.18: Confirm removal of stores
In the Layers section of the web interface, you can view and edit existing layers, add (register) a new
layer, or remove (unregister) a layer. The Layers View page displays the list of layers, and the Store and
Workspace in which each layer is contained. The View page also displays the layer’s status and native SRS.
Layer types
Layers can be divided into two types of data: raster and vector. These two formats differ in how they store
spatial information. Vector types store information about feature types as mathematical paths—a point as
a single x,y coordinate, lines as a series of x,y coordinates, and polygons as a series of x,y coordinates that
start and end on the same place. Raster format data is a cell-based representation of features on the earth
surface. Each cell has a distinct value, and all cells with the same value represent a specific feature.
Field Description
Raster (grid)
Polygon
Line
Point
Add a Layer
At the upper left-hand corner of the layers view page there are two buttons for the adding and removal of
layers. The green plus button allows you to add a new layer. The red minus button allows you to remove
selected layers.
Clicking the Add a new layer button brings up a New Layer Chooser panel. The menu displays all currently
enabled stores. From this menu, select the Store where the layer should be added.
Upon selection of a Store, a list is displayed of resources within the store. Resources which have already
been published as layers are listed first, followed by other resources which are available to be published. In
this example, giant_polygon, poi, poly_landmarks and tiger_roads are all existing layers within
the NYC store.
5.1. Data settings
57
GeoServer User Manual, Release 2.15.1
Fig. 5.19: Layers View
Fig. 5.20: Buttons to Add and Remove a Layer
Fig. 5.21: List of all currently enabled stores
58
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
Fig. 5.22: List of published and available resources in a store
To add a layer for an available resource click Publish. To add a new layer for a published resource click
Publish Again. (Note that when re-publishing the name of the new layer may have to be modified to avoid
conflict with an existing layer.) The actions display an Edit Layer page to enter the definition of the new
layer.
Remove a Layer
To remove a layer, select it by clicking the checkbox next to the layer. As shown below, multiple layers can
be selected for batch removal. Note that selections for removal will not persist from one results pages to the
next.
All layers can be selected for removal by clicking the checkbox in the header.
Once layer(s) are selected, the Remove selected resources link is activated. Once you’ve clicked the link, you
will be asked to confirm or cancel the removal. Selecting OK removes the selected layer(s).
Edit Layer: Data
To view or edit a layer, click the layer name. A layer configuration page will be displayed. The Data tab,
activated by default, allows you to define and change data parameters for a layer.
Basic Info
The beginning sections—Basic Resource Info, Keywords and Metadata link—are analogous to the Service
Metadata section for WCS, WFS, and WMS. These sections provide “data about the data,” specifically textual
information that make the layer data easier to understand and work with. The metadata information will
appear in the capabilities documents which refer to the layer.
• Name—Identifier used to reference the layer in WMS requests. (Note that for a new layer for an
already-published resource, the name must be changed to avoid conflict.)
• Title—Human-readable description to briefly identify the layer to clients (required)
• Abstract—Describes the layer in detail
• Keywords—List of short words associated with the layer to assist catalog searching
• Metadata Links—Allows linking to external documents that describe the data layer. Currently only
two standard format types are valid: TC211 and FGDC. TC211 refers to the metadata structure established by the ISO Technical Committee for Geographic Information/Geomatics (ISO/TC 211) while
5.1. Data settings
59
GeoServer User Manual, Release 2.15.1
Fig. 5.23: Some layers selected for removal
Fig. 5.24: All layers selected for removal
60
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
Fig. 5.25: Edit Layer: Data tab
FGDC refers to those set out by the Federal Geographic Data Committee (FGDC) of the United States.
Fig. 5.26: Adding a metadata link in FGDC format
Coordinate Reference Systems
A coordinate reference system (CRS) defines how georeferenced spatial data relates to real locations on the
Earth’s surface. CRSes are part of a more general model called Spatial Reference Systems (SRS), which
includes referencing by coordinates and geographic identifiers. GeoServer needs to know the Coordinate
Reference System of your data. This information is used for computing the latitude/longitude bounding
box and reprojecting the data during both WMS and WFS requests.
Fig. 5.27: Coordinate reference system of a layer
• Native SRS—Specifies the coordinate system the layer is stored in. Clicking the projection link displays a description of the SRS.
5.1. Data settings
61
GeoServer User Manual, Release 2.15.1
• Declared SRS—Specifies the coordinate system GeoServer publishes to clients
• SRS Handling—Determines how GeoServer should handle projection when the two SRSes differ.
Possible values are:
– Force declared (default): the declared SRS is forced upon the data, overwriting the native one.
This is the default option and normally the best course of action, the declared code comes from
the EPSG database and has a wealth of extra information in it, starting from a valid EPSG code,
an area of validity, a link back in the database to find the best transformation steps to other
coordinate reference systems should reprojection be required. Use this option when the source
has no native CRS, has a wrong one, or has one matching the EPSG code (in order to get full
metadata in the CRS used by GeoServer).
– Reproject from native: This setting should be used when the native data set has a CRS that is not
matching any official EPSG. OGC protocols need to advertise a EPSG code for the layers, with
this setting the declared one will be advertised, and reprojection from native will happen on the
fly as needed (in case a third CRS is requested, the reprojection will go directly from native to
declared)
– Keep native: this is a setting that should be used in very rare cases. Keeping native means using
the declared one in the capabilities documents, but then using the native CRS in all othe requests
(with no reprojection in between, unless explicitly requested from client). This is particularly
problematic if the source is a shapefile, as the PRJ files lack all the extra information provided by
the EPSG database (it will for example break WFS 1.1 and 2.0 SRS declarations in GML output).
The setting meant to be used in cases where WMS is the primary target, and the native and
declared CRSs have very small differences, avoiding on the fly reprojection and datum change.
In summary, use Force Declared as your primary option, Reproject from native only if your source data
does not match any EPSG code, and Keep Native only if you really know what you’re doing.
Bounding Boxes
The bounding box determines the extent of the data within a layer.
• Native Bounding Box—The bounds of the data specified in the Native SRS. These bounds can be
generated by clicking the Compute from data button or they can be generated from the SRS definition
by clicking the Compute from SRS bounds button. The SRS used depends on the SRS Handling chosen:
the declared SRS when Force declared or Reproject native to declared are chosen, otherwise the native SRS
is used. If the SRS does not have a bounding defined then none is generated.
• Lat/Lon Bounding Box—The bounds specified in geographic coordinates. These bounds can be calculated by clicking the Compute from native bounds button.
Fig. 5.28: Bounding Boxes of a layer
62
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
Coverage Parameters (Raster)
Optional coverage parameters are possible for certain types of raster data. For example, WorldImage formats request a valid range of grid coordinates in two dimensions known as a ReadGridGeometry2D. For
ImageMosaic, you can use InputImageThresholdValue, InputTransparentColor, and OutputTransparentColor to
control the rendering of the mosaic in terms of thresholding and transparency.
Curves support (Vector)
GeoServer can handle geometries containing circular arcs (initially only from Oracle Spatial and the “properties data store”, though more data sources are planned).
These geometries are kept in memory in their circular representation for as long as possible, are properly
visually depicted in WMS, and encoded in GML 3.x as curved.
There are two options pertaining the circular arcs:
• Linear geometries can contain circular arcs should be checked to inform the GML encoder that
the layer can contain circular arcs among other linear segments in the geometries, and thus use
“gml:Curve” in place of “gml:LineString” in GML 3.1 output format. This is required because there is
no quick way to know from the data sources if the linear geometries do contain circular arcs, and the
choice of top level GML elements influences whether it is possible, or not, to represent circular arcs in
their natural form.
• Linearization tolerance controls how accurately the linearized version of geometries matches the
original circular version of them. The tolerance can be expressed as an absolute number in the native
unit of measure of the data, or it can be expressed in meters or feet using the “m” and “ft” suffixes
(such as “10m” or “15ft”).
Fig. 5.29: Curved geometry control
Feature Type Details (Vector)
Vector layers have a list of the Feature Type Details. These include the Property and Type of a data source. For
example, the sf:archsites layer shown below includes a geometry (the_geom) of type “point”.
Fig. 5.30: Feature Type Details
The Nillable option refers to whether the property requires a value or may be flagged as being null. Meanwhile Min/Max Occurrences refers to how many values a field is allowed to have. Currently both Nillable and
Min/Max Occurrences are set to true and 0/1 but may be extended with future work on complex features.
5.1. Data settings
63
GeoServer User Manual, Release 2.15.1
Restricting features showing up in the layer
By default GeoServer will publish all the features available in the layer. It is possible to restrict the features
to a subset by specifying a CQL filter in the configuration:
Fig. 5.31: Restrict the features on layer by CQL filter
Note: It is recommended to use this setting for layers that are not meant to be edited. The filter is only
applied to reads, if a WFS-T insert adds a feature not matching the filter, it will be added to the store
anyways, but won’t show up in any of the outputs.
Edit Layer: Publishing
The Publishing tab configures HTTP and WMS/WFS/WCS settings.
Fig. 5.32: Edit Layer: Publishing tab
• Enabled—A layer that is not enabled won’t be available to any kind of request, it will just show up in
the configuration (and in REST config)
64
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
• Advertised—A layer is advertised by default. A non-advertised layer will be available in all data
access requests (for example, WMS GetMap, WMS GetFeature) but won’t appear in any capabilities
document or in the layer preview.
HTTP Settings
Cache parameters that apply to the HTTP response from client requests.
• Response Cache Headers— If selected, GeoServer will not request the same tile twice within the time
specified in Cache Time. One hour measured in seconds (3600), is the default value for Cache Time.
Services Settings
Sets services configuration on layer level.
Fig. 5.33: Services Settings
• Selectively enable services for layer—Activate/deactivate service enable/disable configuration for
the layer.
• Enabled Services—Selects enabled services list for this layer.
• Disabled Services—Selects disabled services list for this layer.
Note: It is also possible to set by-default disabled services to all layers using the org.geoserver.
service.disabled system/env/servlet context variable. This variable accepts a comma separated
list of services that should be disabled by default, in case the resource in question has no explicit
configuration.
5.1. Data settings
65
GeoServer User Manual, Release 2.15.1
WMS Settings
Sets the WMS specific publishing parameters.
Fig. 5.34: WMS Settings
• Queryable—Controls whether the layer is queryable via WMS GetFeatureInfo requests.
• Default style—Style that will be used when the client does not specify a named style in GetMap
requests.
• Additional styles—Other styles that can be associated with this layer. Some clients (and the
GeoServer Layer Preview) will present those as styling alternatives for that layer to the user.
• Default rendering buffer—Default value of the buffer GetMap/GetFeatureInfo vendor parameter.
See the WMS vendor parameters for more details.
• Default WMS path—Location of the layer in the WMS capabilities layer tree. Useful for building
non-opaque layer groups
• Default Interpolation Method—Allows to specify a default resampling (interpolation) method for
this layer. The available options are Nearest neighbor, Bilinear, Bicubic, or Use service default, which
means that no layer specific configuration will be created (the default interpolation method selected
in the WMS service configuration page will be used, see Raster Rendering Options for details). Can be
overridden by the interpolations vendor parameter.
WMS Attribution
Sets publishing information about data providers.
• Attribution Text—Human-readable text describing the data provider. This might be used as the text
for a hyperlink to the data provider’s web site.
66
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
Fig. 5.35: WMS Attribution
• Attribution Link—URL to the data provider’s website.
• Logo URL—URL to an image that serves as a logo for the data provider.
• Logo Content Type, Width, and Height—These fields provide information about the logo image that
clients may use to assist with layout. GeoServer will auto-detect these values if you click the Autodetect image size and type link at the bottom of the section. The text, link, and URL are each advertised in
the WMS Capabilities document if they are provided. Some WMS clients will display this information
to advise users which providers provide a particular dataset. If you omit some of the fields, those that
are provided will be published and those that are not will be omitted from the Capabilities document.
WFS Settings
Sets the WFS specific publishing parameters.
Fig. 5.36: WFS Settings
• Per-Request Feature Limit—Sets the maximum number of features for a layer a WFS GetFeature
operation should generate (regardless of the actual number of query hits)
• Maximum number of decimals—Sets the maximum number of decimals in GML output.
5.1. Data settings
67
GeoServer User Manual, Release 2.15.1
Note: It is also possible to override the OtherSRS/OtherCRS list configured in the WFS service,
including overriding it with an empty list if need be. The input area will accept a comma separated
list of EPSG codes:
Fig. 5.37: WFS otherSRS/otherCRS override
The list will be used only for the capabilities document generation, but will not be used to limit the
actual target SRS usage in GetFeature requests.
• Encode coordinates measures—Checking this setting will cause coordinates measures (“M”) to be
encoded in WFS output formats that support measures. The default (not checked) is to not encode
coordinates measures.
WCS Settings
• Request SRS—Provides a list of SRSs the layer can be converted to. New Request SRS allows you to
add an SRS to that list.
• Interpolation Methods—Sets the raster rendering process, if applicable.
• Formats—Lists which output formats a layers supports.
• GeoSearch—When enabled, allows the Google Geosearch crawler to index from this particular layer.
See What is a Geo Sitemap? for more information.
KML Format Settings
Limits features based on certain criteria, otherwise known as regionation.
• Default Regionating Attribute—Choose which feature should show up more prominently than others.
• Regionating Methods—There are four types of regionating methods:
– external-sorting—Creates a temporary auxiliary database within GeoServer. The first request to
build an index takes longer than subsequent requests.
– geometry—Externally sorts by length (if lines) or area (if polygons)
– native-sorting—Uses the default sorting algorithm of the backend where the data is hosted. It is
faster than external-sorting, but will only work with PostGIS datastores.
68
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
– random—Uses the existing order of the data and does not sort
Edit Layer: Dimensions
GeoServer supports adding specific dimensions to WMS layers, as specified in WMS 1.1.1 and WMS 1.3.0
standards. There are two pre-defined dimensions in the WMS standards mentioned above, TIME and
ELEVATION. Enabling dimensions for a layer allows users to specify those as extra parameters in GetMap
requests, useful for creating maps or animations from underlying multi-dimensional data.
These dimensions can be enabled and configured on the Dimensions tab.
Fig. 5.38: TIME dimension enabled for a WMS layer
For each enabled dimension the following configuration options are available:
• Attribute—Attribute name for picking the value for this dimension (vector only). This is treated at
start of the range if End attribute is also given.
• End attribute—Attribute name for picking the end of the value range for this dimension (optional,
vector only).
• Presentation—The presentation type for the available values in the capabilities document. Either each
value separately (list), interval and resolution, or continuous interval.
• Default value—Default value to use for this dimension if none is provided with the request. Select
one of from four strategies:
– smallest domain value—Uses the smallest available value from the data
– biggest domain value—Uses the biggest available value from the data
– nearest to the reference value—Selects the data value closest to the given reference value
– reference value—Tries to use the given reference value as-is, regardless of whether its actually
available in the data or not.
• Reference value—The default value specifier. Only shown for the default value strategies where its
used.
• Nearest match—Whether to enable, or not, WMS nearest match support on this dimension. Currently
supported only on the time dimension.
• Acceptable interval—A maximum search distance from the specified value (available only when
nearest match is enabled). Can be empty (no limit), a single value (symmetric search) or using a
before/after syntax to specify an asymmetric search range. Time distances should specified using
5.1. Data settings
69
GeoServer User Manual, Release 2.15.1
the ISO period syntax. For example, PT1H/PT0H allows to search up to one hour before the user
specified value, but not after.
For time dimension the value must be in ISO 8601 DateTime format yyyy-MM-ddThh:mm:ss.SSSZ For
elevation dimension, the value must be and integer of floating point number.
Only for the “Reference value” strategy, it is also possible to use ranges or times and ranges of elevation,
in the form fromValue/toValue. Only for the “Reference value” strategy, and limited to times, it’s also
possible to use relative times like P1M/PRESENT, but caution is given that the reference value is copied
verbatim into the capabilities document, and as a result, not all client might be recognizing that syntax.
Note: For more information on specifying times, please see the section on Time Support in GeoServer WMS.
5.1.5 Layer Groups
A layer group is a container in which layers and other layer groups can be organized in a hierarchical
structure. A layer group can be referred to by a single name in WMS requests. This allows simpler requests,
as one layer can be specified instead of multiple individual layers. A layer group also provides a consistent,
fixed ordering of the layers it contains, and can specify alternate (non-default) styles for layers.
Fig. 5.39: Layer Groups page
Layer Group modes
Layer group behaviour can be configured by setting its mode. There are 5 available values:
• single: the layer group is exposed as a single layer with a name, acting as an alias for a list of layers.
The layers are still showing up as top level entries in the WMS capabilities document (unless explicitly
referred by a tree group).
• opaque container: the layer group is exposed as a single layer with a name, acting as an alias for a
list of layers. However, the layers and sub-groups contained in it won’t show up in the capabilities
document (unless explicitly referred by a tree group) and won’t be available by themselves in WMS
calls and in the WMS capabilities document, but only as part of the group.
• named tree: the layer group can be referred to by one name, but also exposes its nested layers and
groups in the capabilities document.
• container tree: the layer group is exposed in the capabilities document, but does not have a name,
making it impossible to render it on its own. This is called “containing category” in the WMS specification.
70
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
• Earth Observation tree: a special type of group created to manage the WMS Earth Observation requirements. This group does not render its nested layers and groups, but only a “preview layer”
called Root Layer. When this mode is chosen, a new field “Root Layer” will be exposed in the configuration UI.
If a layer is included in any non single mode group, it will no longer be listed in the flat layer list. It will still
be possible to include the layer in other layer groups.
Layer Group Mode
Single
Opaque Container
Named Tree
Container Tree
Earth Observation Tree
Named
named
named
named
named
Contains Children
yes
yes
yes
yes
Lists Children
no
no
lists children
lists children
lists children
Details
hides children
has root layer
Edit a Layer Group
To view or edit a layer group, click the layer group name. A layer group configuration page will be displayed. The initial fields allow you to configure the name, title, abstract, workspace, bounds, projection and
mode of the layer group. To automatically set the bounding box, select the Generate Bounds button or the
Generate Bounds From CRS button to use the bounds defined in the CRS (if available). You may also provide
your own custom bounding box extents. To select an appropriate projection click the Find button.
Note: A layer group can contain layers with dissimilar bounds and projections. GeoServer automatically
reprojects all layers to the projection of the layer group.
The table at the bottom of the page lists layers and groups contained within the current layer group. We
refer to layers and layer groups as publishable elements. When a layer group is processed, the layers are
rendered in the order provided, so the publishable elements at the bottom of list will be rendered last and will
show on top of the other publishable elements.
A publishable element can be positioned higher or lower on this list by clicking the green up or down arrows,
respectively, or can be simply dragged in the target position. The layer at the top of the list is the first one
to be painted, the layer below it will be painted second, and so on, the last layer will be painted on top of
all others (this is the so called “painter’s model”).
The Style column shows the style associated with each layer. To change the style associated with a layer,
click the appropriate style link. A list of enabled styles will be displayed. Clicking on a style name reassigns
the layer’s style.
To remove a publishable element from the layer group, select its button in the Remove column. You will now
be prompted to confirm or cancel this deletion.
A layer can be added to the list by clicking the Add Layer. . . button at the top of the table. From the list of
layers, select the layer to be added by clicking the layer name. The selected layer will be appended to the
bottom of the publishable list.
A layer group can be added by clicking the Add Layer Group. . . button at the top of the table. From the list of
layer groups, select the layer group to be added by clicking its name. The selected group will be appended
to the bottom of the publishable list.
A style group can be added by clicking the Add Style Group. . . button at the top of the table. From the list
of styles, select the style group to be added by clicking its name. The selected style will be appended to the
bottom of the publishable list.
You can view layer groups in the Layer Preview section of the web admin.
5.1. Data settings
71
GeoServer User Manual, Release 2.15.1
Fig. 5.40: Layer Groups Edit page
72
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
Fig. 5.41: Style editing for a layer within a layer group
Fig. 5.42: Dialog for adding a layer to a layer group
Fig. 5.43: Dialog for adding a layer group to a layer group
Fig. 5.44: Dialog for adding a style group to a layer group
5.1. Data settings
73
GeoServer User Manual, Release 2.15.1
Fig. 5.45: Openlayers preview of the layer group “tasmania”
Note: By default, a layer group is queryable when at least a child layer is queryable. Uncheck “Queryable”
box if you want to explicitly indicate that it is not queryable independently of how the child layers are
configured.
Add a Layer Group
The buttons for adding and removing a layer group can be found at the top of the Layer Groups page.
Fig. 5.46: Buttons to add or remove a layer group
To add a new layer group, select the “Add a new layer group” button. You will be prompted to name the
layer group.
When finished, click Submit. You will be redirected to an empty layer group configuration page. Begin by
adding layers by clicking the Add layer. . . button (described in the previous section). Once the layers are
positioned accordingly, press Generate Bounds to automatically generate the bounding box and projection.
You may also press the Generate Bounds From CRS button to use the CRS bounds (if available). Press Save to
save the new layer group.
74
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
Fig. 5.47: New layer group dialog
Fig. 5.48: New layer group configuration page
5.1. Data settings
75
GeoServer User Manual, Release 2.15.1
Remove a Layer Group
To remove a layer group, select it by clicking the checkbox next to the layer group. Multiple layer groups
can be selected, or all can be selected by clicking the checkbox in the header. Click the Remove selected layer
group(s) link. You will be asked to confirm or cancel the deletion. Selecting OK removes the selected layer
group(s).
Fig. 5.49: Removing a layer group
Layer Group Keywords
Is possible to associate a layer group with some keywords that will be used to assist catalog searching.
Fig. 5.50: Layer groups keywords editor
Layer groups keywords will no be merged with contained layers keywords but keywords of a layer group
should be logically inherited by contained layers.
Note: Information on the Styles pages can be found on the Styles page.
76
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
5.2 Vector data
This section discusses the vector data sources that GeoServer can access.
The standard GeoServer installation supports the loading and serving of the following data formats:
5.2.1 Shapefile
A shapefile is a popular geospatial vector data format.
Note: While GeoServer has robust support for the shapefile format, it is not the recommended format
of choice in a production environment. Databases such as PostGIS are more suitable in production and
offer better performance and scalability. See the section on Running in a production environment for more
information.
Adding a shapefile
A shapefile is actually a collection of files (with the extensions: .shp, .dbf, .shx, .prj, and sometimes
others). All of these files need to be present in the same directory in order for GeoServer to accurately read
them. As with all formats, adding a shapefile to GeoServer involves adding a new store to the existing
Stores through the Web administration interface.
Warning: The .prj file, while not mandatory, is strongly recommended when working with GeoServer
as it contains valuable projection info. GeoServer may not be able to load your shapefile without it!
To begin, navigate to Stores → Add a new store → Shapefile.
Option
Workspace
Data Source Name
Description
Enabled
URL
namespace
create spatial index
charset
memory
mapped
buffer Cache and
reuse memory maps
Description
Name of the workspace to contain the store. This will also be the prefix of the layer
created from the store.
Name of the shapefile as known to GeoServer. Can be different from the filename.
The combination of the workspace name and this name will be the full layer name
(ex: topp:states).
Description of the shapefile/store.
Enables the store. If unchecked, no data in the shapefile will be served.
Location of the shapefile.
Can be an absolute path (such as
file:C:\Data\shapefile.shp) or a path relative to the data directory
(such as file:data/shapefile.shp.
Namespace to be associated with the shapefile. This field is altered by changing
the workspace name.
Enables the automatic creation of a spatial index.
Character set used to decode strings from the .dbf file.
Enables the use of memory mapped I/O, improving caching of the file in memory.
Turn off on Windows servers.
When finished, click Save.
5.2. Vector data
77
GeoServer User Manual, Release 2.15.1
Fig. 5.51: Adding a shapefile as a store
78
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
Configuring a shapefile layer
Shapefiles contain exactly one layer, which needs to be added as a new layer before it will be able to be
served by GeoServer. See the section on Layers for how to add and edit a new layer.
5.2.2 Directory of spatial files
The directory store automates the process of loading multiple shapefiles into GeoServer. Loading a directory that contains multiple shapefiles will automatically add each shapefile to GeoServer.
Note: While GeoServer has robust support for the shapefile format, it is not the recommended format
of choice in a production environment. Databases such as PostGIS are more suitable in production and
offer better performance and scalability. See the section on Running in a production environment for more
information.
Adding a directory
To begin, navigate to Stores → Add a new store → Directory of spatial files.
Fig. 5.52: Adding a directory of spatial files as a store
5.2. Vector data
79
GeoServer User Manual, Release 2.15.1
Option
Workspace
Data Source Name
Description
Enabled
URL
namespace
Description
Name of the workspace to contain the store. This will also be the prefix of all of the
layer names created from shapefiles in the store.
Name of the store as known to GeoServer.
Description of the directory store.
Enables the store. If disabled, no data in any of the shapefiles will be served.
Location of the directory.
Can be an absolute path (such as
file:C:\Data\shapefile_directory) or a path relative to the data directory (such as file:data/shapefile_directory.
Namespace to be associated with the store. This field is altered by changing the
workspace name.
When finished, click Save.
Configuring shapefiles
All of the shapefiles contained in the directory store will be loaded as part of the directory store, but they
will need to be individually configured as new layers they can be served by GeoServer. See the section on
Layers for how to add and edit new layers.
5.2.3 Java Properties
The Properties data store provides access to one or more feature types (layers) stored in Java property
files; these are plain text files stored on the local filesystem. The Properties data store was never intended
to be shipped with GeoServer. It originated in a GeoTools tutorial, and later found widespread use by
developers in automated tests that required a convenient store for small snippets of data. It slipped into
GeoServer through the completeness of the packaging process, and was automatically detected and offered
to users via the web interface. The Property data store has proved useful in tutorials and examples.
• We do not recommend the use the Properties data store for large amounts of data, with either many
features or large geometries. Its performance will be terrible.
• For small data sets, such as collections of a few dozen points, you may find it to be satisfactory. For
example, if you have a few points you wish to add as an extra layer, and no convenient database in
which store them, the Properties data store provides a straightforward means of delivering them.
• Changes to a property file are immediately reflected in GeoServer responses. There is no need to
recreate the data store unless the first line of a property file is changed, or property files are added or
removed.
Adding a Properties data store
By default, Properties will be an option in the Vector Data Sources list when creating a new data store.
Fig. 5.53: Properties in the list of vector data stores
80
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
Configuring a Properties data store
Fig. 5.54: Configuring a Properties data store
Option
Workspace
Data Source
Name
Description
Enabled
directory
Description
Sets the namespace prefix of the feature types (layers) and their properties
Unique identifier to distinguish this data store
Optional text giving a verbose description of the data store
Features will be delivered only if this option is checked
Filesystem path to a directory containing one or more property files, for example
/usr/local/geoserver/data/ex
Every property file TYPENAME.properties in the designated directory is served as a feature type
TYPENAME (the name of the file without the .properties), in the namespace of the data store.
Before a feature type (layer) can be used, you must edit it to ensure that its bounding box and other metadata
is configured.
Property file format
The property file format is a subset of the Java properties format: a list of lines of the form KEY=VALUE.
This example stations.properties defines four features of the feature type (layer) stations:
_=id:Integer,code:String,name:String,location:Geometry:srid=4326
stations.27=27|ALIC|Alice Springs|POINT(133.8855 -23.6701)
stations.4=4|NORF|Norfolk Island|POINT(167.9388 -29.0434)
stations.12=12|COCO|Cocos|POINT(96.8339 -12.1883)
stations.31=31|ALBY|Albany|POINT(117.8102 -34.9502)
5.2. Vector data
81
GeoServer User Manual, Release 2.15.1
• Blank lines are not permitted anywhere in the file.
• The first line of the property file begins with _= and defines the type information required to interpret
the following lines.
– Comma separated values are of the form NAME:TYPE
– Names are the property name that are used to encode the property in WFS responses.
– Types include Integer, String, Float, and Geometry
– Geometry can have an extra suffix :srid=XXXX that defines the Spatial Reference System by its
numeric EPSG code. Note that geometries defined in this way are in longitude/latitude order.
• Subsequent lines define features, one per line.
– The key before the = is the feature ID (fid or gml:id in WFS responses). Each must be an
NCName.
– Feature data follows the = separated by vertical bars (|). The types of the data must match the
declaration on the first line.
– Leave a field empty if you want it to be null; in this case the property will be ignored.
Note that in this example srid=4326 sets the spatial reference system (SRS) to EPSG:4326, which is
by convention in longitude/latitude order when referred to in the short form. If you request these features in GML 3 you will see that GeoServer correctly translates the geometry to the URN form SRS
urn:x-ogc:def:crs:EPSG:4326 in latitude/longitude form. See the WFS settings page for more on
SRS axis order options.
5.2.4 GeoPackage
GeoPackage is an SQLite based standard format that is able to hold multiple vector and raster data layers
in a single file.
GeoPackage files can be used both as Raster Data Stores as well as Vector Data Stores (so that both kinds of
layers can published).
Adding a GeoPackage Vector Data Store
When the extension has been installed, GeoPackage will be an option in the Vector Data Sources list when
creating a new data store.
Fig. 5.55: GeoPackage in the list of vector data stores
82
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
Fig. 5.56: Configuring a GeoPackage Vector data store
5.2. Vector data
83
GeoServer User Manual, Release 2.15.1
Option
database
user
passwd
namespace
max connections
min connections
fetch size
Connection timeout
validate connections
Description
URI specifying geopackage file.
User to access database.
Password to access database.
Namespace to be associated with the database. This field is altered by changing the
workspace name.
Maximum amount of open connections to the database.
Minimum number of pooled connections.
Number of records read with each interaction with the database.
Time (in seconds) the connection pool will wait before timing out.
Checks the connection is alive before using it.
When finished, click Save.
Other data sources are supplied as GeoServer extensions. Extensions are downloadable modules that add
functionality to GeoServer. Extensions are available at the GeoServer download page.
Warning: The extension version must match the version of the GeoServer instance.
5.2.5 GML
Note: GeoServer does not come built-in with support for GML; it must be installed through an extension.
Proceed to Installing the GML extension for installation details.
Warning: Currently the GML extension is unmaintained and carries unsupported status. While still
usable, do not expect the same reliability as with other extension.
Geographic Markup Language (GML) is a XML based format for representing vector based spatial data.
Supported versions
Currently GML version 2 is supported.
Installing the GML extension
1. Download the GML extension from the GeoServer download page.
Warning: Make sure to match the version of the extension to the version of the GeoServer instance!
2. Extract the contents of the archive into the WEB-INF/lib directory of the GeoServer installation.
84
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
Adding a GML data store
Once the extension is properly installed GML will be an option in the Vector Data Sources list when creating
a new data store.
Fig. 5.57: GML in the list of vector data stores
Configuring a GML data store
Fig. 5.58: Configuring a GML data store
5.2.6 Pregeneralized Features
Note: GeoServer does not come built-in with support for Pregeneralized Features; it must be installed
through an extension.
Installing the Pregeneralized Features extension
1. Download the Pregeneralized Features extension from the GeoServer download page.
Warning: Make sure to match the version of the extension to the version of the GeoServer instance!
5.2. Vector data
85
GeoServer User Manual, Release 2.15.1
2. Extract the contents of the archive into the WEB-INF/lib directory of the GeoServer installation.
Adding a Pregeneralized Features data store
If the extension is properly installed, Generalized Data Store will be listed as an option when creating a new
data store.
Fig. 5.59: Generalized Data Store in the list of vector data stores
Configuring a Pregeneralized Features data store
Fig. 5.60: Configuring a Pregeneralized Features data store
For a detailed description, look at the Tutorial
5.3 Raster data
This section discusses the raster (coverage) data sources that GeoServer can access.
The standard GeoServer installation supports the loading and serving of the following data formats:
86
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
5.3.1 GeoTIFF
A GeoTIFF is a georeferenced TIFF (Tagged Image File Format) file.
Adding a GeoTIFF data store
By default, GeoTIFF will be an option in the Raster Data Sources list when creating a new data store.
Fig. 5.61: GeoTIFF in the list of raster data stores
Configuring a GeoTIFF data store
Fig. 5.62: Configuring a GeoTIFF data store
Option
Workspace
Data Source
Name
Description
Enabled
URL
5.3. Raster data
Description
Name of the workspace to contain the GeoTIFF store. This will also be the prefix of
the raster layer created from the store.
Name of the GeoTIFF as it will be known to GeoServer. This can be different from
the filename. The combination of the workspace name and this name will be the
full layer name (ex: world:landbase)
A full free-form description of the GeoTIFF store.
If checked, it enables the store. If unchecked (disabled), no data in the GeoTIFF will
be served from GeoServer.
Location of the GeoTIFF file.
This can be an absolute path (such as
file:C:\Data\landbase.tif) or a path relative to GeoServer’s data directory
(such as file:data/landbase.tif).
87
GeoServer User Manual, Release 2.15.1
Note: Notice that the GeoTiff plugin is able to handle internal/external overviews and internal/external
masks.
Custom CRS definition
Creating an auxiliary .prj file that contains coordinate reference system information as described in the
Custom CRS Definitions chapter will override internal CRS tags that are included in the original GeoTIFF
file. This can be used to work-around problematic source files without making modifications to the file.
5.3.2 GTOPO30
GTOPO30 is a Digital Elevation Model (DEM) dataset with a horizontal grid spacing of 30 arc seconds.
Note: An example of a GTOPO30 can be found at http://edc.usgs.gov/products/elevation/gtopo30/
gtopo30.html
Adding a GTOPO30 data store
By default, GTOPO30 will be an option in the Raster Data Sources list when creating a new data store.
Fig. 5.63: GTOPO30 in the list of raster data stores
Configuring a GTOPO30 data store
Option
Workspace
Data Source
Name
Description
Enabled
URL
Description
5.3.3 WorldImage
A world file is a plain text file used to georeference raster map images. This file (often with an extension
of .jgw or .tfw) accompanies an associated image file (.jpg or .tif). Together, the world file and the
corresponding image file is known as a WorldImage in GeoServer.
88
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
Fig. 5.64: Configuring a GTOPO30 data store
Adding a WorldImage data store
By default, WorldImage will be an option in the Raster Data Sources list when creating a new data store.
Fig. 5.65: WorldImage in the list of raster data stores
Configuring a WorldImage data store
Option
Workspace
Data Source
Name
Description
Enabled
URL
Description
5.3.4 ImageMosaic
The ImageMosaic data store allows the creation of a mosaic from a number of georeferenced rasters.
The mosaic operation creates a mosaic from two or more source images. This operation could be used to
assemble a set of overlapping geospatially rectified images into a contiguous image. It could also be used
to create a montage of photographs such as a panorama.
5.3. Raster data
89
GeoServer User Manual, Release 2.15.1
Fig. 5.66: Configuring a WorldImage data store
The plugin can be used with GeoTIFFs, as well as rasters accompanied by a world file (.wld, .pgw for PNG
files, .jgw for JPG files, etc.). In addition, if imageIO-ext GDAL extension is properly installed, the plugin
can also serve all the formats supported by it such as MrSID, ECW, JPEG2000. It also supports NetCDF and
GRIB.
ImageMosaic configuration
Granules
Each individual image is commonly referred to as a granule. In recent releases of GeoServer the similarities
requirements for the granules have been dropped significantly, including:
• The granules do not need to share the same coordinate reference system (see the multi-CRS mosaic
tutorial)
• The granules can be in different color models, with an allowance of mixing gray, RGB, RGBA and
indexed color granules (it is however not possible to mix colored granules with scientific data types
like as float/double). In order to benefit of mixed color models JAI-Ext support must be enabled, see
the JAI-EXT support documentation.
In addition it is worth remarking on the fact that currently the ImageMosaic is able to handle raster data
whose grid-to-world transformation is a scale and translate transformation, hence no rotation or skew.
Index and configuration file creation
When a new store is created, an index shapefile will be generated to associate each granule file with its
bounding box. The index creation respects directory trees as well as single directories. All you need to
90
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
do is point the store to the root of the hierarchy, and all images will be considered for inclusion in the
ImageMosaic.
The index will contain the enclosing polygon for each raster file (in an appropriate coordinate reference
system) and the path to each of these files. The location attribute can be relative to the configuration folder
or absolute. By default, the name of this attribute is location, but this can be changed in the main configuration file.
If you already have these files generated, GeoServer will respect them and not generate a new index. By
default, a shapefile is used for the index, but PostGIS, H2, and Oracle are also supported, with additional
configuration steps.
Configuration files
Within each store there are multiple configuration files that determine how the mosaic is rendered.
Primary configuration file
The mosaic configuration file is the primary file used to store the configuration parameters that control
the ImageMosaic plugin. When created by GeoServer it is by default called .properties,
where is the name of the root directory of the store. (It is not related to the store name in
GeoServer.) It can have other names, as long as it does not conflict with other files such as datastore.
properties or indexer.properties. This file usually does not require manual editing.
The table below describes the various elements in this configuration file.
5.3. Raster data
91
GeoServer User Manual, Release 2.15.1
Parameter
Mandatory?
Description
Levels
Y
Represents the resolutions for the various levels of the granules of this mosaic.
Heterogeneous N
Sets whether the image files are heterogeneous. Default is false.
AbsolutePath N
Controls whether or not the path stored inside the location attribute represents
an absolute path or a path relative to the location of the shapefile index. Notice that
a relative index ensures much more portability of the mosaic itself. Default value
for this parameter is false, which means relative paths.
Name
N
The name to be assigned to the index. If unspecified, the index name will usually
match the name of the folder containing the mosaic.
TypeName
Y
Featuretype name for this mosaic. Usually the name as Name.
Caching
N
Boolean value to enable caching. When set to true, the ImageMosaic will try to
save in memory the entire contents of the index to reduce loading/query time. Set
to false for a large granule index and/or if new granules are to be ingested (for
example, when the index is on a database and we interact directly with it). Default
is false.
ExpandToRGB N
Boolean flag to force color expansion from index color model (paletted datasets) to
component color model (RGB). Default is false.
LocationAttributeY
The name of the attribute path in the shapefile index. Default is location.
SuggestedSPI Y
Suggested plugin for reading the image files.
Envelope2D
N
Envelope for the mosaic formatted as LLX,LLY URX,URY (notice the space between the lower left and upper right coordinate pairs).
CheckAuxiliaryMetadata
N
This parameter allows to specify whether the ImageMosaic plugin should check
for the presence of a GDAL aux.xml file beside each granule file. For most common use cases, you don’t need to set or specify this parameter. Being disabled by
Default, ImageMosaic won’t look for an ancillary file for each granule being initialized in the GranuleCatalog. This avoid useless checks, especially when dealing
with thousand of granules. You should set that parameter to true when you want
to instruct the ImageMosaic to look for a GDAL generated aux.xml file containing PAM (Persistent Auxiliary Metadata) for each granule, to be attached to the
Granule info (GranuleDescriptor). This is specially useful when you have setup
a Dynamic ColorMap rendering transformation which dynamically set a color map
based on the statistics collected into the granule’s GDAL PAM being previously
generated with a gdalinfo -stats parameter.
LevelsNum
Y
Represents the number of reduced resolution layers that we currently have for the
granules of this mosaic.
A sample configuration file follows:
Levels=0.4,0.4
Heterogeneous=false
AbsolutePath=false
Name=osm
TypeName=osm
Caching=false
ExpandToRGB=false
LocationAttribute=location
SuggestedSPI=it.geosolutions.imageioimpl.plugins.tiff.TIFFImageReaderSpi
CheckAuxiliaryMetadata=false
LevelsNum=1
92
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
datastore.properties
By default the ImageMosaic index is specified by a shapefile, which is located at the root of the ImageMosaic
directory, just like the primary configuration file.
If needed, different storage can be used for the index — like a spatial DBMS, which is the preferred solution
when you wish to share the ImageMosaic itself in a cluster of GeoServer instances. In this case the user must
supply GeoServer with the proper connection parameters, which can be specified by using a datastore.
properties file placed at the root of the ImageMosaic directory.
Note: A shapefile is created automagically if it does not exist or if there is no datastore.properties
file.
Warning: At the time of writing the following spatial DBMS have been tested successfully: Oracle,
PostgreSQL, H2. SQl Server is not yet supported.
Parameter
StoreName
SPI
Connection
parameters
Mandatory?
Description
N
Can be used to refer to a GeoServer registered store, using a
“workspace:storeName” syntax. When this is used, the no other connection
parameters need to be provided. The SPI can still be provided to inform the mosaic
of the resulting type of store (e.g., Oracle) in case specific behavior need to be
enacted for it (e.g., in the case of Oracle the attributes are all uppercase and cannot
be longer than 30 chars, the mosaic will respect the limits but the SPI parameter
needs to be explicitly set to org.geotools.data.oracle.OracleNGDataStoreFactory as the
actual store type is hidden when it reaches the mosaic code). Also, as a reminder,
the code is picking up a Store reference, not a layer one, meaning that security
restrictions that might have been applied to a layer exposing the feature type do
not apply to the mosaic code (e.g., if a user has restrictions such as a spatial filter
on said layer, it won’t transfer to the mosaic, which needs to be secured separately)
Y
The DataStoreFactory used to connect to the index store:
• PostGIS: org.geotools.data.postgis.PostgisNGDataStoreFactory
• Oracle: org.geotools.data.oracle.OracleNGDataStoreFactory
• H2: org.geotools.data.h2.H2DataStoreFactory
JNDI can also be used with any of these stores. If JNDI is used, the DataStoreFactory name will differ from the above.
Y
The connection parameters used by the specified SPI. The list of these connection
parameters can be found in the GeoTools documentation on the relevant store:
• PostGIS
• Oracle
• H2
If JNDI is used, the connection parameters will include jndiReferenceName instead of host, port, etc. Note that for any connection parameters that include a
space (such as loose bbox), the space must be escaped by preceding it with a
backslash (loose\ bbox).
Here is a sample datastore.properties file for a PostGIS index:
SPI=org.geotools.data.postgis.PostgisNGDataStoreFactory
host=localhost
port=5432
5.3. Raster data
93
GeoServer User Manual, Release 2.15.1
database=osm
schema=public
user=user
passwd=password
Loose\ bbox=true
Estimated\ extends=false
validate\ connections=true
Connection\ timeout=10
preparedStatements=true
Here is a sample datastore.properties file for a PostGIS index via JNDI:
SPI=org.geotools.data.postgis.PostgisNGJNDIDataStoreFactory
#String
# JNDI data source
# Default "java:comp/env/"+"jdbc/mydatabase"
jndiReferenceName=
#Boolean
# perform only primary filter on bbox
# Default Boolean.TRUE
Loose\ bbox=true
#Boolean
# use prepared statements
#Default Boolean.FALSE
preparedStatements=false
indexer.properties
In addition to the required envelope and location attributes, the schema for the index store may expose
other custom attributes which can be used later for filtering the ImageMosaic granules on the fly during a
WMS or WCS request or to diver WMS and WCS dimensions like TIME, ELEVATION and so on. This is
configured by the indexer.properties file:
94
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
Parameter
Schema
Mandatory?
Description
Y
A comma-separated sequence describing the mapping between attribute and data
type.
PropertyCollectors
Y
A comma-separated list of PropertyCollectors. Each entry in the list includes the
extractor class, the file name (within square brackets [ ] and not including the
.properties suffix) containing the regular expression needed to extract the attribute value from the granule file name, and the attribute name (within parentheses ( )). The instance of the extractor class also indicates the type of object computed by the specific collector, so a TimestampFileNameExtractorSPI will return Timestamps while a DoubleFileNameExtractorSPI will return Double
numbers.
TimeAttribute N
Specifies the name of the time-variant attribute.
ElevationAttribute
N
Specifies the name of the elevation attribute.
AuxiliaryFile
N
Path to an auxiliary file to be used for internal purposes (For example: when dealing with NetCDF granules, it refers to the NetCDF XML ancillary file.)
AbsolutePath N
Controls whether or not the path stored inside the location attribute represents
an absolute path or a path relative to the location of the shapefile index. Notice that
a relative index ensures better portability of the mosaic itself. Default value for this
parameter is false, which means relative paths.
Caching
N
Boolean value to enable caching. When set to true, the ImageMosaic will try to
save in memory the entire contents of the index to reduce loading/query time. Set
to false for a large granule index and/or if new granules are to be ingested (for
example, when the index is on a database and we interact directly with it). Default
is false.
CanBeEmpty N
Boolean flag used for configuring empty mosaics. When enabled the ImageMosaic
will not throw an exception caused by the absence of any coverage. By default it is
set to false.
Envelope2D
N
Envelope for the mosaic formatted as LLX,LLY URX,URY (notice the space between the lower left and upper right coordinate pairs).
ExpandToRGB N
Boolean flag to force color expansion from index color model (paletted datasets) to
component color model (RGB). Default is false.
IndexingDirectories
N
Comma separated values list of paths referring to directories containing granules
to be indexed. If unspecified, the IndexingDirectory will be the mosaic configuration directory. This parameter allows configuration of a mosaic in a folder which
contains only configuration files, while the granules to be indexed are stored somewhere else.
Name
N
The name to be assigned to the index. If unspecified, the index name will usually
match the name of the folder containing the mosaic.
CoverageNameCollectorSPI
N
As described in the previous row, the Name parameter allows specification of the
coverage name to be exposed by the ImageMosaic. An ImageMosaic of NetCDFs
instead exposes a coverage for each supported variable found in the NetCDF,
using the variable’s name as the coverage name (for instance, air_temperature,
wind_speed, etc.) The optional CoverageNameCollectorSPI property allows specification of a CoverageNameCollector plugin to be used to instruct the ImageMosaic
on how to setup different coverageNames for granules. It should contains the full
name of the implementing class plus an optional set of semicolon-separated keyValue pairs prefixed by “:”. See below for an example.
Recursive
N
Boolean flag used at indexing time. When set to true, the indexer will look for
granules by scanning any subdirectory contained in the indexing directory. If
false, only the main folder will be analyzed. Default is true.
UseExistingSchema
N
Boolean flag used for enabling/disabling the use of existing schemas. When enabled, the ImageMosaic will start indexing granules using the existing database
schema (from datastore.properties) instead of populating it. This is useful
when you already have a database with a valid mosaic schema (the_geom, location
and other attributes, take a look at gdalindex) or when you do not want to rename
5.3. Raster data
the images to add times and dimensions (you should simply add them to the table,95
to AdditionalDomainAttributes and to PropertyCollectors). Default is false.
Wildcard
N
Wildcard used to specify which files should be scanned by the indexer. (For instance: “.”)
GeoServer User Manual, Release 2.15.1
Here is a sample indexer.properties file:
Schema=*the_geom:Polygon,location:String,ingestion:java.util.Date,elevation:Double
PropertyCollectors=TimestampFileNameExtractorSPI[timeregex](ingestion),
,→DoubleFileNameExtractorSPI[elevationregex](elevation)
TimeAttribute=ingestion
ElevationAttribute=elevation
Caching=false
AbsolutePath=false
An example of optional CoverageNameCollectorSPI could be:
CoverageNameCollectorSPI=org.geotools.gce.imagemosaic.namecollector.
,→FileNameRegexNameCollectorSPI:regex=^([a-zA-Z0-9]+)
This defines a regex-based name collector which extracts the coverage name from the prefix of the file
name, so that an ImageMosaic with temperature_2015.tif, temperature_2016.tif, pressure_2015.tif, pressure_2016.tif will put temperature* granules on a temperature coverage and pressure* granules on a
pressure coverage.
Property collectors
The following table enumerates the available property collectors
Collector
SPI Description
name
ByteFileNameExtractorSPI
Extracts an number from the file name using a regular expression specified in a
DoubleFileNamesidecar file, casting it to the desired type based on the SPI name (e..g, DoubleFileExtractorSPI
NameExtractorSPI extracts double precision floating points, IntegerFileNameExFloatFileNametractorSPI extracts 32 bit integers)
ExtractorSPI
IntegerFileNameExtractorSPI
LongFileNameExtractorSPI
ShortFileNameExtractorSPI
TimestampFileNameExtractorSPI
Extracts a timestamp from the filename using a regular expression specified in a
sidecar file
StringFileNameExtractorSPI
Extracts a string from the filename using a regular expression specified in a sidecar
file
CurrentDateExtractorSPI
Returns the current date and time (useful to track ingestion times in a mosaic)
FSDateExtractorSPI Returns the creation date of the file being harvested
DateExtractorSPI
Returns the date found in tiff file header “DateTime” (code 306)
ResolutionExtractorSPI
Returns the native resolution of the raster being harvested. ResolutionExtractorSPI
ResolutionXExand ResolutionXExtractorSPI return the x resolution of the raster, ResolutionYExtractorSPI Resolu- tractorSPI returns the resolution on the Y axis instead
tionYExtractorSPI
CRSExtractorSPI
Returns the code of the the raster coordinate reference system, as a string, e.g.
“EPSG:4326”
The PropertyCollectors parameter in the example above indicates two additional .properties files
used to populate the ingestion and elevation attributes:
96
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
timeregex.properties:
regex=[0-9]{8}T[0-9]{9}Z(\?!.\*[0-9]{8}T[0-9]{9}Z.\*)
The above is a property file containing a regex used to extract Date and Time represented in ISO-8601 as
part of the filename. (Note the T char between digits for date and digits for time, as per ISO-8601)
In case of custom format datetimes in filename, an additional format element should be added after the
regex, preceded by a comma, defining the custom representation.
Example:
Temperature_2017111319.tif
an hourly Temperature file with datetime = November, 13 2017 at 7:00 PM (the last 2 digits = 19)
In that case, the timeregex.properties file should be like this:
regex=.*([0-9]{10}).*,format=yyyyMMddHH
elevationregex.properties:
regex=(?<=_)(\\d{4}\\.\\d{3})(?=_)
Store parameters
By default, ImageMosaic will be an option in the Raster Data Sources list when creating a new data store.
Fig. 5.67: ImageMosaic in the list of raster data stores
Option
Workspace
Data
Source
Name
Description
Enabled
URL
Description
Workspace for the store
Name of the store
Description of the store
Determines whether the store is enabled. If unchecked, all layers in the store will
be disabled.
The location of the store. Can be a local directory.
Coverage parameters
Creation of the store is the first step to getting an ImageMosaic published in GeoServer. Most of the configuration is done when publishing the resulting coverage (layer).
The Coverage Editor gives users the possibility to set a few control parameters to further control the mosaic
creation process.
The parameters are as follows:
5.3. Raster data
97
GeoServer User Manual, Release 2.15.1
Fig. 5.68: Configuring an ImageMosaic data store
Fig. 5.69: Coverage parameters
98
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
Parameter
Accurate
resolution
computation
AllowMultithreading
BackgroundValues
Filter
Description
Boolean value. If true, computes the resolution of the granules in 9 points:
the corners of the requested area and the middle points, taking the better one.
This will provide better results for cases where there is a lot more deformation on a subregion (top/bottom/sides) of the requested bounding box with
respect to others. If false, computes the resolution using a basic affine scale
transform.
If true, enables multithreaded tile loading. This allows performing parallelized loading of the granules that compose the mosaic. Setting this to true
makes sense only if you set USE_JAI_IMAGEREAD to false at the same
time to force immediate loading of data into memory.
Sets the value of the mosaic background. Depending on the nature of the
mosaic it is wise to set a value for the “nodata” area (usually -9999). This
value is repeated on all the mosaic bands.
Sets the default mosaic filter. It should be a valid ECQL query to be used
by default if no cql_filter is specified (instead of Filter.INCLUDE). This
filter will be applied against the mosaic index, and may include any attributes
exposed by the index store. If the cql_filter is specified in the request it
will be overridden.
Note: Do not use this filter to change time or elevation dimensions defaults.
It will be added as AND condition with CURRENT for “time” and LOWER
for “elevation”.
FootprintBehavior
InputTransparentColor
MaxAllowedTiles
MergeBehavior
OutputTransparentColor
5.3. Raster data
Sets the behavior of the regions of a granule that are outside of the granule footprint. Can be None (ignore the footprint), Cut (remove regions
outside the footprint from the image and don’t add an alpha channel), or
Transparent (make regions outside the footprint completely transparent,
and add an alpha channel if one is not already present). Defaults to None.
Sets the transparent color of the granules prior to processing by the ImageMosaic plugin, in order to control how they are superimposed. When
GeoServer composes the granules to satisfy a user request, some can
overlap others; setting this parameter with an appropriate color avoids
the overlap of “nodata” areas between granules. See below for an example:
Fig. 5.70: InputTransparentColor parameter not configured
Sets the maximum number of tiles that can be loaded simultaneously for a
request. For large mosaics, this parameter should be set to avoid saturating
the server by loading too many granules simultaneously.
The method used to handle overlapping granules during the mosaic operation. Can be FLAT (only the topmost granule is visible in the case of an overlap) or STACK (a band-stacking merge is applied to the overlapping granules).
Default is FLAT.
Set the transparent color for the mosaic.
This parameter make sense for RGB or paletted mosaics,
but not99
for a DEM or MetOc data.
See below for an example:
Fig. 5.7
GeoServer User Manual, Release 2.15.1
Continue on with the ImageMosaic tutorial to learn more and see examples.
Using the ImageMosaic extension
This tutorial will show you how to configure and publish an ImageMosaic store and coverage, followed by
some configuration examples.
Configuring a coverage in GeoServer
This is a process very similar to creating a featuretype. More specifically, one has to perform the steps
highlighted in the sections below:
Create a new store
1. Go to Data Panel → Stores and click Add new Store.
2. Select ImageMosaic under Raster Data Source:
Fig. 5.74: ImageMosaic in the list of raster data stores
3. In order to create a new mosaic it is necessary to choose a workspace and store name in the Basic Store
Info section, as well as a URL in the Connection Parameters section. Valid URLs include:
• The absolute path to the shapefile index, or a directory containing the shapefile index.
• The absolute path to the configuration file (*.properties‘) or a directory containing the configuration file. If datastore.properties and indexer.properties exist, they should be in the
same directory as this configuration file.
• The absolute path of a directory where the files you want to mosaic reside. In this case GeoServer
automatically creates the needed mosaic files (.dbf, .prj, .properties, .shp and .shx) by inspecting
the data present in the given directory and any subdirectories.
4. Click Save:
Create a new coverage
1. Navigate to Data Panel → Layers and click Add a new resource.
2. Choose the name of the store you just created:
3. Click the layer you wish to configure and you will be presented with the Coverage Editor:
4. Make sure there is a value for Native SRS, then click the Submit button. If the Native CRS is UNKNOWN,
you must declare the SRS in the Declared SRS field.
5. Click Save.
6. Use the Layer Preview to view the mosaic.
100
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
Fig. 5.75: Configuring an ImageMosaic data store
Fig. 5.76: Layer Chooser
5.3. Raster data
101
GeoServer User Manual, Release 2.15.1
Fig. 5.77: Coverage Editor
102
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
Warning: If the created layer appears to be all black, it may be that GeoServer has not found any
acceptable granules in the provided index. It is also possible that the shapefile index is empty (no
granules were found in the provided directory) or it might be that the granules’ paths in the shapefile
index are not correct, which could happen if an existing index (using absolute paths) is moved to another
place. If the shapefile index paths are not correct, then the DBF file can be opened and fixed with an
editor. Alternately, you can delete the index and let GeoServer recreate it from the root directory.
Configuration examples
Below are a few examples of mosaic configurations to demonstrate how we can make use of the ImageMosaic parameters.
DEM/Bathymetry
Such a mosaic can be used to serve large amounts of data representing altitude or depth and therefore does
not specify colors directly (it needs an SLD to generate pictures). In our case, we have a DEM dataset which
consists of a set of raw GeoTIFF files.
The first operation is to create the CoverageStore specifying, for example, the path of the shapefile in the
URL field.
Inside the Coverage Editor Publishing tab, you can specify the dem default style in order to represent the
visualization style of the mosaic. The following is an example style:
gtopodemSimple DEM styleClassic elevation color progression1.0
5.3. Raster data
103
GeoServer User Manual, Release 2.15.1
In this way you have a clear distinction between the different intervals of the dataset that compose the
mosaic, like the background and the “nodata” area.
Note: The “nodata” on the sample mosaic is -9999. The default background value is for mosaics is 0.0.
The result is the following:
By setting the other configuration parameters appropriately, it is possible to improve both the appearance
of the mosaic as well as its performance. For instance, we could:
• Make the “nodata” areas transparent and coherent with the real data. To achieve this we need
to change the opacity of the “nodata” ColorMapEntry in the dem style to 0.0 and set the
BackgroundValues parameter to -9999 so that empty areas will be filled with this value. The
result is as follows:
• Allow multithreaded granules loading. By setting the AllowMultiThreading parameter to true,
GeoServer will load the granules in parallel using multiple threads with a increase in performance on
some architectures.
The configuration parameters are as follows:
104
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
Fig. 5.78: Basic configuration
Fig. 5.79: Advanced configuration
5.3. Raster data
105
GeoServer User Manual, Release 2.15.1
Parameter
Value
MaxAllowedTiles
2147483647
BackgroundValues
-9999
OutputTransparentColor “no color”
InputTransparentColor
“no color”
AllowMultiThreading
True
USE_JAI_IMAGEREAD True
SUGGESTED_TILE_SIZE512,512
Aerial imagery
In this example we are going to create a mosaic that will serve aerial imagery, specifically RGB GeoTIFFs.
Because this is visual data, in the Coverage Editor you can use the basic raster style, which is just a stub
SLD to instruct the GeoServer raster renderer to not do anything particular in terms of color management:
rasterrasterRasterA sample style for rasters, good for displaying imagery
,→Abstract>
Feature1.0
The result is the following:
Note: Those ugly black areas are the result of applying the default mosaic parameters to a mosaic that does
not entirely cover its bounding box. The areas within the BBOX that are not covered with data will default
to a value of 0 on each band. Since this mosaic is RGB we can simply set the OutputTransparentColor
to 0,0,0 in order to get transparent fills for the BBOX.
The various parameters can be set as follows:
106
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
Fig. 5.80: Basic configuration
Parameter
Value
MaxAllowedTiles
2147483647
BackgroundValues
(default)
OutputTransparentColor #000000
InputTransparentColor
“no color”
AllowMultiThreading
True
USE_JAI_IMAGEREAD True
SUGGESTED_TILE_SIZE512,512
The result is the following:
Fig. 5.81: Advanced configuration
Scanned maps
In this case we want to show how to serve scanned maps (mostly B&W images) via a GeoServer mosaic.
5.3. Raster data
107
GeoServer User Manual, Release 2.15.1
In the Coverage Editor you can use the basic raster since there is no need to use any of the advanced
RasterSymbolizer capabilities.
The result is the following.
Fig. 5.82: Basic configuration
This mosaic, formed by two single granules, shows a typical case where the “nodata” collar areas of the
granules overlap, as shown in the picture above. In this case we can use the InputTransparentColor
parameter to make the collar areas disappear during the superimposition process — in this case, by using
an InputTransparentColor of #FFFFFF.
The final configuration parameters are the following:
Parameter
Value
MaxAllowedTiles
2147483647
BackgroundValues
(default)
OutputTransparentColor “no color”
InputTransparentColor
#FFFFFF
AllowMultiThreading
True
USE_JAI_IMAGEREAD True
SUGGESTED_TILE_SIZE512,512
This is the result:
Fig. 5.83: Advanced configuration
Dynamic imagery
A mosaic need not be static. It can contain granules which change, are added or deleted. In this example,
we will create a mosaic that changes over time.
108
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
1. Create a mosaic in the standard way. (The specific configuration isn’t important.)
Fig. 5.84: This mosaic contains 5 granules. Note that InputTransparentColor is set to #FFFFFF here.
To add new granules, the index that was created when the mosaic was originally created needs to be regenerated. There are two ways to do this:
• Manually through the file system
• Through the REST interface
To update an ImageMosaic through the file system:
1. Update the contents of the mosaic by copying the new files into place. (Subdirectories are acceptable.)
2. Delete the index files. These files are contained in the top level directory containing the mosaic files
and include (but are not limited to) the following:
• .dbf
• .fix
• .prj
• .properties
• .shp
• .shx
3. (Optional but recommended) Edit the layer definition in GeoServer, making to sure to update the bounding box information (if changed).
4. Save the layer. The index will be recreated.
Note: Please see the REST section for information on Uploading a new image mosaic.
Multi-resolution imagery with reprojection
As a general rule, we want to have the highest resolution granules shown “on top”, with the lowerresolution granules filling in the gaps as necessary.
5.3. Raster data
109
GeoServer User Manual, Release 2.15.1
Fig. 5.85: This mosaic contains 9 granules
In this example, we will serve up overlapping granules that have varying resolutions. In addition, we will
mix resolutions, such that the higher resolution granule is reprojected to match the resolution of the lower
resolution granules.
1. In the Coverage Editor, use the basic raster style.
2. Create the mosaic in GeoServer.
3. One important configuration setting is the SORTING parameter of the layer. In order to see the highest
resolution imagery on top (the typical case), it must be set to resolution A. (For the case of lowest
resolution on top, use resolution D .)
4. Make any other configuration changes.
5. Also, in order to allow for multiple CRSs in a single mosaic, an indexer.properties file will need
to be created. Use the following
GranuleAcceptors=org.geotools.gce.imagemosaic.acceptors.
,→HeterogeneousCRSAcceptorFactory
GranuleHandler=org.geotools.gce.imagemosaic.granulehandler.
,→ReprojectingGranuleHandlerFactory
HeterogeneousCRS=true
MosaicCRS=EPSG\:4326
PropertyCollectors=CRSExtractorSPI(crs),ResolutionExtractorSPI(resolution)
Schema=*the_geom:Polygon,location:String,crs:String,resolution:String
The MosaicCRS property is not mandatory, but it’s a good idea to set a predictable target CRS that
all granule footprints can be reprojected into, otherwise the mosaic machinery will use the CRS of the
first indexed granule.
6. Save this file in the root of the mosaic directory (along with the index files). The result is the following:
110
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
Fig. 5.86: Closeup of granule overlap (high resolution granule on right)
7. To remove the reprojection artifact (shown in the above as a black area) edit the layer configuration to
set InputTransparentColor to #000000.
Referring to a datastore configured in GeoServer
It is possible to make the mosaic refer to an existing data store. The “datastore.properties“ file in this case
will contain only one or two properties, referring to the store to be used via the StoreName property. For
simple cases, e.g., a PostGIS store, the following will be sufficient:
StoreName=workspace:storename
For Oracle or H2, it’s best to also specify the SPI in order to inform the mosaic that it needs to work around
specific limitations of the storage (e.g., forced uppercase attribute usage, limitation in attribute name length
5.3. Raster data
111
GeoServer User Manual, Release 2.15.1
Fig. 5.87: Closeup of granule overlap (high resolution granule on right)
112
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
and the like):
StoreName=workspace:storename
SPI=org.geotools.data.oracle.OracleNGDataStoreFactory
The above will be sufficient in case the image mosaic can create the index table and perform normal indexing, using the directory name as the table name. In case a specific table name needs to be used, add an
“indexer.properties“ specifying the TypeName property, e.g.:
TypeName=myMosaicTypeName
In case the index “table” already exists instead, then a “indexer.properties“ file will be required, with the
following contents:
UseExistingSchema=true
TypeName=nameOfTheFeatureTypeContainingTheIndex
AbsolutePath=true
The above assumes location attribute provides absolute paths to the mosaic granules, instead of paths
relative to the mosaic configuration files directory.
5.3.5 GeoPackage
GeoPackage is an SQLite based standard format that is able to hold multiple vector and raster data layers
in a single file.
GeoPackage files can be used both as Vector Data Stores as well as Raster Data Stores (so that both kinds of
layers can published).
Adding a GeoPackage Raster (Mosaic) Data Store
By default, GeoPackage (mosaic) will be an option in the Raster Data Sources list when creating a new data
store.
Fig. 5.88: GeoPackage (mosaic) in the list of raster data stores
Option
Workspace
Data Source
Name
Description
Enabled
URL
Description
Name of the workspace to contain the GeoPackage Mosaic store. This will also be
the prefix of the raster layers created from the store.
Name of the GeoPackage Mosaic Store as it will be known to GeoServer. This can
be different from the filename. )
A full free-form description of the GeoPackage Mosaic Store.
If checked, it enables the store. If unchecked (disabled), no data in the GeoPackage
Mosaic Store will be served from GeoServer.
Location of the GeoPackage file. This can be an absolute path (such as
file:C:\Data\landbase.gpkg) or a path relative to GeoServer’s data directory (such as file:data/landbase.gpkg).
When finished, click Save.
5.3. Raster data
113
GeoServer User Manual, Release 2.15.1
Fig. 5.89: Configuring a GeoPackage (mosaic) data store
Other data sources are supplied as GeoServer extensions. Extensions are downloadable modules that add
functionality to GeoServer. Extensions are available at the GeoServer download page.
Warning: The extension version must match the version of the GeoServer instance.
5.3.6 ArcGrid
ArcGrid is a coverage file format created by ESRI.
Adding an ArcGrid data store
By default, ArcGrid will be an option in the Raster Data Sources list when creating a new data store.
Fig. 5.90: ArcGrid in the list of raster data stores
Configuring a ArcGrid data store
Option
Workspace
Data Source
Name
Description
Enabled
URL
114
Description
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
Fig. 5.91: Configuring an ArcGrid data store
5.3.7 GDAL Image Formats
GeoServer can leverage the ImageI/O-Ext GDAL libraries to read selected coverage formats. GDAL is able
to read many formats, but for the moment GeoServer supports only a few general interest formats and
those that can be legally redistributed and operated in an open source server.
The following image formats can be read by GeoServer using GDAL:
• DTED, Military Elevation Data (.dt0, .dt1, .dt2): http://www.gdal.org/frmt_dted.html
• EHdr, ESRI .hdr Labelled:
• ENVI, ENVI .hdr Labelled Raster:
• HFA, Erdas Imagine (.img):
• JP2MrSID, JPEG2000 (.jp2, .j2k):
• MrSID, Multi-resolution Seamless Image Database:
• NITF:
• ECW, ERDAS Compressed Wavelets (.ecw):
• JP2ECW, JPEG2000 (.jp2, .j2k): http://www.gdal.org/frmt_jp2ecw.html
• AIG, Arc/Info Binary Grid:
• JP2KAK, JPEG2000 (.jp2, .j2k):
Installing GDAL extension
From GeoServer version 2.2.x, GDAL must be installed as an extension. To install it:
• Navigate to the GeoServer download page
5.3. Raster data
115
GeoServer User Manual, Release 2.15.1
• Find the page that matches the version of the running GeoServer.
Warning: Be sure to match the version of the extension with that of GeoServer, otherwise errors will occur.
• Download the GDAL extension. The download link for GDAL will be in the Extensions section under
Coverage Format.
• Extract the files in this archive to the WEB-INF/lib directory of your GeoServer installation. On
Windows You may be prompted for confirmation to overwrite existing files, confirm the replacement
of the files
Moreover, in order for GeoServer to leverage these libraries, the GDAL (binary) libraries must be installed
through your host system’s OS. Once they are installed, GeoServer will be able to recognize GDAL data
types. See below for more information.
Installing GDAL native libraries
The ImageIO-Ext GDAL plugin for geoserver master uses ImageIO-Ext whose latest artifacts can be downloaded from here.
Browse to the native and then gdal directory for the Image IO-Ext download link. Now you should see a
list of artifacts that can be downloaded. We need to download two things now:
116
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
5.3. Raster data
117
GeoServer User Manual, Release 2.15.1
1. The CRS definitions
2. The native libraries matching the target operating system (more details on picking the right one for
your windows installation in the “Extra Steps for Windows Platforms” section)
Let’s now install the CRS definitions.
• Click on the “gdal_data.zip” to download the CRS definitions archive.
• Extract this archive on disk and place it in a proper directory on your system.
• Create a GDAL_DATA environment variable to the folder where you have extracted this file. Make
also sure that this directory is reachable and readable by the application server process’s user.
We now have to install the native libraries.
• Assuming you are using a 64 bit Ubuntu 11 Linux Operating System (for instance), click on the
linux folder and then on “gdal192-Ubuntu11-gcc4.5.2-x86_64.tar.gz” to download the native libraries
archive (Before doing this, make sure to read and agree with the ECWEULA if you intend to use
ECW).
• If you are using a Windows Operating System make sure to download the archive matching your
Microsoft Visual C++ Redistributables and your architecture. For example on a 64 bit Windows with
2010 Redistributables, download the gdal-1.9.2-MSVC2010-x64.zip archive
• Extract the archive on disk and place it in a proper directory on your system.
Warning:
If you are using a version of GDAL more recent than 1.9.2, replace the
imageio-ext-gdal-bindings-1.9.2.jar file with the equivalent java binding jar (typically named either gdal.jar or imageio-ext-gdal-bindings-*.jar) included with
your GDAL version. If your GDAL version does not include a bindings jar, it was probably
not compiled with the java bindings and will not work with GeoServer.
Warning: If you are on Windows, make sure that the GDAL DLL files are on your PATH. If
you are on Linux, be sure to set the LD_LIBRARY_PATH environment variable to refer to the
folder where the SOs are extracted.
Note: The native libraries contains the GDAL gdalinfo utility which can be used to test whether
or not the libs are corrupted. This can be done by browsing to the directory where the libs have
been extracted and performing a gdalinfo command with the formats options that shows all the
formats supported. The key element of GDAL support in GeoServer is represented by the JAVA
bindings. To test the bindings, the package contains a Java version of the gdalinfo utility inside
the “javainfo” folder (a .bat script for Windows and a .sh for Linux), it is very important to run
it (again, with the formats options) to make sure that the Java bindings are working properly
since that is what GeoServer uses. An error message like Can’t load IA 32-bit .dll on a AMD 64-bit
platform in the log files indicates a mixed version of the tools, please go through the installation
process again and pick the appropriate versions. More details on troubleshooting are provided
in the Note on running GeoServer as a Service on Windows section below.
Once these steps have been completed, restart GeoServer. If all the steps have been performed correctly,
new data formats will be in the Raster Data Sources list when creating a new data store in the Stores section
as shown here below.
If new formats do not appear in the GUI and you see the following message in the log file:
118
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
Fig. 5.92: GDAL image formats in the list of raster data stores
5.3. Raster data
119
GeoServer User Manual, Release 2.15.1
it.geosolutions.imageio.gdalframework.GDALUtilities
loadGDAL
failed.java.lang.UnsatisfiedLinkError: no gdaljni in java.library.path
WARNING:
Native
library
load
that means that the installations failed for some reason.
Extra Steps for Windows Platforms
There are a few things to be careful with as well as some extra steps if you are deploying on Windows.
As stated above, we have multiple versions like MSVC2005, MSVC2008 and so on matching the Microsoft
Visual C++ Redistributables. Depending on the version of the underlying operating system you’ll have to
pick up the right one. You can google around for the one you need. Also make sure you download the
32 bit version if you are using a 32 bit version of Windows or the 64 bit version (has a “-x64” suffix in the
name of the zip file) if you are running a 64 bit version of Windows. Again, pick the one that matches your
infrastructure.
Note on running GeoServer as a Service on Windows
Note that if you downloaded an installed GeoServer as a Windows service you installed the 32 bit version.
Simply deploying the GDAL ImageI/O-Ext native libraries in a location referred by the PATH environment
variable (like, as an instance, the JDK/bin folder) doesn’t allow GeoServer to leverage on GDAL, when run
as a service. As a result, during the service startup, GeoServer log reports this worrisome message:
it.geosolutions.imageio.gdalframework.GDALUtilities
loadGDAL
failed.java.lang.UnsatisfiedLinkError: no gdaljni in java.library.path
WARNING:
Native
library
load
Taking a look at the wrapper.conf configuration file available inside the GeoServer installation (at
bin/wrapper/wrapper.conf), there is this useful entry:
#
Java
Library
Path
(location
per.java.library.path.1=bin/wrapper/lib
of
Wrapper.DLL
or
libwrapper.so)
wrap-
To allow the GDAL native DLLs to be loaded, you have two options:
1. Move the native DLLs to the referenced path (bin/wrapper/lib)
2. Add a wrapper.java.library.path.2=path/where/you/deployed/nativelibs entry just after the wrapper.java.library.path1=bin/wrapper/lib line.
Adding support for ECW and MrSID on Windows
If you are on Windows and you want to add support for ECW and MrSID there is an extra step to perform.
Download and install ECW and MrSID from GeoSolutions site
In the Windows packaging ECW and MrSID are built as plugins hence they are not loaded by default but
we need to place their DLLs in a location that is pointed to by the GDAL_DRIVER_PATH environment
variable. By default the installer place the plugins in C:\Program Files\GDAL\gdalplugins.
GDAL internally uses an environment variable to look up additional drivers (notice that there are a few
default places where GDAL will look anyway). For additional information, please see the GDAL wiki.
Restart GeoServer, you should now see the new data sources available
120
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
5.3. Raster data
121
GeoServer User Manual, Release 2.15.1
Fig. 5.93: Configuring a DTED data store
Configuring a DTED data store
Configuring a EHdr data store
Configuring a ERDASImg data store
Configuring a JP2MrSID data store
Configuring a NITF data store
Supporting vector footprints
Starting with version 2.9.0, GeoServer supports vector footprints. A footprint is a shape used as a mask
to hide those pixels that are outside of the mask, hence making that part of the parent image transparent.
The currently supported footprint formats are WKB, WKT and Shapefile. By convention, the footprint file
should be located in the same directory as the raster data that the footprint applies to.
Note: In the examples of this section and related subsections, we will always use .wkt as extension, representing a WKT footprint, although both .wkb and .shp are supported too.
For example, supposing you have a MrSID file located at /mnt/storage/data/landsat/
N-32-40_2000.sid to be masked, you just need to place a WKT file on the same folder, as /mnt/
storage/data/landsat/N-32-40_2000.wkt Note that the footprint needs to have same path and
name of the original data file, with .wkt extension.
This is how the sample footprint geometry looks:
Once footprint file has been added, you need to change the FootprintBehavior parameter from None (the
default value) to Transparent, from the layer configuration.
122
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
Fig. 5.94: Configuring a EHdr data store
Fig. 5.95: Configuring a ERDASImg data store
5.3. Raster data
123
GeoServer User Manual, Release 2.15.1
Fig. 5.96: Configuring a JP2MrSID data store
Fig. 5.97: Configuring a NITF data store
124
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
Fig. 5.98: A sample geometry stored as WKT, rendered on OpenJump
Fig. 5.99: Setting the FootprintBehavior parameter
The next image depicts 2 layer previews for the same layer: the left one has no footprint, the right one has
a footprint available and FootprintBehavior set to transparent.
Fig. 5.100: No Footprint VS FootprintBehavior = Transparent
External Footprints data directory
As noted above, the footprint file should be placed in the same directory as the raster file. However in some
cases this may not be possible. For example, the folder containing the raster data may be read only.
As an alternative, footprint files can be located in a common directory, the footprints data directory. The
subdirectories and file names under that directory must match the original raster path and file names. The
footprints data directory is specified as a Java System Property or an Environment Variable, by setting the
FOOTPRINTS_DATA_DIR property/variable to the directory to be used as base folder.
Example
Suppose you have 3 raster files with the following paths:
• /data/raster/charts/nitf/italy_2015.ntf
5.3. Raster data
125
GeoServer User Manual, Release 2.15.1
• /data/raster/satellite/ecw/orthofoto_2014.ecw
• /data/raster/satellite/landsat/mrsid/N-32-40_2000.sid
They can be represented by this tree:
/data
\---raster
+---charts
|
\---nitf
|
italy_2015.ntf
|
\---satellite
+---ecw
|
orthofoto_2014.ecw
|
\---landsat
\---mrsid
N-32-40_2000.sid
In order to support external footprints you should
1. Create a /footprints (as an example) directory on disk
2. Set the FOOTPRINTS_DATA_DIR=/footprints variable/property.
3. Replicate the rasters folder hierarchy inside the specified folder, using the full paths.
4. Put the 3 WKT files in the proper locations:
• /footprints/data/raster/charts/nitf/italy_2015.wkt
• /footprints/data/raster/satellite/ecw/orthofoto_2014.wkt
• /footprints/data/raster/satellite/landsat/mrsid/N-32-40_2000.wkt
Which can be represented by this tree:
/footprints
\---data
\---raster
+---charts
|
\---nitf
|
italy_2015.wkt
|
\---satellite
+---ecw
|
orthofoto_2014.wkt
|
\---landsat
\---mrsid
N-32-40_2000.wkt
Such that, in the end, you will have the following folders hierarchy tree:
+---data
|
\---raster
|
+---charts
|
|
\---nitf
|
|
italy_2015.ntf
|
|
|
\---satellite
126
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
|
+---ecw
|
|
orthofoto_2014.ecw
|
|
|
\---landsat
|
\---mrsid
|
N-32-40_2000.sid
|
\---footprints
\---data
\---raster
+---charts
|
\---nitf
|
italy_2015.wkt
|
\---satellite
+---ecw
|
orthofoto_2014.wkt
|
\---landsat
\---mrsid
N-32-40_2000.wkt
Note the parallel mirrored folder hierarchy, with the only differences being a /footprints prefix at the
beginning of the path, and the change in suffix.
5.3.8 Oracle Georaster
Note: GeoServer does not come built-in with support for Oracle Georaster; it must be installed through
an extension. Proceed to Image Mosaic JDBC for installation details. This extension includes the support for
Oracle Georaster.
Adding an Oracle Georaster data store
Read the geotools documentation for Oracle Georaster Support: http://docs.geotools.org/latest/
userguide/library/coverage/oracle.html. After creating the xml config file proceed to the section Configuring GeoServer in the Image Mosaic JDBC Tutorial
5.3.9 Postgis Raster
Note: GeoServer does not come built-in with support for Postgis raster columns, it must be installed
through an extension. Proceed to Image Mosaic JDBC for installation details. This extension includes the
support for Postgis raster.
Adding an Postgis raster data store
Read the geotools documentation for Postgis raster Support: http://docs.geotools.org/latest/userguide/
library/coverage/pgraster.html. After creating the xml config file proceed to the section Configuring
GeoServer in the Image Mosaic JDBC Tutorial
5.3. Raster data
127
GeoServer User Manual, Release 2.15.1
5.3.10 ImagePyramid
Note: GeoServer does not come built-in with support for Image Pyramid; it must be installed through an
extension. Proceed to Installing the ImagePyramid extension for installation details.
An image pyramid is several layers of an image rendered at various image sizes, to be shown at different
zoom levels.
Installing the ImagePyramid extension
1. Download the ImagePyramid extension from the GeoServer download page.
Warning: Make sure to match the version of the extension to the version of the GeoServer instance!
2. Extract the contents of the archive into the WEB-INF/lib directory of the GeoServer installation.
Adding an ImagePyramid data store
Once the extension is properly installed ImagePyramid will be an option in the Raster Data Sources list when
creating a new data store.
Fig. 5.101: ImagePyramid in the list of raster data stores
Configuring an ImagePyramid data store
Option
Workspace
Data Source
Name
Description
Enabled
URL
Description
5.3.11 Image Mosaic JDBC
Note: GeoServer does not come built-in with support for Image Mosaic JDBC; it must be installed through
an extension. Proceed to Installing the JDBC Image Mosaic extension for installation details.
128
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
Fig. 5.102: Configuring an ImagePyramid data store
Installing the JDBC Image Mosaic extension
1. Download the JDBC Image Mosaic extension from the GeoServer download page.
Warning: Make sure to match the version of the extension to the version of the GeoServer instance!
2. Extract the contents of the archive into the WEB-INF/lib directory of the GeoServer installation.
Adding an Image Mosaic JDBC data store
Once the extension is properly installed Image Mosaic JDBC will be an option in the Raster Data Sources list
when creating a new data store.
Fig. 5.103: Image Mosaic JDBC in the list of vector data stores
Configuring an Image Mosaic JDBC data store
For a detailed description, look at the Tutorial
5.3.12 Custom JDBC Access for image data
5.3. Raster data
129
GeoServer User Manual, Release 2.15.1
Fig. 5.104: Configuring an Image Mosaic JDBC data store
Note: GeoServer does not come built-in with support for Custom JDBC Access; it must be installed through
an extension. Proceed to Image Mosaic JDBC for installation details. This extension includes the support for
Custom JDBC Access.
Adding a coverage based on Custom JDBC Access
This extension is targeted to users having a special database layout for storing their image data or use a
special data base extension concerning raster data.
Read the geotools documentation for Custom JDBC Access: http://docs.geotools.org/latest/userguide/
library/coverage/jdbc/customized.html.
After developing the custom plugin, package the classes into a jar file and copy it into the WEB-INF/lib
directory of the geoserver installation.
Create the xml config file and proceed to the section Configuring GeoServer in the Image Mosaic JDBC Tutorial
GeoServer provides extensive facilities for controlling how rasters are accessed. These are covered in the
following sections.
5.3.13 Coverage Views
Starting with GeoServer 2.6.0, You can define a new raster layer as a Coverage View. Coverage Views allow
defining a View made of different bands originally available inside coverages (either bands of the same
coverage or different coverages) of the same Coverage Store.
130
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
Creating a Coverage View
In order to create a Coverage View the administrator invokes the Create new layer page. When a Coverage
store is selected, the usual list of coverages available for publication appears. A link Configure new Coverage
view. . . also appears:
Selecting the Configure new Coverage view. . . link opens a new page where you can configure the coverage
view:
The upper text box allows to specify the name to be assigned to this coverage view. (In the following picture
we want to create as example, a currents view merging together both u and v components of the currents,
which are exposed as separated 1band coverages).
Next step is defining the output bands to be put in the coverage view. It is possible to specify which input
coverage bands need to be put on the view by selecting them from the Composing coverages/bands. . . .
Once selected, they needs to be added to the output bands of the coverage view, using the add button.
Optionally, is it possible to remove the newly added bands using the remove and remove all buttons. Once
done, clicking on the save button will redirect to the standard Layer configuration page.
Scrolling down to the end of the page, is it possible to see the bands composing the coverage (and verify
they are the one previously selected).
At any moment, the Coverage View can be refined and updated by selecting the Edit Coverage view. . . link
available before the Coverage Bands details section.
5.3. Raster data
131
GeoServer User Manual, Release 2.15.1
132
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
Once all the properties of the layer have been configured, by selecting the Save button, the coverage will be
saved in the catalog and it will become visible as a new layer.
Heterogeneous coverage views
In case the various coverages bound in the view have different resolution, the UI will present two extra
controls:
The coverage envelope policy defines how the bounding box of the output is calculated for metadata
purposes. Having different resolutions, the coverages are unlikely to share the same bounding box. The
possible values are:
• Intersect envelopes: Use the intersection of all input coverage envelopes
• Union envelopes: Use the union of all input coverage envelopes
The coverage resolution policy defines which target resolution is used when generating outputs:
• Best: Use the best resolution available among the chosen bands (e.g., in a set having 60m, 20m and
10m the 10m resolution will be chosen)
• Worst: Use the worst resolution available among the chosen bands (e.g., in a set having 60m, 20m and
10m the 60m resolution will be chosen)
The coverage resolution policy is context sensitive. Assume the input is a 12 bands Sentinel 2 dataset at
three different resolution, 10, 20 and 30 meters, and a false color image is generated by performing a band
selection in the SLD. If the policy is best and the SLD selects only bands at 20 and 60 meters, the output will
be at 20 meters instead of 10 meters.
Coverage View in action
A Layer preview of the newly created coverage view will show the rendering of the view. Note that clicking
on a point on the map will result into a GetFeatureInfo call which will report the values of the bands
composing the coverage view.
5.4 Databases
This section discusses the database data sources that GeoServer can access.
The standard GeoServer installation supports accessing the following databases:
5.4. Databases
133
GeoServer User Manual, Release 2.15.1
5.4.1 PostGIS
PostGIS is an open source spatial database based on PostgreSQL, and is currently one of the most popular
open source spatial databases today.
Adding a PostGIS database
As with all formats, adding a shapefile to GeoServer involves adding a new store to the existing Stores
through the Web administration interface.
Using default connection
To begin, navigate to Stores → Add a new store → PostGIS NG.
134
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
Fig. 5.105: Adding a PostGIS database
5.4. Databases
135
GeoServer User Manual, Release 2.15.1
Option
Workspace
Data Source Name
Description
Enabled
dbtype
host
port
database
schema
user
passwd
namespace
max connections
min connections
fetch size
Connection timeout
validate connections
Loose bbox
preparedStatements
Description
Name of the workspace to contain the database. This will also be the prefix of any
layer names created from tables in the database.
Name of the database. This can be different from the name as known to PostgreSQL/PostGIS.
Description of the database/store.
Enables the store. If disabled, no data in the database will be served.
Type of database. Leave this value as the default.
Host name where the database exists.
Port number to connect to the above host.
Name of the database as known on the host.
Schema in the above database.
User name to connect to the database.
Password associated with the above user.
Namespace to be associated with the database. This field is altered by changing the
workspace name.
Maximum amount of open connections to the database.
Minimum number of pooled connections.
Number of records read with each interaction with the database.
Time (in seconds) the connection pool will wait before timing out.
Checks the connection is alive before using it.
Performs only the primary filter on the bounding box. See the section on Using
loose bounding box for details.
Enables prepared statements.
When finished, click Save.
Using JNDI
GeoServer can also connect to a PostGIS database using JNDI (Java Naming and Directory Interface).
To begin, navigate to Stores → Add a new store → PostGIS NG (JNDI).
Option
Workspace
Data Source Name
Description
Enabled
dbtype
jndiReferenceName
schema
namespace
Description
Name of the workspace to contain the store. This will also be the prefix of all of the
layer names created from the store.
Name of the database. This can be different from the name as known to PostgreSQL/PostGIS.
Description of the database/store.
Enables the store. If disabled, no data in the database will be served.
Type of database. Leave this value as the default.
JNDI path to the database.
Schema for the above database.
Namespace to be associated with the database. This field is altered by changing the
workspace name.
When finished, click Save.
136
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
Fig. 5.106: Adding a PostGIS database (using JNDI)
5.4. Databases
137
GeoServer User Manual, Release 2.15.1
Configuring PostGIS layers
When properly loaded, all tables in the database will be visible to GeoServer, but they will need to be
individually configured before being served by GeoServer. See the section on Layers for how to add and
edit new layers.
Using loose bounding box
When the option loose bbox is enabled, only the bounding box of a geometry is used. This can result in
a significant performance gain, but at the expense of total accuracy; some geometries may be considered
inside of a bounding box when they are technically not.
If primarily connecting to this data via WMS, this flag can be set safely since a loss of some accuracy is
usually acceptable. However, if using WFS and especially if making use of BBOX filtering capabilities, this
flag should not be set.
Publishing a PostGIS view
Publishing a view follows the same process as publishing a table. The only additional step is to manually
ensure that the view has an entry in the geometry_columns table.
For example consider a table with the schema:
my_table( id int PRIMARY KEY, name VARCHAR, the_geom GEOMETRY )
Consider also the following view:
CREATE VIEW my_view as SELECT id, the_geom FROM my_table;
Before this view can be served by GeoServer, the following step is necessary to manually create the
geometry_columns entry:
INSERT INTO geometry_columns VALUES ('','public','my_view','my_geom', 2, 4326, 'POINT
,→' );
Performance considerations
GEOS
GEOS (Geometry Engine, Open Source) is an optional component of a PostGIS installation. It is recommended that GEOS be installed with any PostGIS instance used by GeoServer, as this allows GeoServer to
make use of its functionality when doing spatial operations. When GEOS is not available, these operations
are performed internally which can result in degraded performance.
Spatial indexing
It is strongly recommended to create a spatial index on tables with a spatial component (i.e. containing a
geometry column). Any table of which does not have a spatial index will likely respond slowly to queries.
138
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
Common problems
Primary keys
In order to enable transactional extensions on a table (for transactional WFS), the table must have a primary
key. A table without a primary key is considered read-only to GeoServer.
GeoServer has an option to expose primary key values (to make filters easier). Please keep in mind that
these values are only exposed for your convenience - any attempted to modify these values using WFS-T
update will be silently ignored. This restriction is in place as the primary key value is used to define the
FeatureId. If you must change the FeatureId you can use WFS-T delete and add in a single Transaction
request to define a replacement feature.
Multi-line
To insert multi-line text (for use with labeling) remember to use escaped text:
INSERT INTO place VALUES (ST_GeomFromText('POINT(-71.060316 48.432044)', 4326), E
,→'Westfield\nTower');
5.4.2 H2
Note: GeoServer does not come built-in with support for H2; it must be installed through an extension.
Proceed to Installing the H2 extension for installation details.
Installing the H2 extension
1. Download the H2 extension from the GeoServer download page.
Warning: Make sure to match the version of the extension to the version of the GeoServer instance!
2. Extract the contents of the archive into the WEB-INF/lib directory of the GeoServer installation.
Adding an H2 data store
Once the extension is properly installed H2 will be an option in the Vector Data Sources list when creating a
new data store.
Fig. 5.107: H2 in the list of vector data stores
5.4. Databases
139
GeoServer User Manual, Release 2.15.1
Configuring an H2 data store
Fig. 5.108: Configuring an H2 data store
Configuring an H2 data store with JNDI
Other data sources are supplied as GeoServer extensions. Extensions are downloadable modules that add
functionality to GeoServer. Extensions are available at the GeoServer download page.
Warning: The extension version must match the version of the GeoServer instance.
5.4.3 ArcSDE
Note: ArcSDE support is not enabled by default and requires the ArcSDE extension to be installed prior to
use. Please see the section on Installing the ArcSDE extension for details.
140
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
ESRI’s ArcSDE is a spatial engine that runs on top of a relational database such as Oracle or SQL Server.
GeoServer with the ArcSDE extension supports ArcSDE versions 9.2 and 9.3. It has been tested with Oracle
10g and Microsoft SQL Server 2000 Developer Edition. The ArcSDE extension is based on the GeoTools
ArcSDE driver and uses the ESRI Java API libraries. See the GeoTools ArcSDE page for more technical
details.
There are two types of ArcSDE data that can be added to GeoServer: vector and raster.
Vector support
ArcSDE provides efficient access to vector layers, (“featureclasses” in ArcSDE jargon), over a number of
relational databases. GeoServer can set up featuretypes for registered ArcSDE featureclasses and spatial
views. For versioned ArcSDE featureclasses, GeoServer will work on the default database version, for both
read and write access.
Transactional support is enabled for featureclasses with a properly set primary key, regardless if the featureclass is managed by a user or by ArcSDE. If a featureclass has no primary key set, it will be available as
read-only.
Raster support
ArcSDE provides efficient access to multi-band rasters by storing the raw raster data as database blobs,
dividing it into tiles and creating a pyramid. It also allows a compression method to be set for the tiled blob
data and an interpolation method for the pyramid resampling.
All the bands comprising a single ArcSDE raster layer must have the same pixel depth, which can be one
of 1, 4, 8, 16, and 32 bits per sample for integral data types. For 8, 16 and 32 bit bands, they may be signed
or unsigned. 32 and 64 bit floating point sample types are also supported.
ArcSDE rasters may also be color mapped, as long as the raster has a single band of data typed 8 or 16 bit
unsigned.
Finally, ArcSDE supports raster catalogs. A raster catalog is a mosaic of rasters with the same spectral
properties but instead of the mosaic being precomputed, the rasters comprising the catalog are independent
and the mosaic work performed by the application at runtime.
Technical Detail
Compression
methods
Number of bands
Bit
depth
for
color-mapped
rasters
Raster Catalogs
Status
LZW, JPEG
Any number of bands except for 1 and 4 bit rasters (supported for single-band
only).
8 bit and 16 bit
Any pixel storage type
Installing the ArcSDE extension
Warning: Due to licensing requirements, not all files are included with the extension. To install ArcSDE
support, it is necessary to download additional files. Just installing the ArcSDE extension will have
no effect.
5.4. Databases
141
GeoServer User Manual, Release 2.15.1
GeoServer files
1. Download the ArcSDE extension from the GeoServer download page.
Warning: Make sure to match the version of the extension to the version of the GeoServer instance!
2. Extract the contents of the archive into the WEB-INF/lib directory of the GeoServer installation.
Required external files
There are two files that are required but are not packaged with the GeoServer extension:
File
jsde_sdk.jar
jpe_sdk.jar
Notes
Also known as jsde##_sdk.jar where ## is the version number, such as 92 for
ArcSDE version 9.2
Also known as jpe##_sdk.jar where ## is the version number, such as 92 for
ArcSDE version 9.2
You should always make sure the jsde_sdk.jar and jpe_sdk.jar versions match your ArcSDE server
version, including service pack, although client jar versions higher than the ArcSDE Server version usually
work just fine.
These two files are available on your installation of the ArcSDE Java SDK from the ArcSDE installation media (usually C:\Program Files\ArcGIS\ArcSDE\lib). They may also be available on ESRI’s website
if there’s a service pack containing them, but this is not guaranteed. To download these files from ESRI’s
website:
1. Navigate
to
listPatches&PID=66
http://support.esri.com/index.cfm?fa=downloads.patchesServicePacks.
2. Find the link to the latest service pack for your version of ArcSDE
3. Scroll down to Installing this Service Pack → ArcSDE SDK → UNIX (regardless of your target OS)
4. Download any of the target files (but be sure to match 32/64 bit to your OS)
5. Open the archive, and extract the appropriate JARs.
Note: The JAR files may be in a nested archive inside this archive.
Note: The icu4j##.jar may also be on your ArcSDE Java SDK installation folder, but it is already
included as part of the the GeoServer ArcSDE extension and is not necessary to install separately.
1. When downloaded, copy the two files to the WEB-INF/lib directory of the GeoServer installation.
After all GeoServer files and external files have been downloaded and copied, restart GeoServer.
142
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
Adding an ArcSDE vector data store
In order to serve vector data layers, it is first necessary to register the ArcSDE instance as a data store in
GeoServer. Navigate to the New data source page, accessed from the Stores page in the Web administration
interface. and an option for ArcSDE will be in the list of Vector Data Stores.
Note: If ArcSDE is not an option in the Feature Data Set Description drop down box, the extension is not
properly installed. Please see the section on Installing the ArcSDE extension.
Fig. 5.109: ArcSDE in the list of data sources
Configuring an ArcSDE vector data store
The next page contains configuration options for the ArcSDE vector data store. Fill out the form, then click
Save.
Option
Feature Data
Set ID
Enabled
Namespace
Description
server
port
instance
Required?Description
N/A
The name of the data store as set on the previous page.
user
password
Yes
No
N/A
Yes
No
Yes
Yes
No
pool.
No
minConnections
pool.
No
maxConnections
pool.timeOut No
When this box is checked the data store will be available to GeoServer
The namespace associated with the data store.
A description of the data store.
The URL of the ArcSDE instance.
The port that the ArcSDE instance is set to listen to. Default is 5151.
The name of the specific ArcSDE instance, where applicable, depending on
the underlying database.
The username to authenticate with the ArcSDE instance.
The password associated with the above username for authentication with
the ArcSDE instance.
Connection pool configuration parameters. See the Database Connection
Pooling section for details.
Connection pool configuration parameters. See the Database Connection
Pooling section for details.
Connection pool configuration parameters. See the Database Connection
Pooling section for details.
You may now add featuretypes as you would normally do, by navigating to the New Layer page, accessed
from the Layers page in the Web administration interface.
Configuring an ArcSDE vector data store with Direct Connect
ESRI Direct Connect[ESRI DC] allows clients to directly connect to an SDE GEODB 9.2+ without a need of
an SDE server instance, and is recommended for high availability environments, as it removes the ArcSDE
gateway server as a single point of failure. ESRI DC needs additional platform dependent binary drivers
and a working Oracle Client ENVIRONMENT (if connecting to an ORACLE DB). See Properties of a direct
5.4. Databases
143
GeoServer User Manual, Release 2.15.1
Fig. 5.110: Configuring a new ArcSDE data store
144
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
connection to an ArcSDE geodatabase in the ESRI ArcSDE documentation for more information on Direct
Connect, and Setting up clients for a direct connection for information about connecting to the different
databases supported by ArcSDE.
The GeoServer configuration parameters are the same as in the Configuring an ArcSDE vector data store
section above, with a couple differences in how to format the parameters:
• server: In ESRI Direct Connect Mode a value must be given or the Direct Connect Driver will throw
an error, so just put a ‘none’ there - any String will work!
• port: In ESRI Direct Connect Mode the port has a String representation: sde:oracle10g,
sde:oracle11g:/:test, etc. For further information check ArcSDE connection syntax at the official ArcSDE
documentation from ESRI.
• instance: In ESRI Direct Connect Mode a value must be given or the Direct Connect Driver will throw
an error, so just put a ‘none’ there - any String will work!
• user: The username to authenticate with the geo database.
• password: The password associated with the above username for authentication with the geo
database.
Note: Be sure to assemble the password like: password@ for Oracle
You may now add featuretypes as you would normally do, by navigating to the New Layer page, accessed
from the Layers page in the Web Administration Interface.
Adding an ArcSDE vector data store with JNDI
Configuring an ArcSDE vector data store with JNDI
Adding an ArcSDE raster coveragestore
In order to serve raster layers (or coverages), it is first necessary to register the ArcSDE instance as a store
in GeoServer. Navigate to the Add new store page, accessed from the Stores page in the Web administration
interface and an option for ArcSDE Raster Format will be in list.
Note: If ArcSDE Raster Format is not an option in the Coverage Data Set Description drop down box,
the extension is not properly installed. Please see the section on Installing the ArcSDE extension.
Fig. 5.111: ArcSDE Raster in the list of data sources
Configuring an ArcSDE raster coveragestore
The next page contains configuration options for the ArcSDE instance. Fill out the form, then click Save.
5.4. Databases
145
GeoServer User Manual, Release 2.15.1
Fig. 5.112: Configuring a new ArcSDE coveragestore
146
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
Option
Coverage
Data Set ID
Enabled
Namespace
Type
URL
Required?Description
N/A
The name of the coveragestore as set on the previous page.
Description
No
N/A
Yes
No
Yes
When this box is checked the coveragestore will be available to GeoServer.
The namespace associated with the coveragestore.
The type of coveragestore. Leave this to say ArcSDE Raster.
The URL of the raster, of the form sde://:@/
#.
A description of the coveragestore.
You may now add coverages as you would normally do, by navigating to the Add new layer page, accessed
from the Layers page in the Web administration interface.
5.4.4 DB2
Note: GeoServer does not come built-in with support for DB2; it must be installed through an extension.
Proceed to Installing the DB2 extension for installation details.
The IBM DB2 UDB database is a commercial relational database implementing ISO SQL standards and is
similar in functionality to Oracle, SQL Server, MySQL, and PostgreSQL. The DB2 Spatial Extender is a nocharge licensed feature of DB2 UDB which implements the OGC specification “Simple Features for SQL
using types and functions” and the ISO “SQL/MM Part 3 Spatial” standard.
A trial copy of DB2 UDB and Spatial Extender can be downloaded from: http://www-306.ibm.com/
software/data/db2/udb/edition-pde.html . There is also an “Express-C” version of DB2, that is free,
comes with spatial support, and has no limits on size. It can be found at: http://www-306.ibm.com/
software/data/db2/express/download.html
Installing the DB2 extension
Warning: Due to licensing requirements, not all files are included with the extension. To install DB2
support, it is necessary to download additional files. Just installing the DB2 extension will have no
effect.
GeoServer files
1. Download the DB2 extension from the GeoServer download page.
Warning: Make sure to match the version of the extension to the version of the GeoServer instance!
2. Extract the contents of the archive into the WEB-INF/lib directory of the GeoServer installation.
5.4. Databases
147
GeoServer User Manual, Release 2.15.1
Required external files
There are two files that are required but are not packaged with the GeoServer extension: db2jcc.jar
and db2jcc_license_cu.jar. These files should be available in the java subdirectory of your DB2
installation directory. Copy these files to the WEB-INF/lib directory of the GeoServer installation.
After all GeoServer files and external files have been downloaded and copied, restart GeoServer.
Adding a DB2 data store
When properly installed, DB2 will be an option in the Vector Data Sources list when creating a new data
store.
Fig. 5.113: DB2 in the list of raster data stores
Configuring a DB2 data store
Configuring a DB2 data store with JNDI
Notes on usage
DB2 schema, table, and column names are all case-sensitive when working with GeoTools/GeoServer.
When working with DB2 scripts and the DB2 command window, the default is to treat these names as
upper-case unless enclosed in double-quote characters.
5.4.5 MySQL
Note: GeoServer does not come built-in with support for MySQL; it must be installed through an extension.
Proceed to Installing the MySQL extension for installation details.
Warning: Currently the MySQL extension is unmaintained and carries unsupported status. While still
usable, do not expect the same reliability as with other extensions.
MySQL is an open source relational database with some limited spatial functionality.
Installing the MySQL extension
1. Download the MySQL extension from the GeoServer download page.
Warning: Make sure to match the version of the extension to the version of the GeoServer instance!
148
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
Fig. 5.114: Configuring a DB2 data store
5.4. Databases
149
GeoServer User Manual, Release 2.15.1
2. Extract the contents of the archive into the WEB-INF/lib directory of the GeoServer installation.
Adding a MySQL database
Once the extension is properly installed MySQL will show up as an option when creating a new data store.
Fig. 5.115: MySQL in the list of data sources
Configuring a MySQL data store
host
port
database
user
password
max
connections
min
connections
validate
connections
The mysql server host name or ip address.
The port on which the mysql server is accepting connections.
The name of the database to connect to.
The name of the user to connect to the mysql database as.
The password to use when connecting to the database. Left blank for no password.
Connection pool configuration parameters. See the Database Connection Pooling section for details.
5.4.6 Oracle
Note: GeoServer does not come built-in with support for Oracle; it must be installed through an extension.
Proceed to Installing the Oracle extension for installation details.
Oracle Spatial and Locator are the spatial components of Oracle. Locator is provided with all Oracle versions, but has limited spatial functions. Spatial is Oracle’s full-featured spatial offering, but requires a
specific license to use.
Installing the Oracle extension
Warning: Due to licensing requirements, not all files are included with the extension. To install Oracle
support, it is necessary to download additional files.
1. Download the Oracle extension from the GeoServer download page.
Warning: Make sure to match the version of the extension to the version of the GeoServer instance!
150
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
Fig. 5.116: Configuring a MySQL data store
5.4. Databases
151
GeoServer User Manual, Release 2.15.1
2. Extract the contents of the archive into the WEB-INF/lib directory of the GeoServer installation.
3. Get the Oracle JDBC driver from either your Oracle installation (e.g. ojdbc6.jar, ojdbc7.jar) or
download them from the Oracle JDBC driver distribution page
Consider replacing the Oracle JDBC driver
The Oracle data store zip file comes with ojdbc4.jar, an old, Oracle 10 compatible JDBC driver that normally works fine with 11g as well. However, minor glitches have been observed with 11g (issues computing
layer bounds when session initiation scripts are in use) and the driver has not been tested with 12i.
If you encounter functionality or performance issues it is advised to remove this driver and download the
latest version from the Oracle web site.
Adding an Oracle datastore
Once the extension is properly installed Oracle appears as an option in the Vector Data Sources list when
creating a new data store.
Fig. 5.117: Oracle in the list of data sources
152
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
Fig. 5.118: Configuring an Oracle datastore
5.4. Databases
153
GeoServer User Manual, Release 2.15.1
Configuring an Oracle datastore
Option
host
port
database
schema
user
password
max
connections
min
connections
fetch size
Connection
timeout
validate
connections
Loose bbox
Metadata bbox
Description
The Oracle server host name or IP address.
The port on which the Oracle server is accepting connections (often this is port
1521).
The name of the database to connect to. By default this is interpreted as a SID name.
To connect to a Service, prefix the name with a /.
The database schema to access tables from. Setting this value greatly increases the
speed at which the data store displays its publishable tables and views, so it is
advisable to set this.
The name of the user to use when connecting to the database.
The password to use when connecting to the database. Leave blank for no password.
Connection pool configuration parameters. See Database Connection Pooling for details.
Controls how bounding box filters are made against geometries in the database.
See the Using loose bounding box section below.
Flag controlling the use of MDSYS.USER_SDO_GEOM_METADATA or
MDSYS.ALL_SDO_GEOM_METADATA table for bounding box calculations,
this brings a better performance if the views access is fast and the bounds are
configured right in the tables default is false
Connecting to an Oracle cluster
In order to connect to an Oracle RAC one can use an almost full JDBC url as the database, provided it
starts with ( it will be used verbatim and options “host” and “port” will be ignored. Here is an example
“database” value used to connect to an Oracle RAC:
(DESCRIPTION=(LOAD_BALANCE=on)(ADDRESS=(PROTOCOL=TCP)(HOST=host1)
,→(PORT=1521))(ADDRESS=(PROTOCOL=TCP)(HOST=host2) (PORT=1521))(CONNECT_DATA=(SERVICE_
,→NAME=service)))
More information about this syntax can be found in the Oracle documentation.
Connecting to a SID or a Service
Recent versions of Oracle support connecting to a database via either a SID name or a Service name. A SID
connection descriptor has the form: host:port:database, while a Service connection descriptor has the
format host:port/database. GeoServer uses the SID form by default. To connect via a Service, prefix
the database name configuration entry with a /.
154
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
Connecting to database through LDAP
For instance if you want to establish a connection with the jdbc thin driver through LDAP, you
can use following connect string for the input field database ldap://[host]:[Port]/[db],
cn=OracleContext,dc=[oracle_ldap_context].
If you are using referrals, enable it by placing a jndi.properties file in geoserver’s CLASSPATH, which is in
geoserver/WEB-INF/classes. This property file contains:
java.naming.referral=follow
Using loose bounding box
When the Loose bbox option is set, only the bounding box of database geometries is used in spatial
queries. This results in a significant performance gain. The downside is that some geometries may be
reported as intersecting a BBOX when they actually do not.
If the primary use of the database is through the Web Map Service (WMS) this flag can be set safely, since
querying more geometries does not have any visible effect. However, if using the Web Feature Service (WFS)
and making use of BBOX filtering capabilities, this flag should not be set.
Using the geometry metadata table
The Oracle data store by default looks at the MDSYS.USER_SDO* and MDSYS.ALL_SDO* views to determine the geometry type and native SRID of each geometry column. Those views are automatically populated with information about the geometry columns stored in tables that the current user owns (for the
MDSYS.USER_SDO* views) or can otherwise access (for the MDSYS.ALL_SDO* views).
There are a few issues with this strategy:
• if the connection pool user cannot access the tables (because impersonation is used) the MDSYS views
will be empty, making it impossible to determine both the geometry type and the native SRID
• the geometry type can be specified only while building the spatial indexes, as an index constraint.
However such information is often not included when creating the indexes
• the views are populated dynamically based on the current user. If the database has thousands of
tables and users the views can become very slow
Starting with GeoServer 2.1.4 the administrator can address the above issues by manually creating a geometry metadata table describing each geometry column. Its presence is indicated via the Oracle datastore
connection parameter named Geometry metadata table (which may be a simple table name or a schemaqualified one). The table has the following structure (the table name is flexible, just specify the one chosen
in the data store connection parameter):
CREATE TABLE GEOMETRY_COLUMNS(
F_TABLE_SCHEMA VARCHAR(30) NOT NULL,
F_TABLE_NAME VARCHAR(30) NOT NULL,
F_GEOMETRY_COLUMN VARCHAR(30) NOT NULL,
COORD_DIMENSION INTEGER,
SRID INTEGER NOT NULL,
TYPE VARCHAR(30) NOT NULL,
UNIQUE(F_TABLE_SCHEMA, F_TABLE_NAME, F_GEOMETRY_COLUMN),
CHECK(TYPE IN ('POINT','LINE', 'POLYGON', 'COLLECTION', 'MULTIPOINT', 'MULTILINE',
,→'MULTIPOLYGON', 'GEOMETRY') ));
5.4. Databases
155
GeoServer User Manual, Release 2.15.1
When the table is present the store first searches it for information about each geometry column to be
classified, and falls back on the MDSYS views only if the table does not contain any information.
Configuring an Oracle database with JNDI
See Setting up a JNDI connection pool with Tomcat for a guide on setting up an Oracle connection using JNDI.
5.4.7 Microsoft SQL Server and SQL Azure
Note: GeoServer does not come built-in with support for SQL Server; it must be installed through an
extension. Proceed to Installing the SQL Server extension for installation details.
Microsoft’s SQL Server is a relational database with spatial functionality. SQL Azure is the database option
provided in the Azure cloud solution which is in many respects similar to SQL Server 2008.
Supported versions
The extension supports SQL Server 2008 and SQL Azure.
Installing the SQL Server extension
Warning: Due to licensing requirements, not all files are included with the extension. To install SQL
Server support, it is necessary to download additional files.
GeoServer files
1. Download the SQL Server extension from the GeoServer download page.
Warning: Make sure to match the version of the extension to the version of the GeoServer instance!
2. Extract the contents of the archive into the WEB-INF/lib directory of the GeoServer installation.
3. Restart the GeoServer to load the extension.
Microsoft files
1. Navigate to the download page for Microsoft JDBC Drivers for SQL Server.
2. Extract the contents of the archive.
3. Copy the file sqljdbc4.jar to the WEB-INF/lib directory of the GeoServer installation.
4. If GeoServer is installed on Windows, additionally copy auth\x86\sqljdbc_auth.dll and
xa\x86\sqljdbc_xa.dll to C:\Windows\System32.
156
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
Adding a SQL Server database
Once the extension is properly installed SQL Server will show up as an option when creating a new data
store.
Fig. 5.119: SQL Server in the list of vector data sources
Configuring a SQL Server data store
Fig. 5.120: Configuring a SQL Server data store
5.4. Databases
157
GeoServer User Manual, Release 2.15.1
host
port
database
schema
user
password
max
connections
min
connections
The sql server instance host name or ip address, only.
Note that
server\instance notation is not accepted - specify the port below, instead, if
you have a non-default instance.
The port on which the SQL server instance is accepting connections. See the note
below.
The name of the database to connect to. Might be left blank if the user connecting
to SQL Server has a “default database” set in the user configuration
The database schema to access tables from (optional).
The name of the user to connect to the oracle database as.
The password to use when connecting to the database. Leave blank for no password.
Connection pool configuration parameters. See the Database Connection Pooling section for details. If you are connecting to SQL Azure make sure to set the validate
connections flag as SQL Azure closes inactive connections after a very short delay.
Determining the port used by the SQL Server instance
You can determine the port in use by connecting to your SQL server instance using some other software, and
then using netstat to display details on network connections. In the following example on a Windows
PC, the port is 2646
C:\>netstat -a | find "sql1"
TCP
DPI908194:1918
maittestsql1.dpi.nsw.gov.au:2646
ESTABLISHED
Using the geometry metadata table
The SQL server data store can determine the geometry type and native SRID of a particular column only
by data inspection, by looking at the first row in the table. Of course this is error prone, and works only if
there is data in the table. The administrator can address the above issue by manually creating a geometry
metadata table describing each geometry column. Its presence is indicated via the SQL Server datastore
connection parameter named Geometry metadata table (which may be a simple table name or a schemaqualified one). The table has the following structure (the table name is flexible, just specify the one chosen
in the data store connection parameter):
CREATE TABLE GEOMETRY_COLUMNS(
F_TABLE_SCHEMA VARCHAR(30) NOT NULL,
F_TABLE_NAME VARCHAR(30) NOT NULL,
F_GEOMETRY_COLUMN VARCHAR(30) NOT NULL,
COORD_DIMENSION INTEGER,
SRID INTEGER NOT NULL,
TYPE VARCHAR(30) NOT NULL,
UNIQUE(F_TABLE_SCHEMA, F_TABLE_NAME, F_GEOMETRY_COLUMN),
CHECK(TYPE IN ('POINT','LINE', 'POLYGON', 'COLLECTION', 'MULTIPOINT', 'MULTILINE',
,→'MULTIPOLYGON', 'GEOMETRY') ));
When the table is present the store first searches it for information about each geometry column to be
classified, and falls back on data inspection only if the table does not contain any information.
5.4.8 Teradata
158
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
Note: Teradata database support is not enabled by default and requires the Teradata extension to be
installed prior to use. Please see the section on Installing the Teradata extension for details.
The Teradata Database is a commercial relational database (RDBMS) that specializes in parallel processing
and scalability. From version 12.0, Teradata has added geospatial support, closely following the SQL/MM
standard (SQL Multimedia and Applications Packages). Geospatial support was available through an addon in version 12.0 and became standard in version 13.0.
GeoServer connects to a Teradata database via JDBC.
For more information on Teradata and the Teradata Database system, please go to http://www.teradata.
com.
Compatibility
The GeoServer Teradata extension is compatible with GeoServer 2.1.1 and higher. GeoServer can connect
to Teradata databases version 12.0 or higher. Version 12.0 of the Teradata Database requires the optional
geospatial extension to be installed.
Read/write access
The Teradata datastore in GeoServer supports full transactional capabilities, including feature creation,
editing, and deleting.
To support editing, a table must have one of the following:
• a primary key
• a unique primary index
• an identity (sequential) column
Note: It is not recommended to solely use an identity column, as spatial index triggers are not supported
when referencing an identity column. See the section on Spatial Indexes for more details.
Query Banding
The GeoServer Teradata extension supports Query Banding. Query Banding is a feature which allows any
application to associate context information with each query it issues to the database. In practice this can
be used for purposes of workload management (i.e. request prioritization), debugging, and logging.
GeoServer sends the following information as part of a standard request:
• Name of application (i.e. GeoServer)
• Authenticated username (if set up)
• Hostname (if available)
• Type of statement (i.e. “SELECT”, “INSERT”, “DELETE”)
It is not possible to modify this information from within GeoServer.
5.4. Databases
159
GeoServer User Manual, Release 2.15.1
Spatial indexes
GeoServer will read from a spatial index if its exists. The convention for a spatial index table name is:
[TABLENAME]_[GEOMETRYCOLUMN]_idx
So for a layer called “STATES” with a geometry column called “GEOM”, the index table should be called
STATES_GEOM_idx.
Warning: Make sure to match the case of all tables and columns. If the geometry column is called
“GEOM” (upper case) and the index created is called STATES_geom_idx (lower case), the index will not
be properly linked to the table.
This index table should contain two columns:
• A column that maps to the primary key of the spatial data table
• The tessellation cell ID (cellid)
The tessellation cell ID is the ID of the cell where that feature is contained.
Geometry column
As per the SQL/MM standard, in order to make a Teradata table spatially enabled, an entry needs to be
created for that table in the geometry_columns table. This table is stored, like all other spatially-related
tables, in the SYSSPATIAL database.
Tessellation
Tessellation is the name of Teradata’s spatial index. In order to activate tessellation for a given layer, an
entry (row) needs to be placed in the SYSSPATIAL.tessellation table. This table should have the
following schema:
Table name
F_TABLE_SCHEMA
Type
varchar
F_TABLE_NAME
F_GEOMETRY_COLUMN
U_XMIN
U_YMIN
U_XMAX
U_YMAX
G_NX
G_NY
LEVELS
SCALE
SHIFT
varchar
varchar
float
float
float
float
integer
integer
integer
float
float
Description
Name of the spatial database/schema containing
the table
Name of the spatial table
Column that contains the spatial data
Minimum X value for the tessellation universe
Minimum Y value for the tessellation universe
Maximum X value for the tessellation universe
Maximum Y value for the tessellation universe
Number of X grids
Number of Y grids
Number of levels in the grid
Scale value for the grid
Shift value for the grid
Warning: The tessellation table values are case sensitive and so must match the case of the tables and
columns.
160
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
Installing the Teradata extension
Teradata database support is not enabled by default and requires the GeoServer Teradata extension to be
installed prior to use. In addition to this extension, an additional artifact will need to be downloaded from
the Teradata website.
GeoServer artifacts
1. Download the Teradata extension from the download page that matches your version of GeoServer.
The extension is listed at the bottom of the download page under Extensions.
Warning: Make sure to match the version of the extension to the version of GeoServer!
2. Extract the contents of the archive into the WEB-INF/lib directory of the GeoServer installation.
Teradata artifacts
In addition to the GeoServer artifacts, it is also necessary to download the Teradata JDBC driver. This file
cannot be redistributed and so must be downloaded directly from the Teradata website.
1. Download the Teradata JDBC driver at https://downloads.teradata.com/download/connectivity/
jdbc-driver.
Note: You will need to log in to Teradata’s site in order to download this artifact.
2. Extract the contents of the archive into the WEB-INF/lib directory of the GeoServer installation.
When all files have been downloaded and extracted, restart GeoServer. To verify that the installation was
successful, see the section on Adding a Teradata datastore.
Note: The full list of files required are:
• gt-jdbc-teradata-.jar
• tdgssconfig.jar
• terajdbc4.jar
Adding a Teradata datastore
Once the extension has been added, it will now be possible to load an existing Teradata database as a store
in GeoServer. In the Web administration interface, click on Stores then go to Add a new Store. You will see a
option, under Vector Data Stores, for Teradata. Select this option.
Note: If you don’t Teradata in this list, the extension has not been installed properly. Please ensure that the
steps in the Installing the Teradata extension have been followed correctly.
On the next screen, enter in the details on how to connect to the Teradata database. You will need to include
the following information:
5.4. Databases
161
GeoServer User Manual, Release 2.15.1
Fig. 5.121: Teradata in the list of readable stores
Option
Workspace
Data Source Name
Description
Enabled
host
port
database
user
passwd
namespace
Expose
primary
keys
max connections
min connections
fetch size
Connection timeout
validate connections
Primary key metadata table
Loose bbox
tessellationTable
estimatedBounds
Max open prepared
statements
162
Description
Name of the workspace to contain the database. This will also be the prefix of any
layers server from tables in the database.
Name of the database in GeoServer. This can be different from the name of the
Teradata database, if desired.
Description of the database/store.
Enables the store. If disabled, no layers from the database will be served.
Host name where the database exists. Can be a URL or IP address.
Port number on which to connect to the above host.
Name of the Teradata database.
User name to connect to use to connect to the database.
Password associated with the above user.
Namespace to be associated with the database. This field is altered automatically
by the above Workspace field.
Exposes primary key as a standard attribute.
Maximum amount of open/pooled connections to the database.
Minimum number of open/pooled connections.
Number of records read with each interaction with the database.
Time (in seconds) the connection pool will wait before timing out.
Checks the connection is alive before using it.
Name of primary key metadata table to use if unable to determine the primary key
of a table.
If checked, performs only the primary filter on the bounding box.
The name of the database table that contains the tessellations
Enables using the geometry_columns/tessellation table bounds as an estimation
instead of manual calculation.
The maximum number of prepared statements.
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
When finished, click Save.
Using JNDI
GeoServer can also connect to a Teradata database using JNDI (Java Naming and Directory Interface).
To begin, in the Web administration interface, click on Stores then go to Add a new Store. You will see a option,
under Vector Data Stores, for Teradata (JNDI). Select this option.
On the next screen, enter in the details on how to connect to the Teradata database. You will need to include
the following information:
5.4. Databases
163
GeoServer User Manual, Release 2.15.1
Fig. 5.122: Adding a Teradata store
Fig. 5.123: Teradata (JNDI) in the list of readable stores
164
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
Option
Workspace
Data Source Name
Description
Enabled
jndiReferenceName
schema
namespace
Expose
primary
keys
Primary key metadata table
Loose bbox
Description
Name of the workspace to contain the database. This will also be the prefix of any
layers server from tables in the database.
Name of the database in GeoServer. This can be different from the name of the
Teradata database, if desired.
Description of the database/store.
Enables the store. If disabled, no layers from the database will be served.
JNDI path to the database.
Schema for the above database.
Namespace to be associated with the database. This field is altered by changing the
workspace name.
Exposes primary key as a standard attribute.
Name of primary key metadata table to use if unable to determine the primary key
of a table.
If checked, performs only the primary filter on the bounding box.
When finished, click Save.
Fig. 5.124: Adding a Teradata store with JNDI
5.4. Databases
165
GeoServer User Manual, Release 2.15.1
Adding layers
One the store has been loaded into GeoServer, the process for loading data layers from database tables is
the same as any other database source. Please see the Layers section for more information.
Note: Only those database tables that have spatial information and an entry in the SYSSPATIAL.
geometry_columns table can be served through GeoServer.
GeoServer provides extensive facilities for controlling how databases are accessed. These are covered in the
following sections.
5.4.9 Database Connection Pooling
When serving data from a spatial database connection pooling is an important aspect of achieving good performance. When GeoServer serves a request that involves loading data from a database table, a connection
must first be established with the database. This connection comes with a cost as it takes time to set up such
a connection.
The purpose served by a connection pool is to maintain connection to an underlying database between
requests. The benefit of which is that connection setup only need to occur once on the first request. Subsequent requests use existing connections and achieve a performance benefit as a result.
Whenever a data store backed by a database is added to GeoServer an internal connection pool is created.
This connection pool is configurable.
166
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
Connection pool options
max connections
min connections
validate
tions
connec-
fetch size
connection timeout
Test while idle
Evictor run periodicity
Max connection
idle time
Evictor tests per
run
The maximum number of connections the pool can hold. When the maximum
number of connections is exceeded, additional requests that require a database
connection will be halted until a connection from the pool becomes available. The
maximum number of connections limits the number of concurrent requests that
can be made against the database.
The minimum number of connections the pool will hold. This number of connections is held even when there are no active requests. When this number of connections is exceeded due to serving requests additional connections are opened until
the pool reaches its maximum size (described above).
Flag indicating whether connections from the pool should be validated before they
are used. A connection in the pool can become invalid for a number of reasons
including network breakdown, database server timeout, etc.. The benefit of setting
this flag is that an invalid connection will never be used which can prevent client
errors. The downside of setting the flag is that a performance penalty is paid in
order to validate connections.
The number of records read from the database in each network exchange. If set
too low (<50) network latency will affect negatively performance, if set too high it
might consume a significant portion of GeoServer memory and push it towards an
Out Of Memory error. Defaults to 1000.
Time, in seconds, the connection pool will wait before giving up its attempt to get
a new connection from the database. Defaults to 20 seconds.
Periodically test if the connections are still valid also while idle in the pool. Sometimes performing a test query using an idle connection can make the datastore
unavailable for a while. Often the cause of this troublesome behaviour is related
to a network firewall placed between GeoServer and the Database that force the
closing of the underlying idle TCP connections.
Number of seconds between idle object evictor runs.
Number of seconds a connection needs to stay idle before the evictor starts to consider closing it.
Number of connections checked by the idle connection evictor for each of its runs.
5.4.10 JNDI
Many data stores and connections in GeoServer have the option of utilizing Java Naming and Directory
Interface on JNDI. JNDI allows for components in a Java system to look up other objects and data by a
predefined name.
A common use of JNDI is to store a JDBC data source globally in a container. This has a few benefits.
First, it can lead to a much more efficient use of database resources. Database connections in Java are
very resource-intensive objects, so usually they are pooled. If each component that requires a database
connection is responsible for creating their own connection pool, resources will stack up fast. In addition,
often those resources are under-utilized and a component may not size its connection pool accordingly. A
more efficient method is to set up a global pool at the servlet container level, and have every component
that requires a database connection use that.
Furthermore, JNDI consolidates database connection configuration, as not every component that requires a
database connection needs to know any more details than the JNDI name. This is very useful for administrators who may have to change database parameters in a running system, as it allows the change to occur
in a single place.
5.4. Databases
167
GeoServer User Manual, Release 2.15.1
5.4.11 SQL Views
The traditional way to access database data is is to configure layers against either tables or database views.
Starting with GeoServer 2.1.0, layers can also be defined as SQL Views. SQL Views allow executing a
custom SQL query on each request to the layer. This avoids the need to create a database view for complex
queries.
Even more usefully, SQL View queries can be parameterized via string substitution. Parameter values can
be supplied in both WMS and WFS requests. Default values can be supplied for parameters, and input
values can be validated by Regular Expressions to eliminate the risk of SQL injection attacks.
Note: SQL Views are read-only, and thus cannot be updated by WFS-T transactions.
Creating a SQL View
In order to create a SQL View the administrator invokes the Create new layer page. When a database store
is selected, the usual list of tables and views available for publication appears, A link Configure new SQL
view. . . also appears:
Selecting the Configure new SQL view. . . link opens a new page where the SQL view query can be specified:
168
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
Note: The query can be any SQL statement that is valid as a subquery in a FROM clause (that is, select
* from () [as] vtable). This is the case for most SQL statements, but in some
databases special syntax may be needed to call stored procedures. Also, all the columns returned by the
SQL statement must have names. In some databases alias names are required for function calls.
When a valid SQL query has been entered, press the Refresh link in the Attributes table to get the list of the
attribute columns determined from the query:
GeoServer attempts to determine the geometry column type and the native SRID, but these should be
verified and corrected if necessary.
Note: Having a correct SRID (spatial reference id) is essential for spatial queries to work. In many spatial
databases the SRID is equal to the EPSG code for the specific spatial reference system, but this is not always
the case (for instance, Oracle has a number of non-EPSG SRID codes).
If stable feature ids are desired for the view’s features, one or more columns providing a unique id for the
features should be checked in the Identifier column. Always ensure these attributes generate a unique key,
or filtering and WFS requests will not work correctly.
Once the query and the attribute details are defined, press Save. The usual New Layer configuration page
will appear. If further changes to the view are required, the page has a link to the SQL View editor at the
bottom of the Data tab:
Once created, the SQL view layer is used in the same way as a conventional table-backed layer, with the
one limitation of being read-only.
5.4. Databases
169
GeoServer User Manual, Release 2.15.1
Warning: Saving the SQL view definition here is not sufficient, the layer containing it must be saved
as well for the change to have any effect. This is because the SQL view definition is actually just one
component of the layer/featuretype/coverage attributes.
Parameterizing SQL Views
A parametric SQL view is based on a SQL query containing named parameters. The values for the parameters can be provided dynamically in WMS and WFS requests using the viewparams request parameter.
Parameters can have default values specified, to handle the situation where they are not supplied in a request. Validation of supplied parameter values is supported by specifying validation regular expressions.
Parameter values are only accepted if they match the regular expression defined for them. Appropriate
parameter validation should always be used to avoid the risk of SQL injection attacks.
Warning: SQL View parameter substitution should be used with caution, since improperly validated
parameters open the risk of SQL injection attack. Where possible, consider using safer methods such as
dynamic filtering in the request, or Variable substitution in SLD.
Defining parameters
Within the SQL View query, parameter names are delimited by leading and trailing % signs. The parameters
can occur anywhere within the query text, including such uses as within SQL string constants, in place of
SQL keywords, or representing entire SQL clauses.
Here is an example of a SQL View query for a layer called popstates with two parameters, low and high:
Each parameter needs to be defined with its name, an optional default value, and a validation expression.
The Guess parameters from SQL link can be clicked to infer the query parameters automatically, or they can
be entered manually. The result is a table filled with the parameter names, default values and validation
expressions:
In this case the default values should be specified, since the query cannot be executed without values for the
parameters (because the expanded query select gid, state_name, the_geom from pgstates
170
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
where persons between and is invalid SQL). Since the use of the parameters in the SQL query requires their values to be positive integer numbers, the validation regular expressions are specified to allow
only numeric input (i.e. ^[\d]+$):
Once the parameters have been defined, the Attributes Refresh link is clicked to parse the query and retrieve the attribute columns. The computed geometry type and column identifier details can be corrected if
required. From this point on the workflow is the same as for a non-parameterized query.
Using a parametric SQL View
The SQL view parameters are specified by adding the viewparams parameter to the WMS GetMap or
the WFS GetFeature request. The viewparams argument is a list of key:value pairs, separated by
semicolons:
viewparams=p1:v1;p2:v2;...
If the values contain semicolons or commas these must be escaped with a backslash (e.g. \, and \;).
For example, the popstates SQL View layer can be displayed by invoking the Layer Preview. Initially no
parameter values are supplied, so the defaults are used and all the states are displayed,
To display all states having more than 20 million inhabitants the following parameter is added to the
GetMap request: &viewparams=low:20000000
To display all states having between 2 and 5 millions inhabitants the view parameters are:
&viewparams=low:2000000;high:5000000
Parameters can be provided for multiple layers by separating each parameter map with a comma:
&viewparams=l1p1:v1;l1p2:v2,l2p1:v1;l2p2:v2,...
The number of parameter maps must match the number of layers (featuretypes) included in the request.
5.4. Databases
171
GeoServer User Manual, Release 2.15.1
Parameters and validation
The value of a SQL View parameter can be an arbitrary string of text. The only constraint is that the attribute
names and types returned by the view query must never change. This makes it possible to create views
containing parameters representing complex SQL fragments. For example, using the view query select
* from pgstates %where% allows specifying the WHERE clause of the query dynamically. However,
this would likely require an empty validation expression. which presents a serious risk of SQL injection
attacks. This technique should only be used if access to the server is restricted to trusted clients.
In general, SQL parameters must be used with care. They should always include validation regular expressions that accept only the intended parameter values. Note that while validation expressions should
be constructed to prevent illegal values, they do not necessarily have to ensure the values are syntactically
correct, since this will be checked by the database SQL parser. For example:
• ^[\d\.\+-eE]+$ checks that a parameter value contains valid characters for floating-point numbers
(including scientific notation), but does not check that the value is actually a valid number
• [^;']+ checks that a parameter value does not contain quotes or semicolons. This prevents common
SQL injection attacks, but otherwise does not impose much limitation on the actual value
Resources for Validation Regular expressions
Defining effective validation regular expressions is important for security. Regular expressions are a complex topic that cannot be fully addressed here. The following are some resources for constructing regular
expressions:
• GeoServer uses the standard Java regular expression engine. The Pattern class Javadocs contain the
full specification of the allowed syntax.
• http://www.regular-expressions.info has many tutorials and examples of regular expressions.
• The myregexp applet can be used to test regular expressions online.
Place holder for the SQL WHERE clause
The SQL WHERE clause produced by GeoServer using the context filters, e.g. the bounding box filter of a
WMS query, will be added around the SQL view definition. This comes handy (better performance) when
we have extra operations that can be done on top of the rows filtered with the GeoServer produced filter
first.
A typical use case for this functionality is the execution of analytic functions on top of the filtered results:
172
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
SELECT STATION_NAME,
MEASUREMENT,
MEASUREMENT_TYPE,
LOCATION
FROM
(SELECT STATION_NAME,
MEASUREMENT,
MEASUREMENT_TYPE,
LOCATION,
ROW_NUMBER() OVER(PARTITION BY STATION_ID, MEASUREMENT_TYPE
ORDER BY TIME DESC) AS RANK
FROM
(SELECT st.id AS STATION_ID,
st.common_name AS STATION_NAME,
ob.value AS MEASUREMENT,
pr.param_name AS MEASUREMENT_TYPE,
ob.time AS TIME,
st.position AS LOCATION
FROM meteo.meteo_stations st
LEFT JOIN meteo.meteo_observations ob ON st.id = ob.station_id
LEFT JOIN meteo.meteo_parameters pr ON ob.parameter_id = pr.id
-- SQL WHERE clause place holder for GeoServer
WHERE 1 = 1 :where_clause:) AS stations_filtered) AS stations
WHERE RANK = 1;
A few restrictions apply when using the explicit :where_clause: place holder:
• it needs to be added in a position where all the attributes known by GeoServer are already present
• the :where_clause: can only appear once
When a WHERE clause place holder is present, GeoServer will always add an explicit AND at the beginning
of the produced WHERE clause. This allows the injection of the produced WHERE in the middle of complex
expressions if needed.
5.4.12 Controlling feature ID generation in spatial databases
Introduction
All spatial database data stores (PostGIS, Oracle, MySQL and so on) normally derive the feature ID from
the table primary key and assume certain conventions on how to locate the next value for the key in case a
new feature needs to be generated (WFS insert operation).
Common conventions rely on finding auto-increment columns (PostGIS) or finding a sequence that is
named after a specific convention such as
__SEQUENCE (Oracle case).
In case none of the above is found, normally the store will fall back on generating random feature IDs at
each new request, making the table unsuitable for feature ID based searches and transactions.
Metadata table description
These defaults can be overridden manually by creating a primary key metadata table that specifies which
columns to use and what strategy to use to generate new primary key values. The (schema qualified) table
5.4. Databases
173
GeoServer User Manual, Release 2.15.1
can be created with this SQL statement (this one is valid for PostGIS and ORACLE, adapt it to your specific
database, you may remove the check at the end if you want to):
--PostGIS DDL
CREATE TABLE my_schema.gt_pk_metadata (
table_schema VARCHAR(32) NOT NULL,
table_name VARCHAR(32) NOT NULL,
pk_column VARCHAR(32) NOT NULL,
pk_column_idx INTEGER,
pk_policy VARCHAR(32),
pk_sequence VARCHAR(64),
unique (table_schema, table_name, pk_column),
check (pk_policy in ('sequence', 'assigned', 'autogenerated'))
)
--ORACLE DDL
CREATE TABLE gt_pk_metadata (
table_schema VARCHAR2(32) NOT NULL,
table_name VARCHAR2(32) NOT NULL,
pk_column VARCHAR2(32) NOT NULL,
pk_column_idx NUMBER(38),
pk_policy VARCHAR2(32),
pk_sequence VARCHAR2(64),
constraint chk_pk_policy check (pk_policy in ('sequence', 'assigned',
,→'autogenerated')));
CREATE UNIQUE INDEX gt_pk_metadata_table_idx01 ON gt_pk_metadata (table_schema, table_
,→name, pk_column);
The table can be given a different name. In that case, the (schema qualified) name of the table must be
specified in the primary key metadata table configuration parameter of the store.
The following table describes the meaning of each column in the metadata table.
Column
table_schema
table_name
pk_column
pk_column_idx
pk_policy
pk_sequence
Description
Name of the database schema in which the table is located.
Name of the table to be published
Name of a column used to form the feature IDs
Index of the column in a multi-column key. In case multi column keys are needed
multiple records with the same table schema and table name will be used.
The new value generation policy, used in case a new feature needs to be added in
the table (following a WFS-T insert operation).
The name of the database sequence to be used when generating a new value for
the pk_column.
The possible values are:
• assigned. The value of the attribute in the newly inserted feature will be used (this assumes the “expose
primary keys” flag has been enabled)
• sequence. The value of the attribute will be generated from the next value of a sequence indicated in
the “pk_sequence” column.
• autogenerated. The column is an auto-increment one, the next value in the auto-increment will be used.
174
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
Using the metadata table with views
GeoServer can publish spatial views without issues, but normally results in two side effects:
• the view is treated as read only
• the feature IDs are randomly generated
The metadata table can also refer to views, just use the view name in the table_name column: this will
result in stable ids, and in databases supporting updatable views, it will also make the code treat the view
as writable (thus, enabling usage of WFS-T on it).
5.4.13 Custom SQL session start/stop scripts
Starting with version 2.1.4 GeoServer support custom SQL scripts that can be run every time GeoServer
grabs a connection from the connection pool, and every time the session is returned to the pool.
These scripts can be parametrized with the expansion of environment variables, which can be in turn set
into the OGC request parameters with the same mechanism as Variable substitution in SLD.
In addition to the parameters provided via the request the GSUSER variable is guaranteed to contain the
current GeoServer user, or be null if no authentication is available. This is useful if the SQL sessions scripts
are used to provide tight control over database access
The SQL script can expand environment variables using the ${variableName, defaultValue} syntax,
for example the following alters the current database user to be the same as the GeoServer current user, or
geoserver in case no user was authenticated
SET SESSION AUTHORIZATION ${GSUSER,geoserver}
5.4.14 Using SQL session scripts to control authorizations at the database level
GeoServer connects to a database via a connection pool, using the same rights as the user that is specified in
the connection pool setup. In a setup that provides a variety of services and tables the connection pool user
must have a rather large set of rights, such as table selection (WMS), table insert/update/delete (WFS-T)
and even table creation (data upload via RESTConfig, WPS Import process and eventual new processes
leveraging direct database connections).
What a user can do can be controlled by means of the GeoServer security subsystem, but in high security
setups this might not be considered enough, and a database level access control be preferred instead. In
these setups normally the connection pool user has limited access, such as simple read only access, while
specific users are allowed to perform more operations.
When setting up such a solution remember the following guidelines:
• The connection pool user must be able to access all table metadata regardless of whether it is able
to actually perform a select on the tables (dictionary tables/describe functionality must be always
accessible)
• The connection pool must see each and every column of tables and views, in other words, the structure
of the tables must not change as the current user changes
• the database users and the GeoServer user must be kept in synch with some external tools, GeoServer
provides no out of the box facilities
• during the GeoServer startup the code will access the database to perform some sanity checks, in that
moment there is no user authenticated in GeoServer so the code will run under whatever user was
specified as the “default value” for the GSUSER variable.
5.4. Databases
175
GeoServer User Manual, Release 2.15.1
• The user that administers GeoServer (normally admin, but it can be renamed, and other users given
the administration roles too) must also be a database user, all administrative access on the GeoServer
GUI will have that specific user controlling the session
Typical use cases:
• Give insert/update/delete rights only to users that must use WFS-T
• Only allow the administrator to create new tables
• Limit what rows of a table a user can see by using dynamic SQL views taking into account the current
user to decide what rows to return
To make a point in case, if we want the PostgreSQL session to run with the current GeoServer user credentials the following scripts will be used:
Fig. 5.125: Setting up session authorization for PostgreSQL
The first command makes the database session use either the current GeoServer user, or the geoserver
user if no authentication was available (anonymous user, or startup situation). The second command resets
the session to the rights of the connection pool user.
5.5 Cascaded service data
This section discusses how GeoServer can proxy external OGC services. This is known as cascading services.
GeoServer supports cascading the following services:
5.5.1 External Web Feature Server
GeoServer has the ability to load data from a remote Web Feature Server (WFS). This is useful if the remote
WFS lacks certain functionality that GeoServer contains. For example, if the remote WFS is not also a Web
Map Server (WMS), data from the WFS can be cascaded through GeoServer to utilize GeoServer’s WMS. If
the remote WFS has a WMS but that WMS cannot output KML, data can be cascaded through GeoServer’s
WMS to output KML.
Adding an external WFS
To connect to an external WFS, it is necessary to load it as a new datastore. To start, navigate to Stores →
Add a new store → Web Feature Server.
176
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
Fig. 5.126: Adding an external WFS as a store
5.5. Cascaded service data
177
GeoServer User Manual, Release 2.15.1
Option
Workspace
Description
Name of the workspace to contain the store. This will also be the prefix of all of the
layer names created from the store.
Data Source Name
Name of the store as known to GeoServer.
Description
Description of the store.
Enabled
Enables the store. If disabled, no data from the external WFS will be served.
GET_CAPABILITIES_URL
URL to access the capabilities document of the remote WFS.
PROTOCOL
When checked, connects with POST, otherwise uses GET.
USERNAME
The user name to connect to the external WFS.
PASSWORD
The password associated with the above user name.
ENCODING
The character encoding of the XML requests sent to the server. Defaults to UTF-8.
TIMEOUT
Time (in milliseconds) before timing out. Default is 3000.
BUFFER_SIZE
Specifies a buffer size (in number of features). Default is 10 features.
TRY_GZIP
Specifies that the server should transfer data using compressed HTTP if supported
by the server.
LENIENT
When checked, will try to render features that don’t match the appropriate schema.
Errors will be logged.
MAXFEATURES
Maximum amount of features to retrieve for each featuretype. Default is no limit.
AXIS_ORDER
Axis order used in result coordinates (It applies only to WFS 1.x.0 servers). Default
is Compliant.
AXIS_ORDER_FILTER
Axis order used in filter (It applies only to WFS 1.x.0 servers). Default is Compliant.
OUTPUTFORMAT Output format to request (instead of the default remote service one).
GML_COMPLIANCE_LEVEL
OCG GML compliance level. i.e. (simple feature) 0, 1 or 2. Default is 0.
GML_COMPATIBLE_TYPENAMES
Use Gml Compatible TypeNames (replace : by _). Default is no false.
USE_HTTP_CONNECTION_POOLING
Use connection pooling to connect to the remote WFS service. Also enables digest
authentcation.
When finished, click Save.
Configuring external WFS layers
When properly loaded, all layers served by the external WFS will be available to GeoServer. Before they can
be served, however, they will need to be individually configured as new layers. See the section on Layers
for how to add and edit new layers.
Connecting to an external WFS layer via a proxy server
In a corporate environment it may be necessary to connect to an external WFS through a proxy server. To
achieve this, various java variables need to be set.
For a Windows install running GeoServer as a service, this is done by modifying the wrapper.conf file. For
a default Windows install, modify C:\Program Files\GeoServer x.x.x\wrapper\wrapper.conf
similarly to the following.
# Java Additional Parameters
wrapper.java.additional.1=-Djetty.home=.
wrapper.java.additional.2=DGEOSERVER_DATA_DIR=”%GEOSERVER_DATA_DIR%”
wrapper.java.additional.3=Dhttp.proxySet=true
wrapper.java.additional.4=-Dhttp.proxyHost=maitproxy
wrapper.java.additional.5=-Dhttp.proxyPort=8080
wrapper.java.additional.6=Dhttps.proxyHost=maitproxy
wrapper.java.additional.7=-Dhttps.proxyPort=8080
wrapper.java.additional.8=-Dhttp.nonProxyHosts=”mait*|dpi*|localhost”
178
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
Note that the http.proxySet=true parameter is required. Also, the parameter numbers must be consecutive - ie. no gaps.
For a Windows install not running GeoServer as a service, modify startup.bat so that the java command runs with similar -D parameters.
For a Linux/UNIX install, modify startup.sh so that the java command runs with similar -D parameters.
5.5.2 Cascaded Web Feature Service Stored Queries
Stored query is a feature of Web Feature Services. It allows servers to serve pre-configured filter queries
or even queries that cannot be expressed as GetFeature filter queries. This feature of GeoServer allows to
create cascaded layers out of stored queries.
Stored queries are read-only, and layers derived from cascaded stored queries cannot be updated with
WFS-T.
Cascaded stored query parameters
The relationship between stored query parameters and the schema returned by the query is not well defined. For cascaded stored queries to work, the relationship between the query received by GeoServer and
the parameters passed to the stored query must be defined.
When you set up a layer based on a stored query, you have to select which stored query to cascade and
what values are passed to each parameter. Cascaded stored queries can leverage view parameters passed
to the query. This is similar to how arbitrary parameters are passed to SQL Views. GeoServer supports
multiple strategies to pass these values. See below for a full list.
Parameter type
No mapping
Blocked
Default
Static
CQL Expression
Explanation
The value of the view parameter will be passed as is to the stored query. No parameter will be passed if there is no view parameter of the same name.
This parameter will never be passed to the stored query
The specified value is used unless overwritten by a view parameter
The specified value is always used (view parameter value will be ignored)
An expression that will be evaluated on every request (see below for more details)
See Using a parametric SQL View for more details how clients pass view parameters to GeoServer.
CQL expressions
Parameter mappings configured as CQL expressions are evaluated for each request using a context derived
from the request query and the view parameters. General information on CQL expressions is available here
Expression.
The context contains the following properties that may be used in the expressions:
Property name
bboxMinX
bboxMinY
bboxMaxX
bboxMaxY
defaultSRS
viewparam:name
Explanation
Evaluates to a corner coordinate of the full extent of the query
Evaluates to the default SRS of the feature type
Evaluates to the value of the view parameter name in this query
5.5. Cascaded service data
179
GeoServer User Manual, Release 2.15.1
Configuring a cascaded stored query layer
In order to create a cascaded stored query layer the administrator invokes the Create new layer page. When
an External Web Feature Server is selected, the usual list of tables and views available for publication appears,
a link Configure Cascaded Stored Query. . . also appears:
Selecting the Configure Cascaded Stored Query. . . link opens a new page where the parameter mapping is set
up. By default all parameters are set up as No mapping.
5.5.3 External Web Map Server
GeoServer has the ability to proxy a remote Web Map Service (WMS). This process is sometimes known as
Cascading WMS. Loading a remote WMS is useful for many reasons. If you don’t manage or have access
180
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
to the remote WMS, you can now manage its output as if it were local. Even if the remote WMS is not
GeoServer, you can use GeoServer features to treat its output (watermarking, decoration, printing, etc).
To access a remote WMS, it is necessary to load it as a store in GeoServer. GeoServer must be able to access
the capabilities document of the remote WMS for the store to be successfully loaded.
Adding an external WMS
To connect to an external WMS, it is necessary to load it as a new store. To start, in the Web administration
interface, navigate to Stores → Add a new store → WMS. The option is listed under Other Data Sources.
Fig. 5.127: Adding an external WMS as a store
Fig. 5.128: Configuring a new external WMS store
5.5. Cascaded service data
181
GeoServer User Manual, Release 2.15.1
Option
Workspace
Data Source Name
Description
Enabled
Capabilities URL
User Name
Password
Max
concurrent
connections
Description
Name of the workspace to contain the store. This will also be the prefix of all of the
layer names published from the store. The workspace name on the remote WMS
is not cascaded.
Name of the store as known to GeoServer.
Description of the store.
Enables the store. If disabled, no data from the remote WMS will be served.
The full URL to access the capabilities document of the remote WMS.
If the WMS requires authentication, the user name to connect as.
If the WMS requires authentication, the password to connect with.
The maximum number of persistent connections to keep for this WMS.
When finished, click Save.
Configuring external WMS layers
When properly loaded, all layers served by the external WMS will be available to GeoServer. Before they
can be served, however, they will need to be individually configured (published) as new layers. See the
section on Layers for how to add and edit new layers. Once published, these layers will show up in the
Layer Preview and as part of the WMS capabilities document.
Features
Connecting a remote WMS allows for the following features:
• Dynamic reprojection. While the default projection for a layer is cascaded, it is possible to pass
the SRS parameter through to the remote WMS. Should that SRS not be valid on the remote server,
GeoServer will dynamically reproject the images sent to it from the remote WMS.
• GetFeatureInfo. WMS GetFeatureInfo requests will be passed to the remote WMS. If the remote WMS
supports the application/vnd.ogc.gml format the request will be successful.
• Full REST Configuration. See the REST section for more information about the GeoServer REST
interface.
Limitations
Layers served through an external WMS have some, but not all of the functionality of a local WMS.
• Layers cannot be styled with SLD.
• Alternate (local) styles cannot be used.
• Extra request parameters (time, elevation, cql_filter, etc.) cannot be used.
• GetLegendGraphic requests aren’t supported.
• Image format cannot be specified. GeoServer will attempt to request PNG images, and if that fails
will use the remote server’s default image format.
182
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
5.5.4 External Web Map Tile Server
GeoServer has the ability to proxy a remote Web Map Tile Service (WMTS). This process is sometimes
known as Cascading WMTS, even if the incoming requests follow the WMS protocol and the backing
service follows the WMTS one; the WMTS cascading functionality is more like a “protocol translator”,
where the different handled data (capabilities documents, images) are translated by the “WMTS cascading”
logic.
Loading a remote WMTS is useful for many reasons. If you don’t manage or have access to the remote
WMTS, you can now manage its output as if it were local. Even if you don’t have any control on the remote
WMTS, you can use GeoServer features to treat its output (watermarking, decoration, printing, etc).
To access a remote WMTS, it is necessary to load it as a store in GeoServer. GeoServer must be able to access
the capabilities document of the remote WMTS for the store to be successfully loaded.
Adding an external WMTS
To connect to an external WMTS, it is necessary to load it as a new store. To start, in the Web administration
interface, navigate to Stores → Add a new store → WMTS. The option is listed under Other Data Sources.
Fig. 5.129: Adding an external WMTS as a store
Option
Workspace
Data Source Name
Description
Enabled
Capabilities URL
User Name
Password
HTTP header name
HTTP header value
Max
concurrent
connections
Description
Name of the workspace to contain the store. This will also be the prefix of all of the
layer names published from the store.
Name of the store as known to GeoServer.
Description of the store.
Enables the store. If disabled, no data from the remote WMTS will be served.
The full URL to access the capabilities document of the remote WMTS.
If the WMTS requires authentication, the user name to connect as.
If the WMTS requires authentication, the password to connect with.
If the WMTS requires a custom HTTP header, the header name.
If the WMTS requires a custom HTTP header, the header value.
The maximum number of persistent connections to keep for this WMTS.
5.5. Cascaded service data
183
GeoServer User Manual, Release 2.15.1
Fig. 5.130: Configuring a new external WTMS store
When finished, click Save.
Configuring external WMTS layers
When properly loaded, all layers served by the external WMTS will be available to GeoServer. Before they
can be served, however, they will need to be individually configured (published) as new layers. See the
section on Layers for how to add and edit new layers. Once published, these layers will show up in the
Layer Preview and as part of the WMS capabilities document. If the WMTS layer has additional dimensions
(e.g. time), related info will be reported on the WMS capabilities as well.
Features
Connecting a remote WMTS allows for the following features:
• Dynamic reprojection. While the default projection for a layer is cascaded, it is possible to pass
the SRS parameter through to the remote WMS. Should that SRS not be valid on the remote server,
GeoServer will dynamically reproject the tiles sent to it from the remote WMTS.
• Full REST Configuration. See the REST section for more information about the GeoServer REST
interface.
Limitations
Layers served through an external WMTS have some, but not all of the functionality of a local layer.
• Layers cannot be styled with SLD.
184
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
• Alternate (local) styles cannot be used.
• GetFeatureInfo requests aren’t supported.
• GetLegendGraphic requests aren’t supported.
• Image format cannot be specified. GeoServer will attempt to request PNG images, and if that fails
will use the remote server’s default image format.
5.6 Application schemas
The application schema support (app-schema) extension provides support for Complex Features in
GeoServer WFS.
Note: You must install the app-schema plugin to use Application Schema Support.
GeoServer provides support for a broad selection of simple feature data stores, including property files,
shapefiles, and JDBC data stores such as PostGIS and Oracle Spatial. The app-schema module takes one or
more of these simple feature data stores and applies a mapping to convert the simple feature types into one
or more complex feature types conforming to a GML application schema.
Fig. 5.131: Three tables in a database are accessed using GeoServer simple feature support and converted into two
complex feature types.
The app-schema module looks to GeoServer just like any other data store and so can be loaded and used to
service WFS requests. In effect, the app-schema data store is a wrapper or adapter that converts a simple
feature data store into complex features for delivery via WFS. The mapping works both ways, so queries
against properties of complex features are supported.
5.6.1 Complex Features
To understand complex features, and why you would want use them, you first need to know a little about
simple features.
Simple features
A common use of GeoServer WFS is to connect to a data source such as a database and access one or more
tables, where each table is treated as a WFS simple feature type. Simple features contain a list of properties
that each have one piece of simple information such as a string or number. (Special provision is made for
geometry objects, which are treated like single items of simple data.) The Open Geospatial Consortium
5.6. Application schemas
185
GeoServer User Manual, Release 2.15.1
(OGC) defines three Simple Feature profiles; SF-0, SF-1, and SF-2. GeoServer simple features are close to
OGC SF-0, the simplest OGC profile.
GeoServer WFS simple features provide a straightforward mapping from a database table or similar structure to a “flat” XML representation, where every column of the table maps to an XML element that usually
contains no further structure. One reason why GeoServer WFS is so easy to use with simple features is that
the conversion from columns in a database table to XML elements is automatic. The name of each element
is the name of the column, in the namespace of the data store. The name of the feature type defaults to the
name of the table. GeoServer WFS can manufacture an XSD type definition for every simple feature type it
serves. Submit a DescribeFeatureType request to see it.
Benefits of simple features
• Easy to implement
• Fast
• Support queries on properties, including spatial queries on geometries
Drawbacks of simple features
• When GeoServer automatically generates an XSD, the XML format is tied to the database schema.
• To share data with GeoServer simple features, participants must either use the same database schema
or translate between different schemas.
• Even if a community could agree on a single database schema, as more data owners with different
data are added to a community, the number of columns in the table becomes unmanageable.
• Interoperability is difficult because simple features do not allow modification of only part of the
schema.
Simple feature example
For example, if we had a database table stations containing information about GPS stations:
| id | code |
name
|
location
|
+----+------+----------------+--------------------------+
| 27 | ALIC | Alice Springs | POINT(133.8855 -23.6701) |
| 4 | NORF | Norfolk Island | POINT(167.9388 -29.0434) |
| 12 | COCO | Cocos
| POINT(96.8339 -12.1883) |
| 31 | ALBY | Albany
| POINT(117.8102 -34.9502) |
GeoServer would then be able to create the following simple feature WFS response fragment:
ALICAlice Springs-23.6701 133.8855
• Every row in the table is converted into a feature.
186
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
• Every column in the table is converted into an element, which contains the value for that row.
• Every element is in the namespace of the data store.
• Automatic conversions are applied to some special types like geometries, which have internal structure, and include elements defined in GML.
Complex features
Complex features contain properties that can contain further nested properties to arbitrary depth. In particular, complex features can contain properties that are other complex features. Complex features can be
used to represent information not as an XML view of a single table, but as a collection of related objects of
different types.
Simple feature
Properties are single data item, e.g. text, number, geometry
XML view of a single table
Schema automatically generated based on database
One large type
Straightforward
Interoperability relies on simplicity and customisation
Complex feature
Properties can be complex, including complex
features
Collection of related identifiable objects
Schema agreed by community
Multiple different types
Richly featured data standards
Interoperability through standardization
Benefits of complex features
• Can define information model as an object-oriented structure, an application schema.
• Information is modelled not as a single table but as a collection of related objects whose associations
and types may vary from feature to feature (polymorphism), permitting rich expression of content.
• By breaking the schema into a collection of independent types, communities need only extend those
types they need to modify. This simplifies governance and permits interoperability between related
communities who can agree on common base types but need not agree on application-specific subtypes..
Drawbacks of complex features
• More complex to implement
• Complex responses might slower if more database queries are required for each feature.
• Information modelling is required to standardize an application schema. While this is beneficial, it
requires effort from the user community.
Complex feature example
Let us return to our stations table and supplement it with a foreign key gu_id that describes the relationship between the GPS station and the geologic unit to which it is physically attached:
5.6. Application schemas
187
GeoServer User Manual, Release 2.15.1
| id | code |
name
|
location
| gu_id |
+----+------+----------------+--------------------------+-------+
| 27 | ALIC | Alice Springs | POINT(133.8855 -23.6701) | 32785 |
| 4 | NORF | Norfolk Island | POINT(167.9388 -29.0434) | 10237 |
| 12 | COCO | Cocos
| POINT(96.8339 -12.1883) | 19286 |
| 31 | ALBY | Albany
| POINT(117.8102 -34.9502) | 92774 |
The geologic unit is is stored in the table geologicunit:
| gu_id |
urn
|
text
|
+-------+---------------------------------------+---------------------+
| 32785 | urn:x-demo:feature:GeologicUnit:32785 | Metamorphic bedrock |
...
The simple features approach would be to join the stations table with the geologicunit table into one
view and then deliver “flat” XML that contained all the properties of both. The complex feature approach
is to deliver the two tables as separate feature types. This allows the relationship between the entities to be
represented while preserving their individual identity.
For example, we could map the GPS station to a sa:SamplingPoint with a gsml:GeologicUnit. The
these types are defined in the following application schemas respectively:
• http://schemas.opengis.net/sampling/1.0.0/sampling.xsd
– Documentation: OGC 07-002r3: http://portal.opengeospatial.org/files/?artifact_id=22467
• http://www.geosciml.org/geosciml/2.0/xsd/geosciml.xsd
– Documentation: http://www.geosciml.org/geosciml/2.0/doc/
The complex feature WFS response fragment could then be encoded as:
Alice Springs
ALICMetamorphic bedrockurn:x,→demo:feature:GeologicUnit:32785-23.6701 133.8855
• The property sa:sampledFeature can reference any other feature type, inline (included in the response) or by reference (an xlink:href URL or URN). This is an example of the use of polymorphism.
• The property sa:relatedObservation refers to the same GeologicUnit as sa:sampledFeature,
but by reference.
• Derivation of new types provides an extension point, allowing information models to be reused and
extended in a way that supports backwards compatibility.
188
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
• Multiple sampling points can share a single GeologicUnit. Application schemas can also define multivalued properties to support many-to-one or many-to-many associations.
• Each GeologicUnit could have further properties describing in detail the properties of the rock, such
as colour, weathering, lithology, or relevant geologic events.
• The GeologicUnit feature type can be served separately, and could be uniquely identified through its
properties as the same instance seen in the SamplingPoint.
Portrayal complex features (SF0)
Portrayal schemas are standardized schemas with flat attributes, also known as simple feature level 0 (SF0).
Because a community schema is still required (e.g. GeoSciML-Portrayal), app-schema plugin is still used to
map the database columns to the attributes.
• WFS CSV output format is supported for complex features with portrayal schemas. At the moment,
propertyName selection is not yet supported with csv outputFormat, so it always returns the full set
of attributes.
• Complex features with nesting and multi-valued properties are not supported with WFS CSV output
format.
5.6.2 Installation
Application schema support is a GeoServer extension and is downloaded separately.
• Download the app-schema plugin zip file for the same version of GeoServer.
• Unzip the app-schema plugin zip file to obtain the jar files inside. Do not unzip the jar files.
• Place the jar files in the WEB-INF/lib directory of your GeoServer installation.
• Restart GeoServer to load the extension (although you might want to configure it first [see below]).
5.6.3 WFS Service Settings
There are two GeoServer WFS service settings that are strongly recommended for interoperable complex
feature services. These can be enabled through the Services → WFS page on the GeoServer web interface or
by manually editing the wfs.xml file in the data directory,
Canonical schema location
The default GeoServer behaviour is to encode WFS responses that include a schemaLocation for the WFS
schema that is located on the GeoServer instance. A client will not know without retrieving the schema
whether it is identical to the official schema hosted at schemas.opengis.net. The solution is to encode
the schemaLocation for the WFS schema as the canonical location at schemas.opengis.net.
To enable this option, choose one of these:
1. Either: On the Service → WFS page under Conformance check Encode canonical WFS schema location.
2. Or: Insert the following line before the closing tag in wfs.xml:
true
5.6. Application schemas
189
GeoServer User Manual, Release 2.15.1
Encode using featureMember
By default GeoServer will encode WFS 1.1 responses with multiple features in a single
gml:featureMembers element. This will cause invalid output if a response includes a feature at
the top level that has already been encoded as a nested property of an earlier feature, because there is no
single element that can be used to encode this feature by reference. The solution is to encode responses
using gml:featureMember.
To enable this option, choose one of these:
1. Either: On the Service → WFS page under Encode response with select Multiple “featureMember” elements.
2. Or: Insert the following line before the closing tag in wfs.xml:
true
5.6.4 Configuration
Configuration of an app-schema complex feature type requires manual construction of a GeoServer data
directory that contains an XML mapping file and a datastore.xml that points at this mapping file. The
data directory also requires all the other ancillary configuration files used by GeoServer for simple features.
GeoServer can serve simple and complex features at the same time.
Workspace layout
The GeoServer data directory contains a folder called workspaces with the following structure:
workspaces
- gsml
- SomeDataStore
- SomeFeatureType
- featuretype.xml
- datastore.xml
- SomeFeatureType-mapping-file.xml
Note: The folder inside workspaces must have a name (the workspace name) that is the same as the
namespace prefix (gsml in this example).
Datastore
Each data store folder contains a file datastore.xml that contains the configuration parameters of
the data store. To create an app-schema feature type, the data store must be configured to load
the app-schema service module and process the mapping file. These options are contained in the
connectionParameters:
• namespace defines the XML namespace of the complex feature type.
• url is a file: URL that gives the location of the app-schema mapping file relative to the root of the
GeoServer data directory.
• dbtype must be app-schema to trigger the creation of an app-schema feature type.
190
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
5.6.5 Mapping File
An app-schema feature type is configured using a mapping file that defines the data source for the feature
and the mappings from the source data to XPaths in the output XML.
Outline
Here is an outline of a mapping file:
...............
• namespaces defines all the namespace prefixes used in the mapping file.
• includedTypes (optional) defines all the included non-feature type mapping file locations that are
referred in the mapping file.
• sourceDataStores provides the configuration information for the source data stores.
• catalog is the location of the OASIS Catalog used to resolve XML Schema locations.
• targetTypes is the location of the XML Schema that defines the feature type.
• typeMappings give the relationships between the fields of the source data store and the elements of
the output complex feature.
Mapping file schema
• AppSchemaDataAccess.xsd is optional because it is not used by GeoServer. The presence of
AppSchemaDataAccess.xsd in the same folder as the mapping file enables XML editors to observe
its grammar and provide contextual help.
Settings
namespaces
The namespaces section defines all the XML namespaces used in the mapping file:
gsmlurn:cgi:xmlns:CGI:GeoSciML:2.0gmlhttp://www.opengis.net/gml
5.6. Application schemas
191
GeoServer User Manual, Release 2.15.1
xlinkhttp://www.w3.org/1999/xlink
includedTypes (optional)
Non-feature types (eg. gsml:CompositionPart is a data type that is nested in gsml:GeologicUnit) may be
mapped separately for its reusability, but we don’t want to configure it as a feature type as we don’t want
to individually access it. Related feature types don’t need to be explicitly included here as it would have its
own workspace configuration for GeoServer to find it. The location path in Include tag is relative to the
mapping file. For an example, if gsml:CompositionPart configuration file is located in the same directory
as the gsml:GeologicUnit configuration:
gsml_CompositionPart.xml
sourceDataStores
Every mapping file requires at least one data store to provide data for features. app-schema reuses
GeoServer data stores, so there are many available types. See Data Stores for details of data store configuration. For example:
datastore
...
...
If you have more than one DataStore in a mapping file, be sure to give them each a distinct id.
catalog (optional)
The location of an OASIS XML Catalog configuration file, given as a path relative to the mapping file. See
Application Schema Resolution for more information. For example:
../../../schemas/catalog.xml
targetTypes
The targetTypes section lists all the application schemas required to define the mapping. Typically only
one is required. For example:
192
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
http://www.geosciml.org/geosciml/2.0/xsd/geosciml.xsd
Mappings
typeMappings and FeatureTypeMapping
The typeMappings section is the heart of the app-schema module. It defines the mapping from
simple features to the the nested structure of one or more simple features. It consists of a list of
FeatureTypeMapping elements, which each define one output feature type. For example:
mappedfeature1datastoremappedfeaturegsml:MappedFeaturetruegsml:MappedFeature/gsml:shape/gml:Polygon
...
• mappingName is an optional tag, to identify the mapping in Feature Chaining when there are multiple
FeatureTypeMapping instances for the same type. This is solely for feature chaining purposes, and
would not work for identifying top level features.
• sourceDataStore must be an identifier you provided when you defined a source data store the
sourceDataStores section.
• sourceType is the simple feature type name. For example:
– a table or view name, lowercase for PostGIS, uppercase for Oracle.
– a property file name (without the .properties suffix)
• targetElement is the the element name in the target application schema. This is the same as the
WFS feature type name.
• isDenormalised is an optional tag (default true) to indicate whether this type contains denormalised data or not. If data is not denormalised, then app-schema will build a more efficient query to
apply the global feature limit. When combined with a low global feature limit (via Services –> WFS),
setting this option to false can prevent unnecessary processing and database lookups from taking
place.
• defaultGeometry can be used to explicitly define the attribute of the feature type that should be
used as the default geometry, this is more relevant in WMS than WFS. The default geometry XML path
can reference any attribute of the feature type, exactly the same path that would be used to reference
the desired property in a OGC filter. The path can reference a nested attribute belonging to a chained
feature having a zero or one relationship with the root feature type.
5.6. Application schemas
193
GeoServer User Manual, Release 2.15.1
attributeMappings and AttributeMapping
attributeMappings comprises a list of AttributeMapping elements:
..................
targetAttribute
targetAttribute is the XPath to the output element, in the context of the target element. For example,
if the containing mapping is for a feature, you should be able to map a gml:name property by setting the
target attribute:
gml:name
Multivalued attributes resulting from Denormalised sources are automatically encoded. If you wish to encode
multivalued attributes from different input columns as a specific instance of an attribute, you can use a
(one-based) index. For example, you can set the third gml:name with:
gml:name[3]
The reserved name FEATURE_LINK is used to map data that is not encoded in XML but is required for use
in Feature Chaining.
idExpression (optional)
A CQL expression that is used to set the custom gml:id of the output feature type. This should be the name
of a database column on its own. Using functions would cause an exception because it is not supported
with the default joining implementation.
Note: Every feature must have a gml:id. This requirement is an implementation limitation (strictly,
gml:id is optional in GML).
• If idExpression is unspecified, gml:id will be ., e.g.
MAPPEDFEATURE.1.
• In the absence of primary keys, this will be ., e.g.
MAPPEDFEATURE.fid--46fd41b8_1407138b56f_-7fe0.
• If using property files instead of database tables, the default gml:id will be the row key found before
the equals (“=”) in the property file, e.g. the feature with row “mf1=Mudstone|POINT(1 2)|. . . ” will
have gml:id mf1.
Note: gml:id must be an NCName.
194
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
sourceExpression (optional)
Use a sourceExpression tag to set the element content from source data. For example, to set the element
content from a column called DESCRIPTION:
DESCRIPTION
If sourceExpression is not present, the generated element is empty (unless set by another mapping).
You can use CQL expressions to calculate the content of the element. This example concatenated strings
from two columns and a literal:
strConCat(FIRST , strConCat(' followed by ', SECOND))
You can also use CQL functions for vocabulary translations.
Warning: Avoid use of CQL expressions for properties that users will want to query, because the
current implementation cannot reverse these expressions to generate efficient SQL, and will instead
read all features to calculate the property to find the features that match the filter query. Falling back
to brute force search makes queries on CQL-calculated expressions very slow. If you must concatenate
strings to generate content, you may find that doing this in your database is much faster.
linkElement and linkField (optional)
The presence of linkElement and linkField change the meaning of sourceExpression to a Feature
Chaining mapping, in which the source of the mapping is the feature of type linkElement with property
linkField matching the expression. For example, the following sourceExpression uses as the result
of the mapping the (possibly multivalued) gsml:MappedFeature for which gml:name[2] is equal to
the value of URN for the source feature. This is in effect a foreign key relation:
URNgsml:MappedFeaturegml:name[2]
The feature type gsml:MappedFeature might be defined in another mapping file. The linkField can
be FEATURE_LINK if you wish to relate the features by a property not exposed in XML. See Feature Chaining
for a comprehensive discussion.
For special cases, linkElement could be an OCQL function, and linkField could be omitted. See Polymorphism for further information.
targetAttributeNode (optional)
targetAttributeNode is required wherever a property type contains an abstract element and appschema cannot determine the type of the enclosed attribute.
In this example, om:result is of xs:anyType, which is abstract. We can use targetAttributeNode to
set the type of the property type to a type that encloses a non-abstract element:
5.6. Application schemas
195
GeoServer User Manual, Release 2.15.1
om:resultgml:MeasureTypeTOPAGExsi:type'gml:MeasureType'uom'http://www.opengis.net/def/uom/UCUM/0/Ma'
If the casting type is complex, the specific type is implicitly determined by the XPath in targetAttribute
and targetAttributeNode is not required. E.g., in this example om:result is automatically specialised as a
MappedFeatureType:
om:result/gsml:MappedFeature/gml:nameNAME
Although it is not required, we may still specify targetAttributeNode for the root node, and map the children attributes as per normal. This mapping must come before the mapping for the enclosed elements. By
doing this, app-schema will report an exception if a mapping is specified for any of the children attributes
that violates the type in targetAttributeNode. E.g.:
om:resultgsml:MappedFeatureTypeom:result/gsml:MappedFeature/gml:nameNAME
Note that the GML encoding rules require that complex types are never the direct property of another complex type; they are always contained in a property type to ensure that their type is encoded in a surrounding
element. Encoded GML is always type/property/type/property. This is also known as the GML “striping” rule. The consequence of this for app-schema mapping files is that targetAttributeNode must be
applied to the property and the type must be set to the XSD property type, not to the type of the contained
attribute (gsml:CGI_TermValuePropertyType not gsml:CGI_TermValueType). Because the XPath
refers to a property type not the encoded content, targetAttributeNode appears in a mapping with
targetAttribute and no other elements when using with complex types.
The XML encoder will encode nested complex features that are mapped to a complex type that does not
respect the GML striping rule. The Java configuration property encoder.relaxed can be set to false to
disable this behavior.
196
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
encodeIfEmpty (optional)
The encodeIfEmpty element will determine if an attribute will be encoded if it contains a null or empty
value. By default encodeIfEmpty is set to false therefore any attribute that does not contain a value will
be skipped:
true
encodeIfEmpty can be used to bring up attributes that only contain client properties such as
xlink:title.
isMultiple (optional)
The isMultiple element states whether there might be multiple values for this attribute, coming from
denormalised rows. Because the default value is false and it is omitted in this case, it is most usually seen
as:
true
For example, the table below is denormalised with NAME column having multiple values:
ID
gu.25678
gu.25678
NAME
Yaugher Volcanic Group 1
Yaugher Volcanic Group 2
DESCRIPTION
Olivine basalt, tuff, microgabbro
Olivine basalt, tuff, microgabbro
The configuration file specifies isMultiple for gml:name attribute that is mapped to the NAME column:
gml:nameNAMEtruecodeSpace'urn:ietf:rfc:2141'
The output produces multiple gml:name attributes for each feature grouped by the id:
Olivine basalt, tuff, microgabbroYaugher Volcanic Group 1Yaugher Volcanic Group 2
...
isList (optional)
The isList element states whether there might be multiple values for this attribute, concatenated as a list.
The usage is similar with isMultiple, except the values appear concatenated inside a single node instead
of each value encoded in a separate node. Because the default value is false and it is omitted in this case,
it is most usually seen as:
5.6. Application schemas
197
GeoServer User Manual, Release 2.15.1
true
For example, the table below has multiple POSITION for each feature:
ID
ID1.2
ID1.2
ID1.2
ID1.2
ID1.2
POSITION
1948-05
1948-06
1948-07
1948-08
1948-09
The configuration file uses isList on timePositionList attribute mapped to POSITION column:
csml:timePositionListPOSITIONtrue
The output produced:
1949-05 1949-06 1949-07 1949-08 1949-09
,→csml:timePositionList>
ClientProperty (optional, multivalued)
A mapping can have one or more ClientProperty elements which set XML attributes on the mapping
target. Each ClientProperty has a name and a value that is an arbitrary CQL expression. No OCQL
element is used inside value.
This example of a ClientProperty element sets the codeSpace XML attribute to the literal string
urn:ietf:rfc:2141. Note the use of single quotes around the literal string. This could be applied to
any target attribute of GML CodeType:
codeSpace'urn:ietf:rfc:2141'
When the GML association pattern is used to encode a property by reference, the xlink:href attribute is
set and the element is empty. This ClientProperty element sets the xlink:href XML attribute to to the
value of the RELATED_FEATURE_URN field in the data source (for example, a column in an Oracle database
table). This mapping could be applied to any property type, such a gml:FeaturePropertyType, or other
type modelled on the GML association pattern:
xlink:href
198
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
RELATED_FEATURE_URN
See the discussion in Feature Chaining for the special case in which xlink:href is created for multivalued
properties by reference.
CQL
CQL functions enable data conversion and conditional behaviour to be specified in mapping files.
• See CQL functions for information on additional functions provided by the app-schema plugin.
• The uDig manual includes a list of CQL functions:
– http://udig.refractions.net/confluence/display/EN/Constraint+Query+Language
• CQL string literals are enclosed in single quotes, for example 'urn:ogc:def:nil:OGC:missing'.
Database identifiers
When referring to database table/view names or column names, use:
• lowercase for PostGIS
• UPPERCASE for Oracle Spatial and ArcSDE
Denormalised sources
Multivalued properties from denormalised sources (the same source feature ID appears more than once)
are automatically encoded. For example, a view might have a repeated id column with varying name so
that an arbitrarily large number of gml:name properties can be encoded for the output feature.
Warning: Denormalised sources must grouped so that features with duplicate IDs are provided without
any intervening features. This can be achieved by ensuring that denormalised source features are sorted
by ID. Failure to observe this restriction will result in data corruption. This restriction is however not
necessary when using Joining Support For Performance because then ordering will happen automatically.
Attributes with cardinality 1..N
Consider the following two tables, the first table contains information related to meteorological stations:
ID
st.1
st.2
NAME
Station 1
Station 2
The second table contains tags that are associated with meteorological stations:
ID
tg.1
tg.2
tg.2
5.6. Application schemas
STATION_ID
st.1
st.1
st.2
TAG
temperature
wind
pressure
CODE
X1Y
X2Y
X3Y
199
GeoServer User Manual, Release 2.15.1
A station can have multiple tags, establishing a one to many relationship between stations and tags, the
GML representation of the first station should look like this:
(...)
Station 1temperaturewind
(...)
Mappings with a one to many relationship are supported with a custom syntax in JDBC based data stores
and Apache Solr data store.
SQL based data stores
When using JDBC based data stores attributes with a 1..N relationship can be mapped like this:
(...)
st:tagIDTAGSSTATION_IDTAGst:codeCODE
(...)
The targetValue refers to the value of the element, the client property is mapped with the
usual syntax. Behind the scenes App-Schema will take care of associating the st:code attribute value with
the correct tag.
Apache Solr
When using Apache Solr data stores, 1..N relationships can be handled with multiValued fields and
mapped like this:
(...)
st:tagTAGst:codeCODE
(...)
200
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
External Apache Solr Index
Is possible to use an external Apache Solr index to speed up text based searches. Consider the following
WFS GetFeatureRequest:
st:Station/st:measurement/st:Measurement/st:description
,→fes:ValueReference>
*high*
This request will return all the stations that have at least one measurement that contains the text high in its
description. This type of text based queries are (usually) quite expensive to execute in relational data bases.
Apache Solr is a well known open source project that aims to solve those type of performance issues, it
allow us to index several fields and efficiently query those fields. Although Apache Solr allow us to index
several types of fields, e.g. numbers or even latitudes longitudes, where it really shines is when dealing
with text fields and text based queries.
The goal of external indexes is to allow App-Schema to take advantage of Apache Solr text searches performance and at the same time to take advantage of relational databases relational capabilities. In practice, this
means that the full data will be stored in the relational database and we will only need to index in Apache
Solr the fields we need to improve our text based queries.
Using the stations use case as an example, our data will be stored in a relational database, e.g. PostgreSQL,
and we will index the possible descriptions measurements values in an Apache Solr index.
Our mapping file will look like this:
gmlhttp://www.opengis.net/gml/3.2sthttp://www.stations.org/1.0stations_solrhttp://localhost:8983/solr/stations_indexstations_db
5.6. Application schemas
201
GeoServer User Manual, Release 2.15.1
dbtypepostgisng./stations.xsdstations_dbstationsst:Stationstations_solrstations_indexst:Stationiddescription_txtFEATURE_LINK[1]station_id
To be able to use an external Apache Solr index, we need at least to:
• declare the Solr data store and the index: this is done in the root feature type mapping, e.g. st:Station.
• map the Solr index field that matches the database primary key: this is done id mapping of the root
feature type, e.g.“id“.
• map each attribute that is indexed in Apache Solr: this is done using the indexField element, e.g
description_txt.
Is worth mentioning that if an external Solr index was defined, App-Schema will always query the external
Solr index first and then query the relational database.
5.6.6 Application Schema Resolution
To be able to encode XML responses conforming to a GML application schema, the app-schema plugin
must be able to locate the application schema files (XSDs) that define the schema. This page describes the
schema resolution process.
Schema downloading is now automatic for most users
GeoServer will automatically download and cache (see Cache below) all the schemas it needs the first time
it starts if:
1. All the application schemas you use are accessed via http/https URLs, and
2. Your GeoServer instance is deployed on a network that permits it to download them.
Note: This is the recommended way of using GeoServer app-schema for most users.
If cached downloading is used, no manual handling of schemas will be required. The rest of this page is for
those with more complicated arrangements, or who wish to clear the cache.
Resolution order
The order of sources used to resolve application schemas is:
5.6. Application schemas
203
GeoServer User Manual, Release 2.15.1
1. OASIS Catalog
2. Classpath
3. Cache
Every attempt to load a schema works down this list, so imports can be resolved from sources other than
that used for the originating document. For example, an application schema in the cache that references a
schema found in the catalog will use the version in the catalog, rather than caching it. This allows users to
supply unpublished or modified schemas sourced from, for example, the catalog, at the cost of interoperability (how do WFS clients get them?).
OASIS Catalog
An OASIS XML Catalog is a standard configuration file format that instructs an XML processing system
how to process entity references. The GeoServer app-schema resolver uses catalog URI semantics to locate
application schemas, so uri or rewriteURI entries should be present in your catalog. The optional mapping file catalog element provides the location of the OASIS XML Catalog configuration file, given as a
path relative to the mapping file, for example:
../../../schemas/catalog.xml
Earlier versions of the app-schema plugin required all schemas to be present in the catalog. This is no
longer the case. Because the catalog is searched first, existing catalog-based deployments will continue to
work as before.
To migrate an existing GeoServer app-schema deployment that uses an OASIS Catalog to instead use
cached downloads (see Cache below), remove all catalog elements from your mapping files and restart
GeoServer.
Classpath
Java applications such as GeoServer can load resources from the Java classpath. GeoServer app-schema uses
a simple mapping from an http or https URL to a classpath resource location. For example, an application
schema published at http://schemas.example.org/exampleml/exml.xsd would be found on the
classpath if it was stored either:
• at /org/example/schemas/exampleml/exml.xsd in a JAR file on the classpath (for example, a
JAR file in WEB-INF/lib) or,
• on the local filesystem at WEB-INF/classes/org/example/schemas/exampleml/exml.xsd .
The ability to load schemas from the classpath is intended to support testing, but may be useful to users
whose communities supply JAR files containing their application schemas.
Cache
If an application schema cannot be found in the catalog or on the classpath, it is downloaded from the
network and stored in a subdirectory app-schema-cache of the GeoServer data directory.
• Once schemas are downloaded into the cache, they persist indefinitely, including over GeoServer
restarts.
• No attempt will be made to retrieve new versions of cached schemas.
• To clear the cache, remove the subdirectory app-schema-cache of the GeoServer data directory and
restart GeoServer.
204
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
GeoServer app-schema uses a simple mapping from an http or https URL to local filesystem path.
For example, an application schema published at http://schemas.example.org/exampleml/exml.
xsd would be downloaded and stored as app-schema-cache/org/example/schemas/exampleml/
exml.xsd . Note that:
• Only http and https URLs are supported.
• Port numbers, queries, and fragments are ignored.
If your GeoServer instance is deployed on a network whose firewall rules prevent outgoing TCP connections on port 80 (http) or 443 (https), schema downloading will not work. (For security reasons, some
service networks [“demilitarised zones”] prohibit such outgoing connections.) If schema downloading is
not permitted on your network, there are three solutions:
1. Either: Install and configure GeoServer on another network that can make outgoing TCP connections,
start GeoServer to trigger schema download, and then manually copy the app-schema-cache directory to the production server. This is the easiest option because GeoServer automatically downloads
all the schemas it needs, including dependencies.
2. Or: Deploy JAR files containing all required schema files on the classpath (see Classpath above).
3. Or: Use a catalog (see OASIS Catalog above).
Warning: System property “schema.cache.dir” with a cache directory location is required for using a
mapping file from a remote URL with ‘http://’ or ‘https://’ protocol.
5.6.7 Supported GML Versions
GML 3.1.1
• GML 3.1.1 application schemas are supported for WFS 1.1.0.
• Clients must specify WFS 1.1.0 in requests because the GeoServer default is WFS 2.0.0.
• GET URLs must contain version=1.1.0 to set the WFS version to 1.1.0.
GML 3.2.1
• GML 3.2.1 application schemas are supported for WFS 1.1.0 and (incomplete) WFS 2.0.0.
• Some WFS 2.0.0 features not in WFS 1.1.0 such as GetFeatureById are not yet supported.
• Clients using WFS 1.1.0 must specify WFS 1.1.0 in requests and select the gml32 output format for
GML 3.2.1.
• To use WFS 1.1.0 for GML 3.2.1, GET URLs must contain version=1.1.0 to set the WFS version to
1.1.0 and outputFormat=gml32 to set the output format to GML 3.2.1.
• The default WFS version is 2.0.0, for which the default output format is GML 3.2.1.
• All GML 3.2.1 responses are contained in a WFS 2.0.0 FeatureCollection element, even for WFS
1.1.0 requests, because a WFS 1.1.0 FeatureCollection cannot contain GML 3.2.1 features.
5.6. Application schemas
205
GeoServer User Manual, Release 2.15.1
Secondary namespace for GML 3.2.1 required
GML 3.2.1 WFS responses are delivered in a WFS 2.0.0 FeatureCollection. Unlike WFS 1.1.0, WFS 2.0.0
does not depend explicitly on any GML version. As a consequence, the GML namespace is secondary and
must be defined explicitly as a secondary namespace. See Secondary Namespaces for details.
For example, to use the prefix gml for GML 3.2, create workspaces/gml/namespace.xml containing:
gml_namespacegmlhttp://www.opengis.net/gml/3.2
and workspaces/gml/workspace.xml containing:
gml_workspacegml
Failure to define the gml namespace prefix with a secondary namespace will result in errors like:
java.io.IOException: The prefix "null" for element "null:name" is not bound.
while encoding a response (in this case one containing gml:name), even if the namespace prefix is defined
in the mapping file.
GML 3.2.1 geometries require gml:id
GML 3.2.1 requires that all geometries have a gml:id. While GeoServer will happily encode WFS responses without gml:id on geometries, these will be schema-invalid. Encoding a gml:id on a geometry
can be achieved by setting an idExpression in the mapping for the geometry property. For example,
gsml:shape is a geometry property and its gml:id might be generated with:
gsml:shapestrConcat('shape.', getId())SHAPE
In this example, getId() returns the gml:id of the containing feature, so each geometry will have a
unique gml:id formed by appending the gml:id of the containing feature to the string "shape.".
If a multigeometry (such as a MultiPoint or MultiSurface) is assigned a gml:id of (for example)
parentid, to permit GML 3.2.1 schema-validity, each geometry that the multigeometry contains will be
automatically assigned a gml:id of the form parentid.1, parentid.2, . . . in order.
GML 3.3
The proposed GML 3.3 is itself a GML 3.2.1 application schema; preliminary testing with drafts of GML 3.3
indicates that it works with app-schema as expected.
206
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
5.6.8 Secondary Namespaces
What is a secondary namespace?
A secondary namespace is one that is referenced indirectly by the main schema, that is, one schema imports
another one as shown below:
a.xsd imports b.xsd
b.xsd imports c.xsd
(using a, b and c as the respective namespace prefixes for a.xsd, b.xsd and c.xsd):
a.xsd declares b:prefix
b.xsd declares c:prefix
The GeoTools encoder does not honour these namespaces and writes out:
"a:" , "b:" but NOT "c:"
The result is c’s element being encoded as:
When to configure for secondary namespaces
If your application spans several namespaces which may be very common in application schemas.
A sure sign that calls for secondary namespace configuration is when prefixes for namespaces are printed
out as the literal string “null” or error messages like:
java.io.IOException: The prefix "null" for element "null:something" is not bound.
Note: When using secondary namespaces, requests involving complex featuretypes must be made to the
global OWS service only, not to Virtual Services. This is because virtual services are restricted to a single
namespace, and thus are not able to access secondary namespaces.
In order to allow GeoServer App-Schema to support secondary namespaces, please follow the steps outlined below:
Using the sampling namespace as an example.
Step 1:Create the Secondary Namespace folder
Create a folder to represent the secondary namespace in the data/workspaces directory, in our example
that will be the “sa” folder.
Step 2:Create files
Create two files below in the “sa” folder:
1. namespace.xml
2. workspace.xml
5.6. Application schemas
207
GeoServer User Manual, Release 2.15.1
Step 3:Edit content of files
Contents of these files are as follows:
namespace.xml(uri is a valid uri for the secondary namespace, in this case the sampling namespace uri):
sa_workspacesahttp://www.opengis.net/sampling/1.0
workspace.xml:
sa_workspacesa
That’s it.
Your workspace is now configured to use a Secondary Namespace.
5.6.9 CQL functions
CQL functions enable data conversion and conditional behaviour to be specified in mapping files. Some of
these functions are provided by the app-schema plugin specifically for this purpose.
• The uDig manual includes a list of CQL functions:
– http://udig.refractions.net/confluence/display/EN/Constraint%20Query%20Language.html
• CQL string literals are enclosed in single quotes, for example 'urn:ogc:def:nil:OGC:missing'.
• Single quotes are represented in CQL string literals as two single quotes, just as in SQL. For example,
'yyyy-MM-dd''T''HH:mm:ss''Z''' for the string yyyy-MM-dd'T'HH:mm:ss'Z'.
Vocabulary translation
This section describes how to serve vocabulary translations using some function expressions in application
schema mapping file. If you’re not familiar with application schema mapping file, read Mapping File.
Recode
This is similar to if_then_else function, except that there is no default clause. You have to specify a translation
value for every vocabulary key.
Syntax:
Recode(COLUMN_NAME, key1, value1, key2, value2,...)
• COLUMN_NAME: column name to get values from
Example:
208
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
gml:nameRecode(ABBREVIATION, '1GRAV',
,→'urn:cgi:classifier:CGI:SimpleLithology:2008:gravel',
'1TILL',
,→'urn:cgi:classifier:CGI:SimpleLithology:2008:diamictite',
'6ALLU',
,→'urn:cgi:classifier:CGI:SimpleLithology:2008:sediment')
The above example will map gml:name value to urn:cgi:classifier:CGI:SimpleLithology:2008:gravel if the ABBREVIATION column value is 1GRAV.
Categorize
This is more suitable for numeric keys, where the translation value is determined by the key’s position
within the thresholds.
Syntax:
Categorize(COLUMN_NAME, default_value, threshold 1, value 1, threshold 2, value 2, ...
,→, [preceding/succeeding])
• COLUMN_NAME: data source column name
• default_value: default value to be mapped if COLUMN_NAME value is not within the threshold
• threshold(n): threshold value
• value(n): value to be mapped if the threshold is met
• preceding/succeeding:
– optional, succeeding is used by default if not specified.
– not case sensitive.
– preceding: value is within threshold if COLUMN_NAME value > threshold
– succeeding: value is within threshold if COLUMN_NAME value >= threshold
Example:
gml:descriptionCategorize(CGI_LOWER_RANGE, 'missing_value', 1000, 'minor', 5000,
,→'significant')
The above example means gml:description value would be significant if CGI_LOWER_RANGE column
value is >= 5000.
5.6. Application schemas
209
GeoServer User Manual, Release 2.15.1
Vocab
This function is more useful for bigger vocabulary pairs. Instead of writing a long key-to-value pairs in the
function, you can keep them in a separate properties file. The properties file serves as a lookup table to the
function. It has no header, and only contains the pairs in ”=” format.
Syntax:
Vocab(COLUMN_NAME, properties file)
• COLUMN_NAME: column name to get values from
• properties file: absolute path of the properties file
Example:
Properties file:
1GRAV=urn:cgi:classifier:CGI:SimpleLithology:2008:gravel
1TILL=urn:cgi:classifier:CGI:SimpleLithology:2008:diamictite
6ALLU=urn:cgi:classifier:CGI:SimpleLithology:2008:sediment
Mapping file:
gml:nameVocab(ABBREVIATION, strconcat('${config.parent}', '/mapping.properties'))
,→
The above example will map gml:name to urn:cgi:classifier:CGI:SimpleLithology:2008:gravel if ABBREVIATION value is 1GRAV.
This example uses the config.parent predefined interpolation property to specify a vocabulary properties file in the same directory as the mapping file. See Property Interpolation for details.
Geometry creation
toDirectPosition
This function converts double values to DirectPosition geometry type. This is needed when the data
store doesn’t have geometry type columns. This function expects:
Literal 'SRS_NAME' (optional)
Expression expression of SRS name if 'SRS_NAME' is present as the first argument
Expression name of column pointing to first double value
Expression name of column pointing to second double value (optional, only for 2D)
ToEnvelope
ToEnvelope function can take in the following set of parameters and return as either Envelope or
ReferencedEnvelope type:
210
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
Option 1 (1D Envelope):
ToEnvelope(minx,maxx)
Option 2 (1D Envelope with crsname):
ToEnvelope(minx,maxx,crsname)
Option 3 (2D Envelope):
ToEnvelope(minx,maxx,miny,maxy)
Option 4 (2D Envelope with crsname):
ToEnvelope(minx,maxx,miny,maxy,crsname)
toPoint
This function converts double values to a 2D Point geometry type. This is needed when the data store
doesn’t have geometry type columns. This function expects:
Literal 'SRS_NAME' (optional)
Expression expression of SRS name if 'SRS_NAME' is present as the first argument
Expression name of column pointing to first double value
Expression name of column pointing to second double value
Expression expression of gml:id (optional)
toLineString
This function converts double values to 1D LineString geometry type. This is needed to express 1D borehole
intervals with custom (non EPSG) CRS.
Literal 'SRS_NAME' (EPSG code or custom SRS)
Expression name of column pointing to first double value
Expression name of column pointing to second double value
Reference
toXlinkHref
This function redirects an attribute to be encoded as xlink:href, instead of being encoded as a full attribute.
This is useful in polymorphism, where static client property cannot be used when the encoding is conditional. This function expects:
Expression REFERENCE_VALUE (could be another function or literal)
5.6. Application schemas
211
GeoServer User Manual, Release 2.15.1
Date/time formatting
FormatDateTimezone
A function to format a date/time using a SimpleDateFormat pattern in a time zone supported by Java. This
function improves on dateFormat, which formats date/time in the server time zone and can produce
unintended results. Note that the term “date” is derived from a Java class name; this class represents a
date/time, not just a single day.
Syntax:
FormatDateTimezone(pattern, date, timezone)
pattern formatting pattern supported by SimpleDateFormat, for example 'yyyy-MM-dd'.
Use
two single quotes to include a literal single quote in a CQL string literal, for example
'yyyy-MM-dd''T''HH:mm:ss''Z'''.
date the date/time to be formatted or its string representation, for example '1948-01-01T00:00:00Z'.
An exception will be returned if the date is malformed (and not null). Database types with time zone
information are recommended.
timezone the name of a time zone supported by Java, for example 'UTC' or 'Canada/Mountain'. Note
that unrecognised timezones will silently be converted to UTC.
This function returns null if any parameter is null.
This example formats date/times from a column POSITION in UTC for inclusion in a csml:TimeSeries:
csml:timePositionListFormatDateTimezone('yyyy-MM-dd''T''HH:mm:ss''Z''', POSITION, 'UTC')
,→OCQL>
true
5.6.10 Property Interpolation
Interpolation in this context means the substitution of variables into strings. GeoServer app-schema supports the interpolation of properties (the Java equivalent of environment variables) into app-schema mapping files. This can be used, for example, to simplify the management of database connection parameters
that would otherwise be hardcoded in a particular mapping file. This enables data directories to be given to
third parties without inapplicable authentication or system configuration information. Externalising these
parameters make management easier.
Defining properties
• If the system property app-schema.properties is not set, properties are loaded from WEB-INF/
classes/app-schema.properties (or another resource /app-schema.properties on the
classpath).
• If the system property app-schema.properties is set, properties are loaded from the file named
as the value of the property. This is principally intended for debugging, and is designed to be used in
an Eclipse launch configuration.
212
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
– For example, if the JVM is started with -Dapp-schema.properties=/path/to/some/
local.properties, properties are loaded from /path/to/some/local.properties.
• System properties override properties defined in a configuration file, so if you define -Dsome.
property at the java command line, it will override a value specified in the app-schema.
properties file. This is intended for debugging, so you can set a property file in an Eclipse launch
configuration, but override some of the properties contained in the file by setting them explicitly as
system properties.
• All system properties are available for interpolation in mapping files.
Predefined properties
If not set elsewhere, the following properties are set for each mapping file:
• config.file is set to the name of the mapping file
• config.parent is set to the name of the directory containing the mapping file
Using properties
• Using ${some.property} anywhere in the mapping file will cause it to be replaced by the value of
the property some.property.
• It is an error for a property that has not been set to be used for interpolation.
• Interpolation is performed repeatedly, so values can contain new interpolations. Use this behaviour
with caution because it may cause an infinite loop.
• Interpolation is performed before XML parsing, so can be used to include arbitrary chunks of XML.
Example of property interpolation
This example defines an Oracle data store, where the connection parameter are interpolated from properties:
datastoredbtypeOraclehost${example.host}port1521database${example.database}
5.6. Application schemas
213
GeoServer User Manual, Release 2.15.1
user${example.user}passwd${example.passwd}
Example property file
This sample property file gives the property values that are interpolated into the mapping file fragment
above. These properties can be installed in WEB-INF/classes/app-schema.properties in your
GeoServer installation:
example.host = database.example.com
example.database = example
example.user = dbuser
example.passwd = s3cr3t
5.6.11 Data Stores
The app-schema Mapping File requires you to specify your data sources in the sourceDataStores section.
For GeoServer simple features, these are configured using the web interface, but because app-schema lacks
a web configuration interface, data stores must be configured by editing the mapping file.
Many configuration options may be externalised through the use of Property Interpolation.
The DataStore element
A DataStore configuration consists of
• an id, which is an opaque identifier used to refer to the data store elsewhere in a mapping file, and
• one or more Parameter elements, which each contain the name and value of one parameter, and
are used to configure the data store.
An outline of the DataStore element:
datastore......
...
Parameter order is not significant.
214
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
Database options
Databases such as PostGIS, Oracle, and ArcSDE share some common or similar configuration options.
name
dbtype
host
port
database
instance
schema
user
passwd
Expose
primary keys
Meaning
Database type
Host name or IP address of
database server
TCP port on database server
PostGIS/Oracle database
ArcSDE instance
The database schema
The user name used to login to the
database server
The password used to login to the
database server
Columns with primary keys available for mapping
value examples
postgisng, Oracle, arcsde
database.example.org, 192.168.3.12
Default if omitted: 1521 (Oracle), 5432 (PostGIS), 5151 (ArcSDE)
Default is false, set to true to use primary
key columns in mapping
PostGIS
Set the parameter dbtype to postgisng to use the PostGIS NG (New Generation) driver bundled with
GeoServer 2.0 and later.
Example:
datastoredbtypepostgisnghostpostgresql.example.orgport5432databasetestusertestpasswdtest
5.6. Application schemas
215
GeoServer User Manual, Release 2.15.1
Note: PostGIS support is included in the main GeoServer bundle, so a separate plugin is not required.
Oracle
Set the parameter dbtype to Oracle to use the Oracle Spatial NG (New Generation) driver compatible
with GeoServer 2.0 and later.
Example:
datastoredbtypeOraclehostoracle.example.orgport1521databasedemodbuserorauserpasswds3cr3t
Note: You must install the Oracle plugin to connect to Oracle Spatial databases.
ArcSDE
This example connects to an ArcSDE database:
datastore
216
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
dbtypearcsdeserverarcsde.example.orgport5151instancesdeuserdemopasswords3cr3tdatastore.allowNonSpatialTablestrue
The use of non-spatial tables aids delivery of application schemas that use non-spatial properties.
Note: You must install the ArcSDE plugin to connect to ArcSDE databases.
Shapefile
Shapefile data sources are identified by the presence of a parameter url, whose value should be the file
URL for the .shp file.
In this example, only the url parameter is required. The others are optional:
shapefileurlfile:/D:/Workspace/shapefiles/VerdeRiverBuffer.shpmemory mapped bufferfalsecreate spatial indextrue
5.6. Application schemas
217
GeoServer User Manual, Release 2.15.1
charsetISO-8859-1
Note: The url in this case is an example of a Windows filesystem path translated to URL notation.
Note: Shapefile support is included in the main GeoServer bundle, so a separate plugin is not required.
Property file
Property files are configured by specifying a directory that is a file: URI.
• If the directory starts with file:./ it is relative to the mapping file directory. (This is an invalid URI,
but it works.)
For example, the following data store is used to access property files in the same directory as the mapping
file:
propertyfiledirectoryfile:./
A property file data store contains all the feature types stored in .properties files in the directory. For
example, if the directory contained River.properties and station.properties, the data store would be able
to serve them as the feature types River and station. Other file extensions are ignored.
Note: Property file support is included in the main GeoServer bundle, so a separate plugin is not required.
JNDI
Defining a JDBC data store with a jndiReferenceName allows you to use a connection pool provided
by your servlet container. This allows detailed configuration of connection pool parameters and sharing of
connections between data sources, and even between servlets.
To use a JNDI connection provider:
1. Specify a dbtype parameter to to indicate the database type. These values are the same as for the
non-JNDI examples above.
2. Give the jndiReferenceName you set in your servlet container. Both the abbreviated form jdbc/
oracle form, as in Tomcat, and the canonical form java:comp/env/jdbc/oracle are supported.
218
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
This example uses JNDI to obtain Oracle connections:
datastoredbtypeOraclejndiReferenceNamejdbc/oracle
Your servlet container my require you to add a resource-ref section at the end of your geoserver/
WEB-INF/web.xml. (Tomcat requires this, Jetty does not.) For example:
Oracle Spatial Datasourcejdbc/oraclejavax.sql.DataSourceContainer
Here is an example of a Tomcat 6 context in /etc/tomcat6/server.xml that includes an Oracle connection pool:
Firewall timeouts can silently sever idle connections to the database and cause GeoServer to hang. If there is
a firewall between GeoServer and the database, a connection pool configured to shut down idle connections
before the firewall can drop them will prevent GeoServer from hanging. This JNDI connection pool is
5.6. Application schemas
219
GeoServer User Manual, Release 2.15.1
configured to shut down idle connections after 5 to 10 minutes.
See also Setting up a JNDI connection pool with Tomcat.
Expose primary keys
By default, GeoServer conceals the existence of database columns with a primary key. To make such
columns available for use in app-schema mapping files, set the data store parameter Expose primary
keys to true:
Expose primary keystrue
This is known to work with PostGIS, Oracle, and JNDI data stores.
MongoDB
The data store configuration for a MongoDB data base will look like this:
data_sourcedata_storeMONGO_DB_URLnamespaceNAME_SPACEschema_storeSCHEMA_STOREdata_store_typecomplex
Check MongoDB Tutorial for a more detailed description about how to use MongoDB with app-schema.
Note: You must install the MongoDB plugin to connect to MongoDB databases.
220
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
5.6.12 Feature Chaining
Scope
This page describes the use of “Feature Chaining” to compose complex features from simpler components,
and in particular to address some requirements that have proven significant in practice.
• Handling multiple cases of multi-valued properties within a single Feature Type
• Handing nesting of multi-valued properties within other multi-valued properties
• Linking related (through association) Feature Types, and in particular allowing re-use of the related
features types (for example the O&M pattern has relatedObservation from a samplingFeature, but
Observation may be useful in its own right)
• Encoding the same referenced property object as links when it appears in multiple containing features
• Eliminating the need for large denormalized data store views of top level features and their related
features. Denormalized views would still be needed for special cases, such as many-to-many relationships, but won’t be as large.
For non-application schema configurations, please refer to Data Access Integration.
Mapping steps
Create a mapping file for every complex type
We need one mapping file per complex type that is going to be nested, including non features, e.g.
gsml:CompositionPart.
Non-feature types that cannot be individually accessed (eg. CompositionPart as a Data Type) can still be
mapped separately for its reusability. For this case, the containing feature type has to include these types in
its mapping file. The include tag should contain the nested mapping file path relative to the location of the
containing type mapping file. In GeologicUnit_MappingFile.xml:
CGITermValue_MappingFile.xmlCompositionPart_MappingFile.xml
Feature types that can be individually accessed don’t need to be explicitly included in the mapping file, as
they would be configured for GeoServer to find. Such types would have their mapping file associated with
a corresponding datastore.xml file, which means that it can be found from the data store registry. In other
words, if the type is associated with a datastore.xml file, it doesn’t need to be explicitly included if referred
from another mapping file.
Example:
For this output: MappedFeature_Output.xml, here are the mapping files:
• MappedFeature_MappingFile.xml
• GeologicUnit_MappingFile.xml
• CompositionPart_MappingFile.xml
• GeologicEvent_MappingFile.xml
• CGITermValue_MappingFile.xml
5.6. Application schemas
221
GeoServer User Manual, Release 2.15.1
GeologicUnit type
You can see within GeologicUnit features, both gml:composition (CompositionPart type) and
gsml:geologicHistory (GeologicEvent type) are multi-valued properties. It shows how multiple cases of
multi-valued properties can be configured within a single Feature Type. This also proves that you can
“chain” non-feature type, as CompositionPart is a Data Type.
GeologicEvent type
Both gsml:eventEnvironment (CGI_TermValue type) and gsml:eventProcess (also of CGI_TermValue type)
are multi-valued properties. This also shows that “chaining” can be done on many levels, as GeologicEvent
is nested inside GeologicUnit. Note that gsml:eventAge properties are configured as inline attributes, as
there can only be one event age per geologic event, thus eliminating the need for feature chaining.
Configure nesting on the nested feature type
In the nested feature type, make sure we have a field that can be referenced by the parent feature. If there
isn’t any existing field that can be referred to, the system field FEATURE_LINK can be mapped to hold the
foreign key value. This is a multi-valued field, so more than one instances can be mapped in the same
feature type, for features that can be nested by different parent types. Since this field doesn’t exist in the
schema, it wouldn’t appear in the output document.
In the source expression tag:
• OCQL: the value of this should correspond to the OCQL part of the parent feature
Example One: Using FEATURE_LINK in CGI TermValue type, which is referred by GeologicEvent as
gsml:eventProcess and gsml:eventEnvironment.
In GeologicEvent (the container feature) mapping:
gsml:eventEnvironmentidgsml:CGI_TermValueFEATURE_LINK[1]truegsml:eventProcessidgsml:CGI_TermValueFEATURE_LINK[2]true
In CGI_TermValue (the nested feature) mapping:
FEATURE_LINK[1]ENVIRONMENT_OWNER
222
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
FEATURE_LINK[2]<
PROCESS_OWNER
The ENVIRONMENT_OWNER column in CGI_TermValue view corresponds to the ID column in GeologicEvent view.
Geologic Event property file:
id
ge.26931120
ge.26930473
ge.26930960
ge.26932959
GEOLOGIC_UNIT_ID:String
ghminage:String
ghmaxage:String
ghage_cdspace:String
gu.25699
Oligocene
Paleocene
urn:cgi:classifierScheme:ICS:StratChart:2008
gu.25678
Holocene
Pleistocene urn:cgi:classifierScheme:ICS:StratChart:2008
gu.25678
Pliocene
Miocene
urn:cgi:classifierScheme:ICS:StratChart:2008
gu.25678
LowerOrdovician
LowerOrdovician
urn:cgi:classifierScheme:ICS:StratChart:2008
CGI Term Value property file:
id
3
4
5
6
7
8
9
10
11
VALUE:String
fluvial
swamp/marsh/bog
marine
submarine fan
hemipelagic
detrital deposition still water
water [process]
channelled stream flow
turbidity current
PROCESS_OWNER:String
NULL
NULL
NULL
NULL
NULL
ge.26930473
ge.26932959
ge.26931120
ge.26932959
ENVIRONMENT_OWNER:String
ge.26931120
ge.26930473
ge.26930960
ge.26932959
ge.26932959
NULL
NULL
NULL
NULL
The system field FEATURE_LINK doesn’t get encoded in the output:
gu.25699
,→gml:name>
,→Oligocene
,→Paleocene
5.6. Application schemas
223
GeoServer User Manual, Release 2.15.1
fluvialchannelled stream flow
Example Two:
Using existing
MappedFeature_MappingFile.xml:
field
(gml:name)
to
hold
the
foreign
key,
see
gsml:specification links to gml:name in GeologicUnit:
gsml:specificationGEOLOGIC_UNIT_IDgsml:GeologicUnitgml:name[3]
In GeologicUnit_MappingFile.xml:
GeologicUnit has 3 gml:name properties in the mapping file, so each has a code space to clarify them:
gml:name[1]ABBREVIATIONcodeSpace'urn:cgi:classifierScheme:GSV:GeologicalUnitCode'gml:name[2]NAMEcodeSpace'urn:cgi:classifierScheme:GSV:GeologicalUnitName'gml:name[3]idcodeSpace'urn:cgi:classifierScheme:GSV:MappedFeatureReference'
The output with multiple gml:name properties and their code spaces:
224
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
Olivine basalt, tuff, microgabbro, minor sedimentary rocks
,→gml:description>
-Py
,→gml:name>
Yaugher
,→Volcanic Groupgu.
,→25678
If this is the “one” side of a one-to-many or many-to-one database relationship, we can use the feature id as
the source expression field, as you can see in above examples. See one_to_many_relationship.JPG as
an illustration.
If we have a many-to-many relationship, we have to use one denormalized view for either side of the
nesting. This means we can either use the feature id as the referenced field, or assign a column to serve this
purpose. See many_to_many_relationship.JPG as an illustration.
Note:
• For many-to-many relationships, we can’t use the same denormalized view for both sides of the nesting.
Test this configuration by running a getFeature request for the nested feature type on its own.
Configure nesting on the “containing” feature type
When nesting another complex type, you need to specify in your source expression:
• OCQL: OGC’s Common Query Language expression of the data store column
• linkElement:
– the nested element name, which is normally the targetElement or mappingName of the corresponding type.
– on some cases, it has to be an OCQL function (see Polymorphism)
• linkField: the indexed XPath attribute on the nested element that OCQL corresponds to
Example: Nesting composition part in geologic unit feature.
In Geologic Unit mapping file:
gsml:compositionidgsml:CompositionPartFEATURE_LINKtrue
• OCQL: id is the geologic unit id
• linkElement: links to gsml:CompositionPart type
5.6. Application schemas
225
GeoServer User Manual, Release 2.15.1
• linkField: FEATURE_LINK, the linking field mapped in gsml:CompositionPart type that also stores
the geologic unit id. If there are more than one of these attributes in the nested feature type, make
sure the index is included, e.g. FEATURE_LINK[2].
Geologic Unit property file:
id
gu.25699
gu.25678
ABBREVIATAION:String
NAME:String
TEXTDESCRIPTION:String
Yaugher Volcanic Olivine basalt, tuff, microgabbro, minor sedimentary rocks
Py Group
Yaugher Volcanic Olivine basalt, tuff, microgabbro, minor sedimentary rocks
Py Group
Composition Part property file:
id
cp.167775491936278812
cp.167775491936278856
cp.167775491936278844
COMPONENT_ROLE:String
interbedded component
interbedded component
sole component
PROPORTION:String
GEOLOGIC_UNIT_ID:String
significant
gu.25699
minor
gu.25678
major
gu.25678
Run the getFeature request to test this configuration. Check that the nested features returned in Step 2 are
appropriately lined inside the containing features. If they are not there, or exceptions are thrown, scroll
down and read the “Trouble Shooting” section.
Multiple mappings of the same type
At times, you may find the need to have different FeatureTypeMapping instances for the same
type. You may have two different attributes of the same type that need to be nested. For example, in gsml:GeologicUnit, you have gsml:exposureColor and gsml:outcropCharacter that are both of
gsml:CGI_TermValue type.
This is when the optional mappingName tag mentioned in Mapping File comes in. Instead of passing in
the nested feature type’s targetElement in the containing type’s linkElement, specify the corresponding
mappingName.
Note:
• The mappingName is namespace aware and case sensitive.
• When the referred mappingName contains special characters such as ‘-‘, it must be enclosed with
single quotes in the linkElement. E.g. ’observation-method’.
• Each mappingName must be unique against other mappingName and targetElement tags across the
application.
• The mappingName is only to be used to identify the chained type from the nesting type. It is not a
solution for multiple FeatureTypeMapping instances where > 1 of them can be queried as top level
features.
• When queried as a top level feature, the normal targetElement is to be used. Filters involving the
nested type should still use the targetElement in the PropertyName part of the query.
• You can’t have more than 1 FeatureTypeMapping of the same type in the same mapping file if one
of them is a top level feature. This is because featuretype.xml would look for the targetElement and
wouldn’t know which one to get.
226
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
The solution for the last point above is to break them up into separate files and locations with only 1
featuretype.xml in the intended top level feature location. E.g.
• You can have 2 FeatureTypeMapping instances in the same file for gsml:CGI_TermValue type since
it’s not a feature type.
• You can have 2 FeatureTypeMapping instances for gsml:MappedFeature, but they have to be broken
up into separate files. The one that can be queried as top level feature type would have featuretype.xml in its location.
Nesting simple properties
You don’t need to chain multi-valued simple properties and map them separately. The original configuration would still work.
Filtering nested attributes on chained features
Filters would work as usual. You can supply the full XPath of the attribute, and the code would handle
this. E.g. You can run the following filter on gsml:MappedFeatureUseCase2A:
gsml:specification/gsml:GeologicUnit/gml:description
,→ogc:PropertyName>
Olivine basalt, tuff, microgabbro, minor sedimentary rocks
,→1
Multi-valued properties by reference (xlink:href )
You may want to use feature chaining to set multi-valued properties by reference. This is particularly handy
to avoid endless loop in circular relationships. For example, you may have a circular relationship between
gsml:MappedFeature and gsml:GeologicUnit. E.g.
• gsml:MappedFeature has gsml:GeologicUnit as gsml:specification
• gsml:GeologicUnit has gsml:MappedFeature as gsml:occurrence
Obviously you can only encode one side of the relationship, or you’ll end up with an endless loop. You
would need to pick one side to “chain” and use xlink:href for the other side of the relationship.
For this example, we are nesting gsml:GeologicUnit in gsml:MappedFeature as gsml:specification.
• Set up nesting on the container feature type mapping as usual:
gsml:specificationGEOLOGIC_UNIT_IDgsml:GeologicUnitgml:name[2]
5.6. Application schemas
227
GeoServer User Manual, Release 2.15.1
• Set up xlink:href as client property on the other mapping file:
gsml:occurrenceidgsml:MappedFeaturegsml:specificationtruexlink:hrefstrConcat('urn:cgi:feature:MappedFeature:', ID)
As we are getting the client property value from a nested feature, we have to set it as if we are chaining the
feature; but we also add the client property containing xlink:href in the attribute mapping. The code will
detect the xlink:href setting, and will not proceed to build the nested feature’s attributes, and we will end
up with empty attributes with xlink:href client properties.
This would be the encoded result for gsml:GeologicUnit:
Note:
• Don’t forget to add XLink in your mapping file namespaces section, or you could end up with a StackOverflowException as the xlink:href client property won’t be recognized and the mappings would
chain endlessly.
• Resolving may be used to force app-schema to do full feature chaining up to a certain level, even if an
xlink reference is specified.
5.6.13 Polymorphism
Polymorphism in this context refers to the ability of an attribute to have different forms. Depending on the
source value, it could be encoded with a specific structure, type, as an xlink:href reference, or not encoded
at all. To achieve this, we reuse feature chaining syntax and allow OCQL functions in the linkElement tag.
Read more about Feature Chaining, if you’re not familiar with the syntax.
Data-type polymorphism
You can use normal feature chaining to get an attribute to be encoded as a certain type. For example:
ex:someAttribute
228
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
VALUE_IDNumericTypeFEATURE_LINKex:someAttributeVALUE_IDgsml:CGI_TermValueFEATURE_LINK
Note: NumericType here is a mappingName, whereas gsml:CGI_TermValue is a targetElement.
In the above example, ex:someAttribute would be encoded with the configuration in NumericType if the
foreign key matches the linkField. Both instances would be encoded if the foreign key matches the candidate keys in both linked configurations. Therefore this would only work for 0 to many relationships.
Functions can be used for single attribute instances. See useful functions for a list of commonly used functions. Specify the function in the linkElement, and it would map it to the first matching FeatureTypeMapping. For example:
ex:someAttributeVALUE_ID
Recode(CLASS_TEXT, 'numeric', 'NumericType', 'literal', 'gsml:CGI_
,→TermValue')
FEATURE_LINKtrue
The above example means, if the CLASS_TEXT value is ‘numeric’, it would link to ‘NumericType’ FeatureTypeMapping, with VALUE_ID as foreign key to the linked type. It would require all the potential
matching types to have a common attribute that is specified in linkField. In this example, the linkField is
FEATURE_LINK, which is a fake attribute used only for feature chaining. You can omit the linkField and
OCQL if the FeatureTypeMapping being linked to has the same sourceType with the container type. This
would save us from unnecessary extra queries, which would affect performance. For example:
FeatureTypeMapping of the container type:
PropertyFilesPolymorphicFeature
FeatureTypeMapping of NumericType points to the same table:
NumericTypePropertyFilesPolymorphicFeature
FeatureTypeMapping of gsml:CGI_TermValue also points to the same table:
5.6. Application schemas
229
GeoServer User Manual, Release 2.15.1
PropertyFilesPolymorphicFeaturegsml:CGI_TermValue
In this case, we can omit linkField in the polymorphic attribute mapping:
ex:someAttribute
Recode(CLASS_TEXT, 'numeric', 'NumericType', 'literal', 'gsml:CGI_
,→TermValue')
true
Referential polymorphism
This is when an attribute is set to be encoded as an xlink:href reference on the top level. When the scenario
only has reference cases in it, setting a function in Client Property will do the job. E.g.:
ex:someAttributexlink:hrefif_then_else(isNull(NUMERIC_VALUE), 'urn:ogc:def:nil:OGC:1.
,→0:missing', strConcat('#', NUMERIC_VALUE))
The above example means, if NUMERIC_VALUE is null, the attribute should be encoded as:
Otherwise, it would be encoded as:
where NUMERIC_VALUE = '123'
However, this is not possible when we have cases where a fully structured attribute is also a possibility.
The toxlinkhref function can be used for this scenario. E.g.:
ex:someAttribute
if_then_else(isNull(NUMERIC_VALUE), toXlinkHref('urn:ogc:def:nil:OGC:1.
,→0:missing'),
if_then_else(lessEqualThan(NUMERIC_VALUE, 1000), 'numeric_value',
,→toXlinkHref('urn:ogc:def:nil:OGC:1.0:missing')))
230
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
The above example means, if NUMERIC_VALUE is null, the output would be encoded as:
Otherwise, if NUMERIC_VALUE is less or equal than 1000, it would be encoded with attributes from
FeatureTypeMapping with ‘numeric_value’ mappingName. If NUMERIC_VALUE is greater than 1000,
it would be encoded as the first scenario.
Useful functions
if_then_else function
Syntax:
if_then_else(BOOLEAN_EXPRESSION, value, default value)
• BOOLEAN_EXPRESSION: could be a Boolean column value, or a Boolean function
• value: the value to map to, if BOOLEAN_EXPRESSION is true
• default value: the value to map to, if BOOLEAN_EXPRESSION is false
Recode function
Syntax:
Recode(EXPRESSION, key1, value1, key2, value2,...)
• EXPRESSION: column name to get values from, or another function
• key-n:
– key expression to map to value-n
– if the evaluated value of EXPRESSION doesn’t match any key, nothing would be encoded
for the attribute.
• value-n: value expression which translates to a mappingName or targetElement
lessEqualThan
Returns true if ATTRIBUTE_EXPRESSION evaluates to less or equal than LIMIT_EXPRESSION.
Syntax:
lessEqualThan(ATTRIBUTE_EXPRESSION, LIMIT_EXPRESSION)
• ATTRIBUTE_EXPRESSION: expression of the attribute being evaluated.
• LIMIT_EXPRESSION: expression of the numeric value to be compared against.
5.6. Application schemas
231
GeoServer User Manual, Release 2.15.1
lessThan
Returns true if ATTRIBUTE_EXPRESSION evaluates to less than LIMIT_EXPRESSION.
Syntax:
lessThan(ATTRIBUTE_EXPRESSION, LIMIT_EXPRESSION)
• ATTRIBUTE_EXPRESSION: expression of the attribute being evaluated.
• LIMIT_EXPRESSION: expression of the numeric value to be compared against.
equalTo
Compares two expressions and returns true if they’re equal.
Syntax:
equalTo(LHS_EXPRESSION, RHS_EXPRESSION)
isNull
Returns a Boolean that is true if the expression evaluates to null.
Syntax:
isNull(EXPRESSION)
• EXPRESSION: expression to be evaluated.
toXlinkHref
Special function written for referential polymorphism and feature chaining, not to be used outside of
linkElement. It infers that the attribute should be encoded as xlink:href.
Syntax:
toXlinkHref(XLINK_HREF_EXPRESSION)
• XLINK_HREF_EXPRESSION:
– could be a function or a literal
– has to be wrapped in single quotes if it’s a literal
Note:
• To get toXlinkHref function working, you need to declare xlink URI in the namespaces.
Other functions
Please refer to Filter Function Reference.
232
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
Combinations
You can combine functions, but it might affect performance. E.g.:
if_then_else(isNull(NUMERIC_VALUE), toXlinkHref('urn:ogc:def:nil:OGC:1.0:missing'),
if_then_else(lessEqualThan(NUMERIC_VALUE, 1000), 'numeric_value', toXlinkHref(
,→'urn:ogc:def:nil:OGC:1.0:missing')))
Note:
• When specifying a mappingName or targetElement as a value in functions, make sure they’re enclosed in single quotes.
• Some functions have no null checking, and will fail when they encounter null.
• The workaround for this is to wrap the expression with isNull() function if null is known to exist in
the data set.
Null or missing value
To skip the attribute for a specific case, you can use Expression.NIL as a value in if_then_else or not include
the key in Recode function . E.g.:
if_then_else(isNull(VALUE), Expression.NIL, 'gsml:CGI_TermValue')
means the attribute would not be encoded if VALUE is null.
Recode(VALUE, 'term_value', 'gsml:CGI_TermValue')
means the attribute would not be encoded if VALUE is anything but 'term_value'.
To encode an attribute as xlink:href that represents missing value on the top level, see Referential Polymorphism.
Any type
Having xs:anyType as the attribute type itself infers that it is polymorphic, since they can be encoded as
any type.
If the type is pre-determined and would always be the same, we might need to specify targetAttributeNode
(optional). E.g.:
om:resultgml:MeasureTypeTOPAGExsi:type'gml:MeasureType'uom'http://www.opengis.net/def/uom/UCUM/0/Ma'
5.6. Application schemas
233
GeoServer User Manual, Release 2.15.1
If the casting type is complex, this is not a requirement as app-schema is able to automatically determine
the type from the XPath in targetAttribute. E.g., in this example om:result is automatically specialised as
a MappedFeatureType:
om:result/gsml:MappedFeature/gml:nameNAME
Alternatively, we can use feature chaining. For the same example above, the mapping would be:
om:resultLEX_Dgsml:MappedFeaturegml:name
If the type is conditional, the mapping style for such attributes is the same as any other polymorphic attributes. E.g.:
om:result
Recode(NAME, Expression.Nil, toXlinkHref('urn:ogc:def:nil:OGC::missing
,→'),'numeric',
toXlinkHref(strConcat('urn:numeric-value::', NUMERIC_VALUE)), 'literal
,→', 'TermValue2')
Filters
Filters should work as usual, as long as the users know what they want to filter. For example, when an
attribute could be encoded as gsml:CGI_TermValue or gsml:CGI_NumericValue, users can run filters with
property names of:
• ex:someAttribute/gsml:CGI_TermValue/gsml:value to return matching attributes that are encoded
as gsml:CGI_TermValue and satisfy the filter.
• likewise, ex:someAttribute/gsml:CGI_NumericValue/gsml:principalValue should return matching
gsml:CGI_NumericValue attributes.
Another limitation is filtering attributes of an xlink:href attribute pointing to an instance outside of the
document.
234
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
5.6.14 Data Access Integration
This page assumes prior knowledge of Application schemas and Feature Chaining. To use feature chaining,
the nested features can come from any complex feature data access, as long as:
• it has valid data referred by the “container” feature type,
• the data access is registered via DataAccessRegistry,
• if FEATURE_LINK is used as the link field, the feature types were created via ComplexFeatureTypeFactoryImpl
However, the “container” features must come from an application schema data access. The rest of this
article describes how we can create an application data access from an existing non-application schema
data access, in order to “chain” features. The input data access referred in this article is assumed to be the
non-application schema data access.
How to connect to the input data access
Configure the data store connection in “sourceDataStores” tag as usual, but also specify the additional “isDataAccess” tag. This flag marks that we want to get the registered complex feature source of the specified
“sourceType”, when processing the source data store. This assumes that the input data access is registered
in DataAccessRegistry upon creation, for the system to find it.
Example:
EarthResourcedirectoryfile:./true
...
EarthResourceEarthResource
...
How to configure the mapping
Use “inputAttribute” in place of “OCQL” tag inside “sourceExpression”, to specify the input XPath expressions.
Example:
gsml:classifier/gsml:ControlledConcept/gsml:preferredName
,→targetAttribute>
mo:classification/mo:MineralDepositModel/mo:mineralDepositGroup
,→
5.6. Application schemas
235
GeoServer User Manual, Release 2.15.1
How to chain features
Feature chaining works both ways for the re-mapped complex features. You can chain other features inside
these features, and vice-versa. The only difference is to use “inputAttribute” for the input XPath expressions, instead of “OCQL” as mentioned above.
Example:
gsml:occurencemo:commodityDescriptiongsml:MappedFeaturegml:name[2]true
How to use filters
From the user point of view, filters are configured as per normal, using the mapped/output target attribute
XPath expressions. However, when one or more attributes in the expression is a multi-valued property,
we need to specify a function such as “contains_text” in the filter. This is because when multiple values
are returned, comparing them to a single value would only return true if there is only one value returned,
and it is the same value. Please note that the “contains_text” function used in the following example is not
available in GeoServer API, but defined in the database.
Example:
Composition is a multi-valued property:
gsml:composition/gsml:CompositionPart/gsml:proportion/
,→gsml:CGI_TermValue/gsml:valueOlivine basalt, tuff, microgabbro, minor sedimentary rocks
,→ogc:Literal>
1
5.6.15 WMS Support
App-schema supports WMS requests as well as WFS requests. This page provides some useful examples
for configuring the WMS service to work with complex features.
Note that the rendering performance of WMS can be significantly slower when using app-schema data
stores. We strongly recommend employing Joining Support For Performance when using WMS with feature
chaining, which can make response time for large data requests several orders of magnitude faster.
236
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
Configuration
For WMS to be applicable to complex feature data, it is necessary that the complex feature types are
recognised by GeoServer as layers. This must be configured by adding an extra configuration file named
‘layer.xml’ in the data directory of each feature type that we want to use as a WMS layer.
This will expand the structure of the workspaces folder in the GeoServer data directory as follows
(workspaces) (see Configuration):
workspaces
- gsml
- SomeDataStore
- SomeFeatureType
- featuretype.xml
- layer.xml
- datastore.xml
- SomeFeatureType-mapping-file.xml
The file layer.xml must have the following contents:
[mylayerid][mylayername]/VECTOR[mydefaultstyle][myfeaturetypeid]true00
Replace the fields in between brackets with the following values:
• [mylayerid] must be a custom id for the layer.
• [mylayername] must be a custom name for the layer.
• [mydefaultstyle] the default style used for this layer (when a style is not specified in the wms request).
The style must exist in the GeoServer configuration.
• [myfeaturetypeid] is the id of the feature type. This must the same as the id specified in the file
featuretype.xml of the same directory.
GetMap
Read GetMap for general information on the GetMap request. Read Styling for general information on how
to style WMS maps with SLD files. When styling complex features, you can use XPaths to specify nested
properties in your filters, as explained in Filtering nested attributes on chained features. However, in WMS
styling filters X-paths do not support handling referenced features (see Multi-valued properties by reference
(xlink:href)) as if they were actual nested features (because the filters are applied after building the features
5.6. Application schemas
237
GeoServer User Manual, Release 2.15.1
rather than before.) The prefix/namespace context that is used in the XPath expression is defined locally in
the XML tags of the style file. This is an example of a Style file for complex features:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
geology-lithologygeology-lithologyGeological Unit Lithology ThemeThe colour has been creatively adapted from Moyer,Hasting
and Raines, 2005 (http://pubs.usgs.gov/of/2005/1314/of2005-1314.pdf)
which provides xls spreadsheets for various color schemes.
plus some creative entries to fill missing entries.
1acidic igneous materialIgneous material with more than 63 percent SiO2.
(after LeMaitre et al. 2002)
gsml:specification/gsml:GeologicUnit/gsml:composition/
gsml:CompositionPart/gsml:lithology/@xlink:hrefurn:cgi:classifier:CGI:SimpleLithology:200811:
acidic_igneous_material#FFCCB3acidic igneous rockIgneous rock with more than 63 percent SiO2.
(after LeMaitre et al. 2002)
gsml:specification/gsml:GeologicUnit/gsml:composition/
gsml:CompositionPart/gsml:lithology/@xlink:hrefurn:cgi:classifier:CGI:SimpleLithology:200811:
acidic_igneous_rock#FECDB2
238
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
57
58
59
60
61
62
63
64
...
GetFeatureInfo
Read GetFeatureInfo for general information on the GetFeatureInfo request. Read the tutorial on GetFeatureInfo Templates for information on how to template the html output. If you want to store a separate
standard template for complex feature collections, save it under the filename complex_content.ftl in
the template directory.
Read the tutorial on Freemarker Templates for more information on how to use the freemarker templates.
Freemarker templates support recursive calls, which can be useful for templating complex content. For
example, the following freemarker template creates a table of features with a column for each property, and
will create another table inside each cell that contains a feature as property:
<#-Macro's used for content
-->
<#macro property node>
<#if !node.isGeometry>
<#if node.isComplex>
<@feature node=node.rawValue type=node.type />
<#else>
${node.value?string}
#if>
#if>
#macro>
<#macro header typenode>
${typenode.name}
fid
<#list typenode.attributes as attribute>
<#if !attribute.isGeometry>
<#if attribute.prefix == "">
${attribute.name}
<#else>
${attribute.prefix}:${attribute.name}
#if>
#if>
#list>
#macro>
<#macro feature node type>
<@header typenode=type />
${node.fid}
5.6. Application schemas
239
GeoServer User Manual, Release 2.15.1
<#list node.attributes as attribute>
<@property node=attribute />
#list>
#macro>
<#-Body section of the GetFeatureInfo template, it's provided with one feature
,→collection, and
will be called multiple times if there are various feature collections
-->
<@header typenode=type />
<#assign odd = false>
<#list features as feature>
<#if odd>
<#else>
#if>
<#assign odd = !odd>
${feature.fid}
<#list feature.attributes as attribute>
<@property node=attribute />
#list>
#list>
5.6.16 WFS 2.0 Support
Resolving
Local resolve is supported in app-schema. This can be done by setting the ‘resolve’ parameter to either
‘local’ or ‘all’. (Remote Resolving is not supported.) The parameter ‘resolveDepth’ specifies how many
levels of references will be resolved. The parameter ‘resolveTimeOut’ may be used to specify, in seconds,
an upper limit to how long app-schema should search for the feature needed for resolving. If the time out
limit is reached, the feature is not resolved.
When resolving without Feature Chaining (see below), a GML ID is extracted from the x-link reference and
a brute force is done on all feature types to find a feature with this GML ID. The extraction of this GML ID
from the Xlink Reference is done using the following rules:
• In case of a URN: The GML ID comes after last colon in the URN. Make sure that the full GML ID is
included after the last colon (including a possible feature type prefix).
• In case of a URL: The GML ID comes after the # symbol.
Failing to respect one of these rules will result in failure of resolve.
240
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
Resolving and Feature Chaining By Reference
The ‘resolve’ and ‘resolveDepth’ parameters may also be used in the case of Multi-valued properties by reference (xlink:href). In this case, no brute force will take place, but resolving will instruct App-Schema to do
full feature chaining rather than inserting a reference. The URI will not be used to find the feature, but the
feature chaining parameters specified in the mapping, as with normal feature chaining. Because of this, the
parameter ‘resolveTimeOut’ will be ignored in this case.
However, be aware that every feature can only appear once in a response. If resolving would break this
rule, for example with circular references, the encoder will change the resolved feature back to an (internal)
x-link reference.
GetPropertyValue
The GetPropertyValue request is now fully supported. Resolving is also possible in this request, following
the same rules as described above.
Paging
Paging is now supported in App-Schema. There are a few exceptions:
• Paging is only supported for data stores with JDBC back ends and will not work for data stores with
property files. It has been tested with Oracle and PostGIS databases.
• Paging with filters involving attributes that are mapped to functions will not be supported, as this
cannot be translated into SQL.
For more efficient SQL queries generation, please set isDenormalised to false where applicable (when a
one to one database table is used). See Mapping File.
5.6.17 Joining Support For Performance
App-schema joining is a optional configuration parameter that tells app-schema to use a different implementation for Feature Chaining, which in many cases can improve performance considerably, by reducing
the amount of SQL queries sent to the DBMS.
Conditions
In order to use App-schema Joining, the following configuration conditions must be met:
• All feature mappings used must be mapped to JDBC datastores.
• All feature mappings that are chained to each other must map to the same physical database.
• In your mappings, there are restrictions on the CQL expressions specified in the
of both the referencing field in the parent feature as well as the referenced field in the nested feature
(like FEATURE_LINK). Any operators or functions used in this expression must be supported by
the filter capibilities, i.e. geotools must be able to translate them directly to SQL code. This can be
different for each DBMS, though as a general rule it can assumed that comparison operators, logical
operators and arithmetic operators are all supported but functions are not. Using simple field names
for feature chaining is guaranteed to always work.
Failing to comply with any of these three restrictions when turning on Joining will result in exceptions
thrown at run-time.
5.6. Application schemas
241
GeoServer User Manual, Release 2.15.1
When using app-schema with Joining turned on, the following restrictions exist with respect to normal
behaviour:
• XPaths specified inside Filters do not support handling referenced features (see Multi-valued properties
by reference (xlink:href)) as if they were actual nested features, i.e. XPaths can only be evaluated when
they can be evaluated against the actual XML code produced by WFS according to the XPath standard.
Configuration
Joining is turned on by default. It is disabled by adding this simple line to your app-schema.properties file
(see Property Interpolation)
app-schema.joining = false
Or, alternatively, by setting the value of the Java System Property “app-schema.joining” to “false”, for
example
java -DGEOSERVER_DATA_DIR=... -Dapp-schema.joining=false Start
Not specifying “app-schema.joining” parameter will enable joining by default.
Database Design Guidelines
• Databases should be optimised for fast on-the-fly joining and ordering.
• Make sure to put indexes on all fields used as identifiers and for feature chaining, unique indexes
where possible. Lack of indices may result in data being encoded in the wrong order or corrupted
output when feature chaining is involved.
• Map your features preferably to normalised tables.
• It is recommended to apply feature chaining to regular one-to-many relationships, i.e. there should
be a unique constraint defined on one of the fields used for the chaining, and if possible a foreign key
constraint defined on the other field.
Effects on Performance
Typical curves of response time for configurations with and without joining against the amount of features
produced will be shaped like this:
In the default implementation, response time increases rapidly with respect to the amount of produced
features. This is because feature chaining is implemented by sending multiple SQL requests to the DBMS
per feature, so the amount of requests increases with the amount of features produced. When Joining is
turned on, response time will be almost constant with respect to the number of features. This is because
242
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
in this implementation a small amount of larger queries is sent to the DBMS, independant of the amount
of features produced. In summary, difference in performance becomes greater as the amount of features
requested gets bigger. General performance of joining will be dependant on database and mapping design
(see above) and database size.
Using joining is strongly recommended when a large number of features need to be produced, for example
when producing maps with WMS (see WMS Support).
Optimising the performance of the database will maximise the benefit of using joining, including for small
queries.
Native Encoding of Filters on Nested Attributes
When App-Schema Joining is active, filters operating on nested attributes (i.e. attributes of features that are
joined to the queried type via Feature Chaining) are translated to SQL and executed directly in the database
backend, rather than being evaluated in memory after all features have been loaded (which was standard
behavior in earlier versions of GeoServer). Native encoding can yield significant performance improvements, especially when the total number of features in the database is high (several thousands or more),
but only a few of them would satisfy the filter.
There are, however, a few limitations in the current implementation:
1. Joining support must not have been explicitly disabled and all its pre-conditions must be met (see
above)
2. Only binary comparison operators (e.g. PropertyIsEqualTo, PropertyIsGreaterThan, etc. . . ),
PropertyIsLike and PropertyIsNull filters are translated to SQL
3. Filters involving conditional polymorphic mappings are evaluated in memory
4. Filters comparing two or more different nested attributes are evaluated in memory
5. Filters matching multiple nested attribute mappings are evaluated in memory
Much like joining support, native encoding of nested filters is turned on by default, and it is disabled by
adding to your app-schema.properties file the line
app-schema.encodeNestedFilters = false
Or, alternatively, by setting the value of the Java System Property “app-schema.encodeNestedFilters” to
“false”, for example
java -DGEOSERVER_DATA_DIR=... -Dapp-schema.encodeNestedFilters=false Start
UNION performance improvement for OR conditions
OR conditions are difficult to optimize for postgresql and are usually slow. App-Schema improves OR
condition performance using UNION clauses instead OR for nested filter subqueries.
With UNION improvement enabled main OR binary operator on nested filter subquery will rebuild normal
OR query like:
SELECT id, name FROM table WHERE name = "A" OR name = "B"
to:
SELECT id, name FROM table WHERE name = "A" UNION SELECT id, name FROM table WHERE
,→name = "B"
5.6. Application schemas
243
GeoServer User Manual, Release 2.15.1
UNION improvement is enabled by default, and it is disabled by adding to your app-schema.properties
file the line
app-schema.orUnionReplace = false
Or, alternatively, by setting the value of the Java System Property “app-schema.orUnionReplace” to “false”,
for example
java -DGEOSERVER_DATA_DIR=... -Dapp-schema.orUnionReplace=false Start
Note: This optimization will only be applied when a PostgresSQL database is being used.
5.6.18 Tutorial
This tutorial demonstrates how to configure two complex feature types using the app-schema plugin and
data from two property files.
GeoSciML
This example uses Geoscience Markup Language (GeoSciML) 2.0, a GML 3.1 application schema:
“GeoSciML is an application schema that specifies a set of feature-types and supporting structures for
information used in the solid-earth geosciences.”
The tutorial defines two feature types:
1. gsml:GeologicUnit, which describes “a body of material in the Earth”.
2. gsml:MappedFeature, which describes the representation on a map of a feature, in this case
gsml:GeologicUnit.
Because a single gsml:GeologicUnit can be observed at several distinct locations on the Earth’s surface,
it can have a multivalued gsml:occurrence property, each being a gsml:MappedFeature.
Installation
• Install GeoServer as usual.
• Install the app-schema plugin geoserver-*-app-schema-plugin.zip:
– Place the jar files in WEB-INF/lib.
– The tutorial folder contains the GeoServer configuraration (data directory) used for this tutorial.
* Either replace your existing data directory with the tutorial data directory,
* Or edit WEB-INF/web.xml to set GEOSERVER_DATA_DIR to point to the tutorial data directory. (Be sure to uncomment the section that sets GEOSERVER_DATA_DIR.)
• Perform any configuration required by your servlet container, and then start the servlet. For example,
if you are using Tomcat, configure a new context in server.xml and then restart Tomcat.
• The first time GeoServer starts with the tutorial configuration, it will download all the schema (XSD)
files it needs and store them in the app-schema-cache folder in the data directory. You must be
connected to the internet for this to work.
244
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
datastore.xml
Each data store configuration file datastore.xml specifies the location of a mapping file and triggers its
loading as an app-schema data source. This file should not be confused with the source data store, which
is specified inside the mapping file.
For gsml_GeologicUnit the file is workspaces/gsml/gsml_GeologicUnit/datastore.xml:
gsml_GeologicUnit_datastoregsml_GeologicUnittruegsml_workspaceurn:cgi:xmlns:CGI:GeoSciML:2.0file:workspaces/gsml/gsml_GeologicUnit/gsml_GeologicUnit.xml
,→app-schema
For gsml:MappedFeature the file is workspaces/gsml/gsml_MappedFeature/datastore.xml:
gsml_MappedFeature_datastoregsml_MappedFeaturetruegsml_workspaceurn:cgi:xmlns:CGI:GeoSciML:2.0file:workspaces/gsml/gsml_MappedFeature/gsml_MappedFeature.
,→xmlapp-schema
Note: Ensure that there is no whitespace inside an entry element.
Mapping files
Configuration of app-schema feature types is performed in mapping files:
• workspaces/gsml/gsml_GeologicUnit/gsml_GeologicUnit.xml
• workspaces/gsml/gsml_MappedFeature/gsml_MappedFeature.xml
Namespaces
Each mapping file contains namespace prefix definitions:
5.6. Application schemas
245
GeoServer User Manual, Release 2.15.1
gmlhttp://www.opengis.net/gmlgsmlurn:cgi:xmlns:CGI:GeoSciML:2.0xlinkhttp://www.w3.org/1999/xlink
Only those namespace prefixes used in the mapping file need to be declared, so the mapping file for
gsml:GeologicUnit has less.
Source data store
The data for this tutorial is contained in two property files:
• workspaces/gsml/gsml_GeologicUnit/gsml_GeologicUnit.properties
• workspaces/gsml/gsml_MappedFeature/gsml_MappedFeature.properties
Java Properties describes the format of property files.
For this example, each feature type uses an identical source data store configuration. This directory
parameter indicates that the source data is contained in property files named by their feature type, in the
same directory as the corresponding mapping file:
datastoredirectoryfile:./
See Data Stores for a description of how to use other types of data stores such as databases.
Target types
Both feature types are defined by the same XML Schema, the top-level schema for GeoSciML 2.0. This is
specified in the targetTypes section. The type of the output feature is defined in targetElement in the
typeMapping section below:
http://www.geosciml.org/geosciml/2.0/xsd/geosciml.xsd
246
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
In this case the schema is published, but because the OASIS XML Catalog is used for schema resolution, a
private or modified schema in the catalog can be used if desired.
Mappings
The typeMappings element begins with configuration elements.
gsml:GeologicUnit:
From the mapping file for
datastoregsml_GeologicUnitgsml:GeologicUnit
• The mapping starts with sourceDataStore, which gives the arbitrary identifier used above to name
the source of the input data in the sourceDataStores section.
• sourceType gives the name of the source simple feature type. In this case it is the simple feature
type gsml_GeologicUnit, sourced from the rows of the file gsml_GeologicUnit.properties
in the same directory as the mapping file.
• When working with databases sourceType is the name of a table or view. Database identifiers must
be lowercase for PostGIS or uppercase for Oracle Spatial.
• targetElement is the name of the output complex feature type.
gml:id mapping
The first mapping sets the gml:id to be the feature id specified in the source property file:
gsml:GeologicUnit
ID
• targetAttribute is the XPath to the element for which the mapping applies, in this case, the toplevel feature type.
• idExpression is a special form that can only be used to set the gml:id on a feature. Any field or
CQL expression can be used, if it evaluates to an NCName.
Ordinary mapping
Most mappings consist of a target and source. Here is one from gsml:GeologicUnit:
gml:description
DESCRIPTION
5.6. Application schemas
247
GeoServer User Manual, Release 2.15.1
• In this case, the value of gml:description is just the value of the DESCRIPTION field in the property file.
• For a database, the field name is the name of the column (the table/view is set in sourceType above).
Database identifiers must be lowercase for PostGIS or uppercase for Oracle Spatial.
• CQL expressions can be used to calculate content. Use caution because queries on CQL-calculated
values prevent the construction of efficient SQL queries.
• Source expressions can be CQL literals, which are single-quoted.
Client properties
In addition to the element content, a mapping can set one or more “client properties” (XML attributes).
Here is one from gsml:MappedFeature:
gsml:specification
xlink:hrefGU_URN
• This mapping leaves the content of the gsml:specification element empty but sets an
xlink:href attribute to the value of the GU_URN field.
• Multiple ClientProperty mappings can be set.
In this example from the mapping for gsml:GeologicUnit both element content and an XML attribute
are provided:
gml:name[1]
NAMEcodeSpace'urn:x-test:classifierScheme:TestAuthority:GeologicUnitName'
• The codespace XML attribute is set to a fixed value by providing a CQL literal.
• There are multiple mappings for gml:name, and the index [1] means that this mapping targets the
first.
248
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
targetAttributeNode
If the type of a property is abstract, a targetAttributeNode mapping must be used to specify a concrete
type. This mapping must occur before the mapping for the content of the property.
Here is an example from the mapping file for gsml:MappedFeature:
gsml:positionalAccuracygsml:CGI_TermValuePropertyTypegsml:positionalAccuracy/gsml:CGI_TermValue/gsml:value
,→targetAttribute>
'urn:ogc:def:nil:OGC:missing'codeSpace'urn:ietf:rfc:2141'
• gsml:positionalAccuracy is of type gsml:CGI_TermValuePropertyType, which is abstract, so must be mapped to its concrete subtype gsml:CGI_TermValuePropertyType with a
targetAttributeNode mapping before its contents can be mapped.
• This example also demonstrates that mapping can be applied to nested properties to arbitrary depth.
This becomes unmanageable for deep nesting, where feature chaining is preferred.
Feature chaining
In feature chaining, one feature type is used as a property of an enclosing feature type, by value or by
reference:
gsml:occurrence
URNgsml:MappedFeaturegml:name[2]true
• In this case from the mapping for gsml:GeologicUnit, we specify a mapping for its
gsml:occurrence.
• The URN field of the source gsml_GeologicUnit simple feature is use as the “foreign key”, which
maps to the second gml:name in each gsml:MappedFeature.
• Every gsml:MappedFeature with gml:name[2] equal to the URN of the gsml:GeologicUnit
under construction is included as a gsml:occurrence property of the gsml:GeologicUnit (by
value).
5.6. Application schemas
249
GeoServer User Manual, Release 2.15.1
WFS response
When GeoServer is running, test app-schema WFS in a web browser.
localhost:8080 you can query the two feature types using these links:
If GeoServer is listening on
• http://localhost:8080/geoserver/wfs?request=GetFeature&version=1.1.0&typeName=gsml:
GeologicUnit
• http://localhost:8080/geoserver/wfs?request=GetFeature&version=1.1.0&typeName=gsml:
MappedFeature
gsml:GeologicUnit
Feature chaining has been used to construct the multivalued property gsml:occurrence of
gsml:GeologicUnit.
This property is a gsml:MappedFeature.
The WFS response for
gsml:GeologicUnit combines the output of both feature types into a single response. The first
gsml:GeologicUnit has two gsml:occurrence properties, while the second has one. The relationships between the feature instances are data driven.
Because the mapping files in the tutorial configuration do not contain attribute mappings for all mandatory
properties of these feature types, the WFS response is not schema-valid against the GeoSciML 2.0 schemas.
Schema-validity can be achieved by adding more attribute mappings to the mapping files.
Note: These feature types are defined in terms of GML 3.1 (the default for WFS 1.1.0); other GML versions
will not work.
Warning: The web interface does not yet support app-schema store or layer administration.
Acknowledgements
gsml_GeologicUnit.properties and gsml_MappedFeature.properties are derived from data
provided by the Department of Primary Industries, Victoria, Australia. For the purposes of this tutorial,
this data has been modified to the extent that it has no real-world meaning.
5.6.19 MongoDB Tutorial
This tutorial demonstrates how to use app-schema plugin with a MongoDB data store. This tutorial will focus on the MongoDB data store specificities is highly recommended to read the app-schema documentation
before.
Use Case
The use case for this tutorial will be to serve through app-schema the information about some meteorological stations stored in a MongoDB database. Note that this use case is completely fictional and only used to
demonstrate the MongoDB and app-schema integration.
First of all let’s insert some test data in a MongoDB data store:
250
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
db.stations.insert({
"id": "1",
"name": "station 1",
"contact": {
"mail": "station1@mail.com"
},
"geometry": {
"coordinates": [
50,
60
],
"type": "Point"
},
"measurements": [
{
"name": "temp",
"unit": "c",
"values": [
{
"time": 1482146800,
"value": 20
}
]
},
{
"name": "wind",
"unit": "km/h",
"values": [
{
"time": 1482146833,
"value": 155
}
]
}
]
})
db.stations.insert({
"id": "2",
"name": "station 2",
"contact": {
"mail": "station2@mail.com"
},
"geometry": {
"coordinates": [
100,
-50
],
"type": "Point"
},
"measurements": [
{
"name": "temp",
"unit": "c",
"values": [
{
"time": 1482146911,
"value": 35
5.6. Application schemas
251
GeoServer User Manual, Release 2.15.1
},
{
"time": 1482146935,
"value": 25
}
]
},
{
"name": "wind",
"unit": "km/h",
"values": [
{
"time": 1482146964,
"value": 80
}
]
},
{
"name": "pression",
"unit": "pa",
"values": [
{
"time": 1482147026,
"value": 1019
},
{
"time": 1482147051,
"value": 1015
}
]
}
]
})
db.stations.createIndex({
"geometry": "2dsphere"
})
This is the schema that will be used to do the mappings in app-schema:
252
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
,→
Mappings
MongoDB objects may contain nested elements and nested collections. The following three functions make
possible to select nested elements and link nested collections using a JSON path:
5.6. Application schemas
253
GeoServer User Manual, Release 2.15.1
Function
jsonSelect
Example
jsonSelect(‘contact.mail’)
Description
Used to retrieve the value for the mapping from a
MongoDB object.
collectionLink
collectionLink(‘measurements.values’)
Used when chaining entities with a nested collection.
collectionId
collectionId()
Instructs the mapper to generate a ID for the
nested collection.
nestedCollectionLinknestedCollectionLink()
Used on the nested collection to create a link with
the parent feature.
A station data is composed of some meta-information about the station and a list of measurements. Each
measurement as some meta-information and contains a list of values. The mappings will contain three top
entities: the station, the measurements and the values.
Follows a the complete mappings file:
sthttp://www.stations.org/1.0gmlhttp://www.opengis.net/gmldata_sourcedata_storemongodb://{mongoHost}:{mongoPort}/{dataBaseName}namespacehttp://www.stations.org/1.0schema_storefile:{schemaStore}data_store_typecomplex
254
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
stations.xsddata_source{collectionName}st:StationFeaturest:StationFeaturejsonSelect('id')st:namejsonSelect('name')st:contact/st:mailjsonSelect('contact.mail')st:measurementcollectionLink('measurements')aaaFEATURE_LINK[1]truest:geometryjsonSelect('geometry')data_source{collectionName}aaast:Measurementst:MeasurementcollectionId()
5.6. Application schemas
255
GeoServer User Manual, Release 2.15.1
st:namejsonSelect('name')st:unitjsonSelect('unit')st:valuescollectionLink('values')st:ValueFEATURE_LINK[2]trueFEATURE_LINK[1]nestedCollectionLink()data_source{collectionName}st:Valuest:ValuecollectionId()st:timestampjsonSelect('time')st:valuejsonSelect('value')FEATURE_LINK[2]nestedCollectionLink()
256
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
The mappings for the attributes are straightforward, for example the following mapping:
st:contact/st:mailjsonSelect('contact.mail')
The mapping above defines that the contact mail for a station will be available at the JSON path contact.
mail and that the correspondent XML schema element is the XPATH st:contact/st:mail.
The feature chaining is a little bit more complex. Let’s take as an example the chaining between
StationFeature and Measurement features. In the StationFeature feature type the link to the Measurement entity is defined with the following mapping:
st:measurementcollectionLink('measurements')st:MeasurementFEATURE_LINK[1]true
and in the Measurement feature type the link to the parent feature is defined with the following mapping:
FEATURE_LINK[1]nestedCollectionLink()
With the two mapping above we tie the two features types together. When working with a MongoDB data
store this mappings will always be petty much the same, only the nested collection path and the feature
link index need to be updated. Note that the JSON path of the nested collections attributes are relative to
the parent.
Querying
To create an MongoDB app-schema layer in GeoServer, the app-schema extension and the mongo-complex
extension needs to be installed.
A workspace for each name space declared in the mappings file needs to be created, in this case the
workspace st with URI http://www.stations.org/1.0 needs to be created. No need to create a gml
workspace.
Creating a MongoDB app-schema layer is similar to any other app-schema layer, just create an app-schema
store pointing to the correct mappings file and select the layer correspondent to the top entity, in this case
5.6. Application schemas
257
GeoServer User Manual, Release 2.15.1
st:StationFeature.
Is possible to query with WFS complex features encoded in GML and GeoJson using complex features
filtering capabilities. For example, querying all the stations that have a measurement value with a time
stamp superior to 1482146964:
st:StationFeature/st:measurement/st:values/st:timestamp
1482146964
5.6.20 Apache Solr Tutorial
This tutorial demonstrates how to use the App-Schema plugin with a Apache Solr data store. This tutorial
will focus on the Apache Solr data store specific aspects, and the App-Schema documentation should be
read first.
The use case for this tutorial will be to serve through App-Schema the information about some meteorological stations index in an Apache Solr core. Note that this use case is completely fictional and only used to
demonstrate the Apache Solr and App-Schema integration.
A station data is composed of some meta-information about the station, e.g. it’s name and position. The
only extra different configuration we need to provide when using Apache Solr as a data source is the
configuration of the data store itself.
Apache Solr data source configuration as a specific syntax and allow us to specify geometry attributes and
to explicitly set the default geometry:
stationshttp://localhost:8983/solr/stationslocation4326POINT
In this particular case the the location attribute contains a point geometry and will be the default geometry.
The complete mapping file is:
258
Chapter 5. Data management
GeoServer User Manual, Release 2.15.1
sthttp://www.stations.org/1.0gmlhttp://www.opengis.net/gml/3.2stationshttp://localhost:8983/solr/stationslocation4326POINTstations.xsdstations_solrstationsstationsst:Stationst:Stationstation_idst:stationNamestation_namest:positionstation_location
5.6. Application schemas
259
GeoServer User Manual, Release 2.15.1
The mappings for the attributes are straightforward and follow the normal App-Schema attributes mappings syntax. Currently multi valued fields are not supported.
260
Chapter 5. Data management
CHAPTER
6
Styling
This section discusses the styling of geospatial data served through GeoServer.
6.1 Styles
This section will detail how to work with the styles pages in the Web administration interface. For more
information on styles and syntax, please see the main section on Styling.
Styles are used to control the appearance of geospatial data. Styles for GeoServer are written in a number
of different formats:
• Styled Layer Descriptor (SLD): An OGC standard for geospatial styling. Available by default.
• Cascading Style Sheets (CSS): A CSS-like syntax. Available via an extension.
• YSLD: An SLD-equivalent based on YAML for improved authoring. Available via the ysld extension .
• MBStyle: A syntax based on JSON for improved interoperability. Available via the mbstyle extension .
6.1.1 Styles page
On the Styles page, you can add a new style, remove a style, or view or edit an existing style.
Add a Style
The buttons for adding and removing a style can be found at the top of the Styles page.
To add a new style, click Add a new style button. You will be redirected to the new style page, which is the
same as the Style Editor Data tab.
The editor page provides several options for submitting a new style:
• Type the style definition directly into the editor.
261
GeoServer User Manual, Release 2.15.1
Fig. 6.1: Styles page
Fig. 6.2: Adding or removing a style
Fig. 6.3: Generating a new default style.
262
Chapter 6. Styling
GeoServer User Manual, Release 2.15.1
• Generate a new default style based on an internal template:
• Copy the contents of an existing style into the editor:
Fig. 6.4: Copying an existing Style from GeoServer
• Upload a local file that contains the style:
Fig. 6.5: Uploading an file from the local system
When creating a style, only the Data tab will be available. Click Apply on the new style to stay on the Style
Editor page and gain access to all tabs.
Remove a Style
To remove a style, click the check box next to the style. Multiple styles can be selected at the same time.
Click the Remove selected style(s) link at the top of the page. You will be asked for confirmation:
Fig. 6.6: Confirmation prompt for removing styles
Click OK to remove the selected style(s).
6.1.2 Style Editor
On the Styles page, click a style name to open the Style Editor.
6.1. Styles
263
GeoServer User Manual, Release 2.15.1
The Style Editor page presents the style definition. The page contains four tabs with many configuration
options:
• Data: Includes basic style information, the ability to generate a style, and legend details
• Publishing: Displays which layers are using this style
• Layer Preview: Previews the style with an associated layer while editing
• Layer Attributes: Displays a list of attributes for the associated layer
Fig. 6.7: Style Editor tabs
At the bottom of the Style Editor page is a number of options:
Option
Validate
Apply
Submit
Cancel
Description
Will test the current style for correctness according to the Format option selected
Makes the changes to the style and remain on the Style Editor page. This is
useful to update the Layer Preview tab.
Makes the changes to the style and returns to the Styles page
Cancels all changes to the style and returns to the Styles page
Fig. 6.8: Style Editor options
Style definition
On all tabs, the Style Editor will display the style definition at the bottom, allowing for direct editing of the
style. Switch between the tabs in order to facilitate style creation and editing.
The style editor supports line numbering, automatic indentation, and real-time syntax highlighting. You
can also increase or decrease the font size of the editor.
Button
Description
Undo
Redo
Go to line
Auto-format the editor contents
Change the font size in the editor
Insert image into style (choose existing or upload)
Change height of style editor (disabled in full screen mode)
During editing and especially after editing is complete, you will want to check validation of the syntax.
This can be done by clicking the Validate button at the bottom.
264
Chapter 6. Styling
GeoServer User Manual, Release 2.15.1
Fig. 6.9: Style editor
If no errors are found, you will see this message:
Fig. 6.10: No validation errors
If any validation errors are found, they will be displayed:
Fig. 6.11: Validation error message
Style Editor: Data tab
The Data tab includes basic style information, the ability to generate a style, and legend details.
The Style Data area has mandatory basic style information:
Option
Name
Workspace
Format
Description
Name of the style
Workspace in which the style is contained. Styles can be inside workspaces,
but can also be “global” (no workspace).
Format of the style. Options are SLD, CSS, and YSLD, MBStyle depending on
availability.
The Style Content area allows you to generate a style, copy an existing style, or upload an existing style:
6.1. Styles
265
GeoServer User Manual, Release 2.15.1
Fig. 6.12: Style Data area
Option
Generate a default style
Copy from existing style
Upload a style file
Description
Selects a generic style based on geometry. Options are Point, Line, Polygon,
Raster, and Generic. Click Generate when selected.
Selects an existing style in GeoServer and copy its contents to this style. Any
style in GeoServer is available as an option. Not all styles will work with all
layers. Click Copy when selected.
Selects a plain text file on your local system to add as the style. Click Upload
when selected.
Fig. 6.13: Style Content area
The Legend area allows you to add, modify, or delete a custom style, and preview the legend for the style.
By default GeoServer will generate a legend based on your style file, but this can be customized here:
Option
Add legend
Online Resource
Auto-detect image size
and type
Width
Height
Format
Discard legend
Preview legend
Description
Allows you to use a custom legend
Path to the custom legend graphic to use. Can be a URL or a local path (relative to the style file path). See Structure of the data directory for a description of
the styles directory.
Populates the Width, Height, and Format options for the Online Resource
Width of the custom legend graphic
Height of the custom legend graphic
Mime type of the custom legend graphic
Will remove the settings for the custom legend graphic and will instead use
the default generated legend.
Previews the legend based on the current settings
Style Editor: Publishing tab
The Publishing tab displays a list of all layers on the server, with the purpose of showing which layers are
associated with the current style. Layers can set a single default style and have any number of additional
266
Chapter 6. Styling
GeoServer User Manual, Release 2.15.1
Fig. 6.14: Legend area
styles. If this style is set to be either of these options for a layer, it will be shown with a check box in the
table.
Option
Workspace
Layer
Default
Associated
Description
Workspace of the layer
Name of the layer
Shows whether the style being edited is the default for a given layer
Shows whether the style being edited is an additional style for a given layer
Fig. 6.15: Publishing tab
Style Editor: Layer Preview tab
It is very common to have to iterate your styles and test how the visualization changes over time. The Layer
Preview tab allows you to make changes to the style and see them without having to navigate away from
the page.
The Layer Preview tab shows a single image. GeoServer tries to identify which layer should be shown (for
example, a layer for which this style is the default), but if the layer being previewed is not the desired one,
click the layer name above the preview box and select a layer.
Style Editor: Layer Attributes tab
Most styles utilize the specific values of certain attributes of the associated layer in order to create more detailed and useful styles. (For example: styling all large cities different from small cities based on a particular
attribute.)
The Layer Attributes tab will display a list of attributes for the given associated layer. GeoServer tries to
identify which layer should be shown (for example, a layer for which this style is the default), but if the
layer being previewed is not the desired one, click the layer name above the table and select a layer.
6.1. Styles
267
GeoServer User Manual, Release 2.15.1
Fig. 6.16: Layer Preview tab
Option
name
type
sample
min
max
computeStats
Description
Name of the attribute
Type of the attribute. Can be a numeric (such as “Long”), a string (“String”),
or a geometry (such as “Point”).
Sample value of the attribute taken from the data
Minimum value of the attribute in the data set, if applicable
Minimum value of the attribute in the data set, if applicable
Click Compute to calculate the min and max values for that attribute, if applicable
Fig. 6.17: Layer Attributes tab
Style Editor: full screen side by side mode
The style editor page has now a “outwards arrows” button on the top right side of the window:
Pressing it will cause the editor and preview to go side by side and use the entire browser window space:
The button turns into a “inwards arrows” icon, pressing it resumes the original editing mode.
6.2 SLD Styling
This section discusses styling of geospatial data using “Style Layer Descriptor” XML files.
268
Chapter 6. Styling
GeoServer User Manual, Release 2.15.1
Fig. 6.18: The new fullscreen functionality
Fig. 6.19: Side by side style editing
6.2. SLD Styling
269
GeoServer User Manual, Release 2.15.1
6.2.1 Introduction to SLD
Geospatial data has no intrinsic visual component. In order to see data, it must be styled. Styling specifies
color, thickness, and other visible attributes used to render data on a map.
In GeoServer, styling is accomplished using a markup language called Styled Layer Descriptor, or SLD for
short. SLD is an XML-based markup language and is very powerful, although somewhat complex. This
page gives an introduction to the capabilities of SLD and how it works within GeoServer.
Note: Since GeoServer uses SLD exclusively for styling, the terms “SLD” and “style” will often be used
interchangeably.
SLD Concepts
In GeoServer styling is most often specified using XML SLD style documents. Style documents are associated with GeoServer layers (featuretypes) to specify how they should be rendered. A style document
specifies a single named layer and a user style for it. The layer and style can have metadata elements such
as a name identifying them, a title for displaying them, and an abstract describing them in detail. Within
the top-level style are one or more feature type styles, which act as “virtual layers” to provide control over
rendering order (allowing styling effects such as cased lines for roads). Each feature type style contains
one or more rules, which control how styling is applied based on feature attributes and zoom level. Rules
select applicable features by using filters, which are logical conditions containing predicates, expressions
and filter functions. To specify the details of styling for individual features, rules contain any number of
symbolizers. Symbolizers specify styling for points, lines and polygons, as well as rasters and text labels.
For more information refer to the SLD Reference.
Types of styling
Vector data that GeoServer can serve consists of three classes of shapes: Points, lines, and polygons. Lines
(one dimensional shapes) are the simplest, as they have only the edge to style (also known as “stroke”).
Polygons, two dimensional shapes, have an edge and an inside (also known as a “fill”), both of which can
be styled differently. Points, even though they lack dimension, have both an edge and a fill (not to mention
a size) that can be styled. For fills, color can be specified; for strokes, color and thickness can be specified.
GeoServer also serves raster data. This can be styled with a wide variety of control over color palette,
opacity, contrast and other parameters.
More advanced styling is possible as well. Points can be specified with well-known shapes like circles,
squares, stars, and even custom graphics or text. Lines can be styled with a dash styles and hashes. Polygons can be filled with a custom tiled graphics. Styling can be based on attributes in the data, so that certain
features are styled differently. Text labels on features are possible as well. Styling can also be determined
by zoom level, so that features are displayed in a way appropriate to their apparent size. The possibilities
are vast.
A basic style example
A good way to learn about SLD is to study styling examples. The following is a simple SLD that can be
applied to a layer that contains points, to style them as red circles with a size of 6 pixels. (This is the first
example in the Points section of the SLD Cookbook.)
270
Chapter 6. Styling
GeoServer User Manual, Release 2.15.1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
Simple pointGeoServer SLD Cook Book: Simple pointcircle#FF00006
Although the example looks long, only a few lines are really important to understand. Line 14 states that a
“PointSymbolizer” is to be used to style data as points. Lines 15-17 state that points are to be styled using
a graphic shape specified by a “well known name”, in this case a circle. SLD provides names for many
shapes such as “square”, “star”, “triangle”, etc. Lines 18-20 specify the shape should be filled with a color
of #FF0000 (red). This is an RGB color code, written in hexadecimal, in the form of #RRGGBB. Finally, line
22 specifies that the size of the shape is 6 pixels in width. The rest of the structure contains metadata about
the style, such as a name identifying the style and a title for use in legends.
Note: In SLD documents some tags have prefixes, such as ogc:. This is because they are defined in XML
namespaces. The top-level StyledLayerDescriptor tag (lines 2-7) specifies two XML namespaces, one
called xmlns, and one called xmlns:ogc. The first namespace is the default for the document, so tags
belonging to it do not need a prefix. Tags belonging to the second require the prefix ogc:. In fact, the
namespace prefixes can be any identifier. The first namespace could be called xmlns:sld (as it often is)
and then all the tags in this example would require an sld: prefix. The key point is that tags need to have
the prefix for the namespace they belong to.
See the SLD Cookbook for more examples of styling with SLD.
6.2.2 Working with SLD
This section describes how to create, view and troubleshoot SLD styling in GeoServer.
6.2. SLD Styling
271
GeoServer User Manual, Release 2.15.1
Creating
GeoServer comes with some basic styles defined in its catalog. Any number of new styles can be added
to the catalog. Styles can also be specified externally to the server, either to define a complete map, or to
extend the server style catalog using library mode.
Catalog Styles
Styles in the catalog can be viewed, edited and validated via the Styles page menu of the Web administration
interface. They may also be created and accessed via the REST Styles API.
There are two types of Catalog Styles: Symbology Encoding styles (the default) and Style Layer Descriptor
styles.
Symbology Encoding Styles
A Symbology Encoding style consists of a Symbology Encoding document used to specify the styling of
a single layer. In GeoServer, this is more commonly referred to as a style.
GeoServer supports the use of a StyledLayerDescriptor document containing a single element, which contains a single element to specify the styling.
• When used in this fashion the layer name is ignored, since the style may be applied to many different
layers.
• When using an an StyledLayerDescriptor generated by another application keep in mind only the first
is used, any subsequent content is ignored.
Every layer (featuretype) registered with GeoServer must have at least one symbology encoding style
associated with it, which is the default style for rendering the layer. Any number of additional styles
can be associated with a layer. This allows layers to have appropriate styles advertised in the WMS
GetCapabilities document. A layer’s styles can be changed using the Layers page of the Web administration interface.
Note: When adding a layer and a style for it to GeoServer at the same time, the style should be added first,
so that the new layer can be associated with the style immediately.
Style Layer Descriptor Styles
A Style Layer Descriptor is a StyledLayerDescriptor document containing any number of
and elements, each of which may contain any number of or
elements.
Within a Style Layer Descriptor document, the name of any elements should match a layer
(or layer group) in the catalog. Likewise, any elements should refer to a style in the catalog.
Style Layer Descriptor styles can define new layers of styled data, by using the InlineFeature element to
provide feature data.
Within GeoServer, when Style Layer Descriptor styles are used they are typically in the form of style groups.
Style groups can be added to layer groups as an alternative way of defining a collection of styled layers,
using either the Web Administration interface or the REST API.
272
Chapter 6. Styling
GeoServer User Manual, Release 2.15.1
Style Layer Descriptor styles can still be assigned to layers and used like a layer style, in which case only
the first will be used. Style Layer Descriptor styles can also be used as an External Style,
via the geoserver styles endpoint (/geoserver/styles) or the geoserver REST api.
External Styles
Styling can be defined externally to the server in a number of ways:
• An internet-accessible SLD document can be provided via the SLD=url parameter in a WMS GetMap
GET request
• An SLD document can be provided directly in a WMS GetMap GET request using the
SLD_BODY=style parameter. The SLD XML must be URL-encoded.
• A StyledLayerDescriptor element can be included in a WMS GetMap POST request XML document.
In all of these cases, if the WMS layers parameter is not supplied then the map content is defined completely by the layers and styles present in the external SLD. If the layers parameter is present, then styling
operates in Library Mode.
The structure of an external style is the same as a Style Layer Descriptor style, as described above.
External styles can define new layers of styled data, by using the SLD InlineFeature element to provide
feature data. This can be used to implement dynamic feature highlighting, for example.
External styling may be generated dynamically by client applications, This provides a powerful way for
clients to control styling effects.
Library Mode
In library mode externally-defined styles are treated as a style library, which acts as an extension to the
server style catalog. Library mode occurs when map layers and styles are specified using the layers and
styles WMS parameters, and additional styling is supplied externally using one of the methods described
in the previous section. The styles in the external style document take precedence over the catalog styles
during rendering.
Style lookup in library mode operates as follows:
• For each layer in the layers list, the applied style is either a named style specified in the styles list
(if present), or the layer default style
• For a named style, if the external style document has a ... with
matching layer name and style name, then it is used. Otherwise, the style name is searched for in
the catalog. If it is not found there, an error occurs.
• For a default style, the external style document is searched to find a element with
the layer name. If it contains a with the element having the value 1
then that style is used. Otherwise, the default server style for the layer (which must exist) is used.
Generally it is simpler and more performant to use styles from the server catalog. However, library mode
can be useful if it is required to style a map containing many layers and where only a few of them need to
have their styling defined externally.
Viewing
Once a style has been associated with a layer, the resulting rendering of the layer data can be viewed by
using the Layer Preview. The most convenient output format to use is the built-in OpenLayers viewer.
6.2. SLD Styling
273
GeoServer User Manual, Release 2.15.1
Styles can be modified while the view is open, and their effect is visible as soon as the map view is panned
or zoomed. Alternate styles can be viewed by specifying them in the styles WMS request parameter.
To view the effect of compositing multiple styled layers, several approaches are available:
• Create a layer group for the desired layers using the Layer Groups page, and preview it. Non-default
styles can be specified for layers if required.
• Submit a WMS GetMap GET request specifying multiple layers in the layers parameter, and the
corresponding styles in the styles parameter (if non-default styles are required).
• Submit a WMS GetMap POST request containing a StyledLayerDescriptor element specifying server
layers, optional layers of inline data, and either named catalog styles or user-defined styling for each
layer.
Troubleshooting
SLD is a type of programming language, not unlike creating a web page or building a script. As such,
problems may arise that may require troubleshooting.
Syntax Errors
To minimize syntax errors when creating the SLD, it is recommended to use a text editor that is designed
to work with XML (such as the Style Editor provided in the GeoServer UI). XML editors can make finding
syntax errors easier by providing syntax highlighting and (sometimes) built-in error checking.
The GeoServer Style Editor allows validating a document against the SLD XML schema. This is not mandatory, but is recommended to do before saving styles.
Semantic Errors
Semantic errors cannot be caught by SLD validation, but show up when a style is applied during map
rendering. Most of the time this will result in a map displaying no features (a blank map), but some errors
will prevent the map from rendering at all.
The easiest way to fix semantic errors in an SLD is to try to isolate the error. If the SLD is long with many
rules and filters, try temporarily removing some of them to see if the errors go away.
In some cases the server will produce a WMS Exception document which may help to identify the error. It
is also worth checking the server log to see if any error messages have been recorded.
6.2.3 SLD Cookbook
The SLD Cookbook is a collection of SLD “recipes” for creating various types of map styles. Wherever
possible, each example is designed to show off a single SLD feature so that code can be copied from the
examples and adapted when creating SLDs of your own. While not an exhaustive reference like the SLD
Reference or the OGC SLD 1.0 specification the SLD Cookbook is designed to be a practical reference, showing common style templates that are easy to understand.
The SLD Cookbook is divided into four sections: the first three for each of the vector types (points, lines, and
polygons) and the fourth section for rasters. Each example in every section contains a screenshot showing
actual GeoServer WMS output, a snippet of the SLD code for reference, and a link to download the full
SLD.
274
Chapter 6. Styling
GeoServer User Manual, Release 2.15.1
Each section uses data created especially for the SLD Cookbook, with shapefiles for vector data and GeoTIFFs for raster data. The projection for data is EPSG:4326. All files can be easily loaded into GeoServer in
order to recreate the examples.
Data Type
Point
Line
Polygon
Raster
Shapefile
sld_cookbook_point.zip
sld_cookbook_line.zip
sld_cookbook_polygon.zip
sld_cookbook_raster.zip
Points
While points are seemingly the simplest type of shape, possessing only position and no other dimensions,
there are many different ways that a point can be styled in SLD.
Warning: The code examples shown on this page are not the full SLD code, as they omit the SLD
header and footer information for the sake of brevity. Please use the links to download the full SLD for
each example.
Example points layer
The points layer used for the examples below contains name and population information for the major
cities of a fictional country. For reference, the attribute table for the points in this layer is included below.
fid (Feature ID)
point.1
point.2
point.3
point.4
point.5
point.6
point.7
name (City name)
Borfin
Supox City
Ruckis
Thisland
Synopolis
San Glissando
Detrania
pop (Population)
157860
578231
98159
34879
24567
76024
205609
Download the points shapefile
Simple point
This example specifies points be styled as red circles with a diameter of 6 pixels.
Code
View and download the full "Simple point" SLD
1
2
3
4
5
6.2. SLD Styling
275
GeoServer User Manual, Release 2.15.1
Fig. 6.20: Simple point
6
7
8
9
10
11
12
13
14
15
circle#FF00006
Details
There is one in one for this SLD, which is the simplest possible situation.
(All subsequent examples will contain one and one unless otherwise specified.) Styling points is accomplished via the (lines 3-13). Line 6 specifies the shape
of the symbol to be a circle, with line 8 determining the fill color to be red (#FF0000). Line 11 sets the size
(diameter) of the graphic to be 6 pixels.
Simple point with stroke
This example adds a stroke (or border) around the Simple point, with the stroke colored black and given a
thickness of 2 pixels.
Code
View and download the full "Simple point with stroke" SLD
1
2
3
4
5
6
7
circle
276
Chapter 6. Styling
GeoServer User Manual, Release 2.15.1
Fig. 6.21: Simple point with stroke
8
9
10
11
12
13
14
15
16
17
18
19
#FF0000#00000026
Details
This example is similar to the Simple point example. Lines 10-13 specify the stroke, with line 11 setting the
color to black (#000000) and line 12 setting the width to 2 pixels.
Rotated square
This example creates a square instead of a circle, colors it green, sizes it to 12 pixels, and rotates it by 45
degrees.
Code
View and download the full "Rotated square" SLD
1
2
3
4
5
6
7
8
square#009900
6.2. SLD Styling
277
GeoServer User Manual, Release 2.15.1
Fig. 6.22: Rotated square
9
10
11
12
13
14
15
16
1245
Details
In this example, line 6 sets the shape to be a square, with line 8 setting the color to a dark green (#009900).
Line 11 sets the size of the square to be 12 pixels, and line 12 set the rotation is to 45 degrees.
Transparent triangle
This example draws a triangle, creates a black stroke identical to the Simple point with stroke example, and
sets the fill of the triangle to 20% opacity (mostly transparent).
Fig. 6.23: Transparent triangle
278
Chapter 6. Styling
GeoServer User Manual, Release 2.15.1
Code
View and download the full "Transparent triangle" SLD
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
triangle#0099000.2#000000212
Details
In this example, line 6 once again sets the shape, in this case to a triangle. Line 8 sets the fill color to a
dark green (#009900) and line 9 sets the opacity to 0.2 (20% opaque). An opacity value of 1 means that
the shape is drawn 100% opaque, while an opacity value of 0 means that the shape is drawn 0% opaque, or
completely transparent. The value of 0.2 (20% opaque) means that the fill of the points partially takes on the
color and style of whatever is drawn beneath it. In this example, since the background is white, the dark
green looks lighter. Were the points imposed on a dark background, the resulting color would be darker.
Lines 12-13 set the stroke color to black (#000000) and width to 2 pixels. Finally, line 16 sets the size of the
point to be 12 pixels in diameter.
Point as graphic
This example styles each point as a graphic instead of as a simple shape.
Code
View and download the full "Point as graphic" SLD
1
2
3
4
5
6
7
8
9
image/png
6.2. SLD Styling
279
GeoServer User Manual, Release 2.15.1
Fig. 6.24: Point as graphic
10
11
12
13
14
15
32
Details
This style uses a graphic instead of a simple shape to render the points. In SLD, this is known as an
, to distinguish it from the commonly-used shapes such as squares and circles that
are “internal” to the renderer. Lines 5-10 specify the details of this graphic. Line 8 sets the path and file
name of the graphic, while line 9 indicates the format (MIME type) of the graphic (image/png). In this
example, the graphic is contained in the same directory as the SLD, so no path information is necessary in
line 8, although a full URL could be used if desired. Line 11 determines the size of the displayed graphic;
this can be set independently of the dimensions of the graphic itself, although in this case they are the same
(32 pixels). Should a graphic be rectangular, the value will apply to the height of the graphic only,
with the width scaled proportionally.
Fig. 6.25: Graphic used for points
Point with default label
This example shows a text label on the Simple point that displays the “name” attribute of the point. This is
how a label will be displayed in the absence of any other customization.
Code
View and download the full "Point with default label" SLD
280
Chapter 6. Styling
GeoServer User Manual, Release 2.15.1
Fig. 6.26: Point with default label
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
circle#FF00006#000000
Details
Lines 3-13, which contain the , are identical to the Simple point example above. The
label is set in the on lines 14-27. Lines 15-17 determine what text to display in the
label, which in this case is the value of the “name” attribute. (Refer to the attribute table in the Example
points layer section if necessary.) Line 19 sets the text color. All other details about the label are set to the
renderer default, which here is Times New Roman font, font color black, and font size of 10 pixels. The
bottom left of the label is aligned with the center of the point.
Point with styled label
This example improves the label style from the Point with default label example by centering the label above
the point and providing a different font name and size.
6.2. SLD Styling
281
GeoServer User Manual, Release 2.15.1
Fig. 6.27: Point with styled label
Code
View and download the full "Point with styled label" SLD
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
circle#FF00006Arial12normalbold0.50.005
282
Chapter 6. Styling
GeoServer User Manual, Release 2.15.1
37
38
39
40
41
#000000
Details
In this example, lines 3-13 are identical to the Simple point example above. The on
lines 14-39 contains many more details about the label styling than the previous example, Point with default
label. Lines 15-17 once again specify the “name” attribute as text to display. Lines 18-23 set the font information: line 19 sets the font family to be “Arial”, line 20 sets the font size to 12, line 21 sets the font style
to “normal” (as opposed to “italic” or “oblique”), and line 22 sets the font weight to “bold” (as opposed to
“normal”). Lines 24-35 () determine the placement of the label relative to the point.
The (lines 26-29) sets the point of intersection between the label and point, which here
(line 27-28) sets the point to be centered (0.5) horizontally axis and bottom aligned (0.0) vertically with the
label. There is also (lines 30-33), which sets the offset of the label relative to the line,
which in this case is 0 pixels horizontally (line 31) and 5 pixels vertically (line 32). Finally, line 37 sets the
font color of the label to black (#000000).
The result is a centered bold label placed slightly above each point.
Point with rotated label
This example builds on the previous example, Point with styled label, by rotating the label by 45 degrees,
positioning the labels farther away from the points, and changing the color of the label to purple.
Fig. 6.28: Point with rotated label
Code
View and download the full "Point with rotated label" SLD
1
2
3
4
6.2. SLD Styling
283
GeoServer User Manual, Release 2.15.1
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
circle#FF00006Arial12normalbold0.50.0025-45#990099
Details
This example is similar to the Point with styled label, but there are three important differences. Line 32
specifies 25 pixels of vertical displacement. Line 34 specifies a rotation of “-45” or 45 degrees counterclockwise. (Rotation values increase clockwise, which is why the value is negative.) Finally, line 38 sets the
font color to be a shade of purple (#99099).
Note that the displacement takes effect before the rotation during rendering, so in this example, the 25 pixel
vertical displacement is itself rotated 45 degrees.
Attribute-based point
This example alters the size of the symbol based on the value of the population (“pop”) attribute.
284
Chapter 6. Styling
GeoServer User Manual, Release 2.15.1
Fig. 6.29: Attribute-based point
Code
View and download the full "Attribute-based point" SLD
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
SmallPop1 to 50000pop50000circle#0033CC8MediumPop50000 to 100000pop50000pop100000
6.2. SLD Styling
285
GeoServer User Manual, Release 2.15.1
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
circle#0033CC12LargePopGreater than 100000pop100000circle#0033CC16
Details
Note: Refer to the Example points layer to see the attributes for this data. This example has eschewed labels
in order to simplify the style, but you can refer to the example Point with styled label to see which attributes
correspond to which points.
This style contains three rules. Each varies the style based on the value of the population (“pop”)
attribute for each point, with smaller values yielding a smaller circle, and larger values yielding a larger
circle.
The three rules are designed as follows:
Rule order
1
2
3
286
Rule name
SmallPop
MediumPop
LargePop
Population (“pop”)
Less than 50,000
50,000 to 100,000
Greater than 100,000
Size
8
12
16
Chapter 6. Styling
GeoServer User Manual, Release 2.15.1
The order of the rules does not matter in this case, since each shape is only rendered by a single rule.
The first rule, on lines 2-22, specifies the styling of those points whose population attribute is less than
50,000. Lines 5-10 set this filter, with lines 6-9 setting the “less than” filter, line 7 denoting the attribute
(“pop”), and line 8 the value of 50,000. The symbol is a circle (line 14), the color is dark blue (#0033CC, on
line 16), and the size is 8 pixels in diameter (line 19).
The second rule, on lines 23-49, specifies a style for points whose population attribute is greater than or
equal to 50,000 and less than 100,000. The population filter is set on lines 26-37. This filter is longer than
in the first rule because two criteria need to be specified instead of one: a “greater than or equal to” and a
“less than” filter. Notice the And on line 27 and line 36. This mandates that both filters need to be true for
the rule to be applicable. The size of the graphic is set to 12 pixels on line 46. All other styling directives
are identical to the first rule.
The third rule, on lines 50-70, specifies a style for points whose population attribute is greater than or equal
to 100,000. The population filter is set on lines 53-58, and the only other difference is the size of the circle,
which in this rule (line 67) is 16 pixels.
The result of this style is that cities with larger populations have larger points.
Zoom-based point
This example alters the style of the points at different zoom levels.
Fig. 6.30: Zoom-based point: Zoomed in
Code
View and download the full "Zoom-based point" SLD
6.2. SLD Styling
287
GeoServer User Manual, Release 2.15.1
Fig. 6.31: Zoom-based point: Partially zoomed
Fig. 6.32: Zoom-based point: Zoomed out
288
Chapter 6. Styling
GeoServer User Manual, Release 2.15.1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
Large160000000circle#CC330012Medium160000000320000000circle#CC33008Small320000000circle#CC33004
Details
It is often desirable to make shapes larger at higher zoom levels when creating a natural-looking map. This
example styles the points to vary in size based on the zoom level (or more accurately, scale denominator).
Scale denominators refer to the scale of the map. A scale denominator of 10,000 means the map has a scale
of 1:10,000 in the units of the map projection.
6.2. SLD Styling
289
GeoServer User Manual, Release 2.15.1
Note: Determining the appropriate scale denominators (zoom levels) to use is beyond the scope of this
example.
This style contains three rules. The three rules are designed as follows:
Rule order
1
2
Rule name
Large
Medium
3
Small
Scale denominator
1:160,000,000 or less
1:160,000,000
to
1:320,000,000
Greater
than
1:320,000,000
Point size
12
8
4
The order of these rules does not matter since the scales denominated in each rule do not overlap.
The first rule (lines 2-16) is for the smallest scale denominator, corresponding to when the view is “zoomed
in”. The scale rule is set on line 4, so that the rule will apply to any map with a scale denominator of
160,000,000 or less. The rule draws a circle (line 8), colored red (#CC3300 on line 10) with a size of 12 pixels
(line 13).
The second rule (lines 17-32) is the intermediate scale denominator, corresponding to when the view is
“partially zoomed”. The scale rules are set on lines 19-20, so that the rule will apply to any map with a
scale denominator between 160,000,000 and 320,000,000. (The is inclusive and
the is exclusive, so a zoom level of exactly 320,000,000 would not apply here.)
Aside from the scale, the only difference between this rule and the first is the size of the symbol, which is
set to 8 pixels on line 29.
The third rule (lines 33-47) is the largest scale denominator, corresponding to when the map is “zoomed
out”. The scale rule is set on line 35, so that the rule will apply to any map with a scale denominator of
320,000,000 or more. Again, the only other difference between this rule and the others is the size of the
symbol, which is set to 4 pixels on line 44.
The result of this style is that points are drawn larger as one zooms in and smaller as one zooms out.
Lines
While lines can also seem to be simple shapes, having length but no width, there are many options and
tricks for making lines display nicely.
Warning: The code examples shown on this page are not the full SLD code, as they omit the SLD
header and footer information for the sake of brevity. Please use the links to download the full SLD for
each example.
Example lines layer
The lines layer used in the examples below contains road information for a fictional country. For reference, the attribute table for the points in this layer is included below.
290
Chapter 6. Styling
GeoServer User Manual, Release 2.15.1
fid (Feature ID)
line.1
line.2
line.3
line.4
line.5
line.6
line.7
line.8
line.9
line.10
line.11
line.12
line.13
line.14
line.15
line.16
line.17
line.18
line.19
line.20
line.21
line.22
line.23
line.24
line.25
name (Road name)
Latway
Crescent Avenue
Forest Avenue
Longway
Saxer Avenue
Ridge Avenue
Holly Lane
Mulberry Street
Nathan Lane
Central Street
Lois Lane
Rocky Road
Fleet Street
Diane Court
Cedar Trail
Victory Road
Highland Road
Easy Street
Hill Street
Country Road
Main Street
Jani Lane
Shinbone Alley
State Street
River Road
type (Road class)
highway
secondary
secondary
highway
secondary
secondary
local-road
local-road
local-road
local-road
local-road
local-road
local-road
local-road
local-road
local-road
local-road
local-road
local-road
local-road
local-road
local-road
local-road
local-road
local-road
Download the lines shapefile
Simple line
This example specifies lines be colored black with a thickness of 3 pixels.
Code
View and download the full "Simple line" SLD
1
2
3
4
5
6
7
8
9
10
#0000003
6.2. SLD Styling
291
GeoServer User Manual, Release 2.15.1
Fig. 6.33: Simple line
Details
There is one in one for this SLD, which is the simplest possible situation.
(All subsequent examples will contain one and one unless otherwise specified.) Styling lines is accomplished via the (lines 3-8). Line 5 specifies the color of
the line to be black (#000000), while line 6 specifies the width of the lines to be 3 pixels.
Line with border
This example shows how to draw lines with borders (sometimes called “cased lines”). In this case the lines
are drawn with a 3 pixel blue center and a 1 pixel wide gray border.
Code
View and download the full "Line with border" SLD
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#3333335round
292
Chapter 6. Styling
GeoServer User Manual, Release 2.15.1
Fig. 6.34: Line with border
15
16
17
18
19
20
21
22
#6699FF3round
Details
Lines in SLD have no notion of a “fill”, only “stroke”. Thus, unlike points or polygons, it is not possible
to style the “edge” of the line geometry. It is, however, possible to achieve this effect by drawing each line
twice: once with a certain width and again with a slightly smaller width. This gives the illusion of fill and
stroke by obscuring the larger lines everywhere except along the edges of the smaller lines.
Since every line is drawn twice, the order of the rendering is very important. GeoServer renders
s in the order that they are presented in the SLD. In this style, the gray border
lines are drawn first via the first , followed by the blue center lines in a second
. This ensures that the blue lines are not obscured by the gray lines, and also ensures proper rendering at intersections, so that the blue lines “connect”.
In this example, lines 1-11 comprise the first , which is the outer line (or “stroke”).
Line 5 specifies the color of the line to be dark gray (#333333), line 6 specifies the width of this line to be
5 pixels, and in line 7 a stroke-linecap parameter of round renders the ends of the line as rounded
instead of flat. (When working with bordered lines using a round line cap ensures that the border connects
properly at the ends of the lines.)
Lines 12-22 comprise the second , which is the the inner line (or “fill”). Line 16
specifies the color of the line to be a medium blue (#6699FF), line 17 specifies the width of this line to be 3
pixels, and line 18 again renders the edges of the line to be rounded instead of flat.
6.2. SLD Styling
293
GeoServer User Manual, Release 2.15.1
The result is a 3 pixel blue line with a 1 pixel gray border, since the 5 pixel gray line will display 1 pixel on
each side of the 3 pixel blue line.
Dashed line
This example alters the Simple line to create a dashed line consisting of 5 pixels of drawn line alternating
with 2 pixels of blank space.
Fig. 6.35: Dashed line
Code
View and download the full "Dashed line" SLD
1
2
3
4
5
6
7
8
9
10
11
#0000FF35 2
Details
In this example, line 5 sets the color of the lines to be blue (#0000FF) and line 6 sets the width of the lines
to be 3 pixels. Line 7 determines the composition of the line dashes. The value of 5 2 creates a repeating
pattern of 5 pixels of drawn line, followed by 2 pixels of omitted line.
294
Chapter 6. Styling
GeoServer User Manual, Release 2.15.1
Offset line
This example alters the Simple line to add a perpendicular offset line on the left side of the line, at five pixels
distance.
Fig. 6.36: Offset line
Code
View and download the full "Dashed line" SLD
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#000000#FF00005 25
Details
In this example, the first line symbolizer just paints the lines black. line 8 begines a second lines symbolizer,
sets the color of the lines to be red (#FF0000) at line 10 and determines the composition of the line dashes
6.2. SLD Styling
295
GeoServer User Manual, Release 2.15.1
at Line 11. Line 13 finally specifies a perpendicular offset of 5 pixels (positive, thus on the left side).
Railroad (hatching)
This example uses hatching to create a railroad style. Both the line and the hatches are black, with a 2 pixel
thickness for the main line and a 1 pixel width for the perpendicular hatches.
Note: This example leverages an SLD extension in GeoServer. Hatching is not part of the standard SLD 1.0
specification.
Fig. 6.37: Railroad (hatching)
Code
View and download the full "Railroad (hatching)" SLD
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#3333333shape://vertline
296
Chapter 6. Styling
GeoServer User Manual, Release 2.15.1
16
17
18
19
20
21
22
23
24
25
26
#333333112
Details
In this example there are two s. The first symbolizer, on lines 3-8, draws a standard
line, with line 5 drawing the lines as dark gray (#333333) and line 6 setting the width of the lines to be 2
pixels.
The hatching is invoked in the second symbolizer, on lines 9-24. Line 14 specifies that the symbolizer draw
a vertical line hatch (shape://vertline) perpendicular to the line geometry. Lines 16-17 set the hatch
color to dark gray (#333333) and width to 1 pixel. Finally, line 20 specifies both the length of the hatch
and the distance between each hatch to both be 12 pixels.
Spaced graphic symbols
This example uses a graphic stroke along with dash arrays to create a “dot and space” line type. Adding the
dash array specification allows to control the amount of space between one symbol and the next one. Without using the dash array the lines would be densely populated with dots, each one touching the previous
one.
Note: This example may not work in other systems using SLD, since they may not support combining the
use of stroke-dasharray and GraphicStroke. While the SLD is spec-compliant, the SLD specification
does not state what this combination is supposed to produce.
Code
View and download the full "Spaced symbols" SLD
1
2
3
4
5
6
7
8
9
10
11
12
13
circle#666666#333333
6.2. SLD Styling
297
GeoServer User Manual, Release 2.15.1
Fig. 6.38: Spaced symbols along a line
14
15
16
17
18
19
20
21
22
23
24
144 6
Details
This example, like others before, uses a GraphicStroke to place a graphic symbol along a line. The
symbol, defined at lines 7-16 is a 4 pixel gray circle with a dark gray outline. The spacing between symbols
is controlled with the stroke-dasharray at line 20, which specifies 4 pixels of pen-down (just enough to
draw the circle) and 6 pixels of pen-up, to provide the spacing.
Alternating symbols with dash offsets
This example shows how to create a complex line style which alternates a dashed line and a graphic symbol.
The code builds on features shown in the previous examples:
• stroke-dasharray controls pen-down/pen-up behavior to generate dashed lines
• GraphicStroke places symbols along a line
• combining the two allows control of symbol spacing
This also shows the usage of a dash offset, which controls where rendering starts in the dash array. For
example, with a dash array of 5 10 and a dash offset of 7 the renderer starts drawing the pattern 7 pixels
from the beginning. It skips the 5 pixels pen-down section and 2 pixels of the pen-up section, then draws
the remaining 8 pixels of pen-up, then 5 down, 10 up, and so on.
298
Chapter 6. Styling
GeoServer User Manual, Release 2.15.1
The example shows how to use these features to create two synchronized sequences of dash arrays, one
drawing line segments and the other symbols.
Note: This example may not work in other systems using SLD, since they may not support combining the
use of stroke-dasharray and GraphicStroke. While the SLD is spec-compliant, the SLD specification
does not state what this combination is supposed to produce.
Fig. 6.39: Alternating dash and symbol
Code
View and download the full "Spaced symbols" SLD
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#0000FF110 10circle#000033155 15
6.2. SLD Styling
299
GeoServer User Manual, Release 2.15.1
25
26
27
28
29
7.5
Details
In this example two LineSymbolizers use stroke-dasharray and different symbology to produce
a sequence of alternating dashes and symbols. The first symbolizer (lines 3-9) is a simple dashed line
alternating 10 pixels of pen-down with 10 pixels of pen-up. The second symbolizer (lines 10-27) alternates
a 5 pixel empty circle with 15 pixels of white space. The circle symbol is produced by a Mark element, with
its symbology specified by stroke parameters (lines 17-18). The spacing between symbols is controlled
with the stroke-dasharray (line 24), which specifies 5 pixels of pen-down (just enough to draw the
circle) and 15 pixels of pen-up. In order to have the two sequences positioned correctly the second one uses
a stroke-dashoffset of 7.5 (line 25). This makes the sequence start with 12.5 pixels of white space, then
a circle (which is then centered between the two line segments of the other pattern), then 15 pixels of white
space, and so on.
Line with default label
This example shows a text label on the simple line. This is how a label will be displayed in the absence of
any other customization.
Fig. 6.40: Line with default label
Code
View and download the full "Line with default label" SLD
300
Chapter 6. Styling
GeoServer User Manual, Release 2.15.1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#FF0000#000000
Details
In this example, there is one rule with a and a . The
(lines 3-7) draws red lines (#FF0000). Since no width is specified, the default is
set to 1 pixel. The (lines 8-15) determines the labeling of the lines. Lines 9-11 specify
that the text of the label will be determined by the value of the “name” attribute for each line. (Refer to the
attribute table in the Example lines layer section if necessary.) Line 13 sets the text color to black. All other
details about the label are set to the renderer default, which here is Times New Roman font, font color black,
and font size of 10 pixels.
Label following line
This example renders the text label to follow the contour of the lines.
Note: Labels following lines is an SLD extension specific to GeoServer. It is not part of the SLD 1.0
specification.
Code
View and download the full "Label following line" SLD
1
2
3
4
5
6
7
8
9
#FF0000#000000true
Details
As the Alternating symbols with dash offsets example showed, the default label behavior isn’t optimal. The
label is displayed at a tangent to the line itself, leading to uncertainty as to which label corresponds to
which line.
This example is similar to the Alternating symbols with dash offsets example with the exception of lines 12-18.
Line 18 sets the option to have the label follow the line, while lines 12-14 specify that the label is placed
along a line. If is not specified in an SLD, then is assumed,
which isn’t compatible with line-specific rendering options.
Note: Not all labels are shown due to label conflict resolution. See the next section on Optimized label
placement for an example of how to maximize label display.
302
Chapter 6. Styling
GeoServer User Manual, Release 2.15.1
Optimized label placement
This example optimizes label placement for lines such that the maximum number of labels are displayed.
Note: This example uses options that are specific to GeoServer and are not part of the SLD 1.0 specification.
Fig. 6.42: Optimized label
Code
View and download the full "Optimized label" SLD
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#FF0000#000000true90400150
6.2. SLD Styling
303
GeoServer User Manual, Release 2.15.1
22
23
24
Details
GeoServer uses “conflict resolution” to ensure that labels aren’t drawn on top of other labels, obscuring
them both. This accounts for the reason why many lines don’t have labels in the previous example, Label
following line. While this setting can be toggled, it is usually a good idea to leave it on and use other label
placement options to ensure that labels are drawn as often as desired and in the correct places. This example
does just that.
This example is similar to the previous example, Label following line. The only differences are contained in
lines 18-21. Line 19 sets the maximum angle that the label will follow. This sets the label to never bend
more than 90 degrees to prevent the label from becoming illegible due to a pronounced curve or angle.
Line 20 sets the maximum displacement of the label to be 400 pixels. In order to resolve conflicts with
overlapping labels, GeoServer will attempt to move the labels such that they are no longer overlapping.
This value sets how far the label can be moved relative to its original placement. Finally, line 21 sets the
labels to be repeated every 150 pixels. A feature will typically receive only one label, but this can cause
confusion for long lines. Setting the label to repeat ensures that the line is always labeled locally.
Optimized and styled label
This example improves the style of the labels from the Optimized label placement example.
Fig. 6.43: Optimized and styled label
Code
View and download the full "Optimized and styled label" SLD
304
Chapter 6. Styling
GeoServer User Manual, Release 2.15.1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#FF0000#000000Arial10normalboldtrue90400150
Details
This example is similar to the Optimized label placement. The only difference is in the font information, which
is contained in lines 18-23. Line 19 sets the font family to be “Arial”, line 20 sets the font size to 10, line
21 sets the font style to “normal” (as opposed to “italic” or “oblique”), and line 22 sets the font weight to
“bold” (as opposed to “normal”).
Attribute-based line
This example styles the lines differently based on the “type” (Road class) attribute.
Code
View and download the full "Attribute-based line" SLD
1
2
3
4
5
6
7
local-roadtypelocal-road
6.2. SLD Styling
305
GeoServer User Manual, Release 2.15.1
Fig. 6.44: Attribute-based line
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#0099332secondarytypesecondary#0055CC3highwaytype
306
Chapter 6. Styling
GeoServer User Manual, Release 2.15.1
41
42
43
44
45
46
47
48
49
50
51
highway#FF00006
Details
Note: Refer to the Example lines layer to see the attributes for the layer. This example has eschewed labels in
order to simplify the style, but you can refer to the example Optimized and styled label to see which attributes
correspond to which points.
There are three types of road classes in our fictional country, ranging from back roads to high-speed freeways: “highway”, “secondary”, and “local-road”. In order to handle each case separately, there is more
than one , each containing a single rule. This ensures that each road type is rendered in order, as each is drawn based on the order in which it appears in the
SLD.
The three rules are designed as follows:
Rule order
1
2
3
Rule name / type
local-road
secondary
highway
Color
#009933 (green)
#0055CC (blue)
#FF0000 (red)
Size
2
3
6
Lines 2-16 comprise the first . Lines 4-9 set the filter for this rule, such that the “type” attribute
has a value of “local-road”. If this condition is true for a particular line, the rule is rendered according to
the which is on lines 10-15. Lines 12-13 set the color of the line to be a dark green
(#009933) and the width to be 2 pixels.
Lines 19-33 comprise the second . Lines 21-26 set the filter for this rule, such that the “type”
attribute has a value of “secondary”. If this condition is true for a particular line, the rule is rendered
according to the which is on lines 27-32. Lines 29-30 set the color of the line to be a
dark blue (#0055CC) and the width to be 3 pixels, making the lines slightly thicker than the “local-road”
lines and also a different color.
Lines 36-50 comprise the third and final . Lines 38-43 set the filter for this rule, such that the
“type” attribute has a value of “primary”. If this condition is true for a particular line, the rule is rendered
according to the which is on lines 44-49. Lines 46-47 set the color of the line to be a
bright red (#FF0000) and the width to be 6 pixels, so that these lines are rendered on top of and thicker
than the other two road classes. In this way, the “primary” roads are given priority in the map rendering.
Zoom-based line
This example alters the Simple line style at different zoom levels.
6.2. SLD Styling
307
GeoServer User Manual, Release 2.15.1
Fig. 6.45: Zoom-based line: Zoomed in
Fig. 6.46: Zoom-based line: Partially zoomed
308
Chapter 6. Styling
GeoServer User Manual, Release 2.15.1
Fig. 6.47: Zoom-based line: Zoomed out
Code
View and download the full "Zoom-based line" SLD
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
Large180000000#0099336Medium180000000360000000#0099334Small360000000#0099332
6.2. SLD Styling
309
GeoServer User Manual, Release 2.15.1
31
32
33
Details
It is often desirable to make shapes larger at higher zoom levels when creating a natural-looking map. This
example varies the thickness of the lines according to the zoom level (or more accurately, scale denominator). Scale denominators refer to the scale of the map. A scale denominator of 10,000 means the map has a
scale of 1:10,000 in the units of the map projection.
Note: Determining the appropriate scale denominators (zoom levels) to use is beyond the scope of this
example.
This style contains three rules. The three rules are designed as follows:
Rule order
1
2
3
Rule name
Large
Medium
Small
Scale denominator
1:180,000,000 or less
1:180,000,000 to 1:360,000,000
Greater than 1:360,000,000
Line width
6
4
2
The order of these rules does not matter since the scales denominated in each rule do not overlap.
The first rule (lines 2-11) is the smallest scale denominator, corresponding to when the view is “zoomed in”.
The scale rule is set on line 4, so that the rule will apply to any map with a scale denominator of 180,000,000
or less. Line 7-8 draws the line to be dark green (#009933) with a width of 6 pixels.
The second rule (lines 12-22) is the intermediate scale denominator, corresponding to when the view is
“partially zoomed”. Lines 14-15 set the scale such that the rule will apply to any map with scale denominators between 180,000,000 and 360,000,000. (The is inclusive and the
is exclusive, so a zoom level of exactly 360,000,000 would not apply here.)
Aside from the scale, the only difference between this rule and the previous is the width of the lines, which
is set to 4 pixels on line 19.
The third rule (lines 23-32) is the largest scale denominator, corresponding to when the map is “zoomed
out”. The scale rule is set on line 25, so that the rule will apply to any map with a scale denominator of
360,000,000 or greater. Again, the only other difference between this rule and the others is the width of the
lines, which is set to 2 pixels on line 29.
The result of this style is that lines are drawn with larger widths as one zooms in and smaller widths as one
zooms out.
Polygons
Polygons are two dimensional shapes that contain both an outer edge (or “stroke”) and an inside (or “fill”).
A polygon can be thought of as an irregularly-shaped point and is styled in similar ways to points.
Warning: The code examples shown on this page are not the full SLD code, as they omit the SLD
header and footer information for the sake of brevity. Please use the links to download the full SLD for
each example.
310
Chapter 6. Styling
GeoServer User Manual, Release 2.15.1
Example polygons layer
The polygons layer used below contains county information for a fictional country. For reference, the
attribute table for the polygons is included below.
fid (Feature ID)
polygon.1
polygon.2
polygon.3
polygon.4
polygon.5
polygon.6
polygon.7
polygon.8
name (County name)
Irony County
Tracker County
Dracula County
Poly County
Bearing County
Monte Cristo County
Massive County
Rhombus County
pop (Population)
412234
235421
135022
1567879
201989
152734
67123
198029
Download the polygons shapefile
Simple polygon
This example shows a polygon filled in blue.
Fig. 6.48: Simple polygon
Code
View and download the full "Simple polygon" SLD
1
2
3
6.2. SLD Styling
311
GeoServer User Manual, Release 2.15.1
4
5
6
7
8
9
#000080
Details
There is one in one for this style, which is the simplest possible situation.
(All subsequent examples will share this characteristic unless otherwise specified.) Styling polygons is
accomplished via the (lines 3-7). Line 5 specifies dark blue (#000080) as the
polygon’s fill color.
Note: The light-colored borders around the polygons in the figure are artifacts of the renderer caused by
the polygons being adjacent. There is no border in this style.
Simple polygon with stroke
This example adds a 2 pixel white stroke to the Simple polygon example.
Fig. 6.49: Simple polygon with stroke
Code
View and download the full "Simple polygon with stroke" SLD
312
Chapter 6. Styling
GeoServer User Manual, Release 2.15.1
1
2
3
4
5
6
7
8
9
10
11
12
13
#000080#FFFFFF2
Details
This example is similar to the Simple polygon example above, with the addition of the tag (lines
7-10). Line 8 sets the color of stroke to white (#FFFFFF) and line 9 sets the width of the stroke to 2 pixels.
Transparent polygon
This example builds on the Simple polygon with stroke example and makes the fill partially transparent by
setting the opacity to 50%.
Fig. 6.50: Transparent polygon
Code
View and download the full "Transparent polygon" SLD
6.2. SLD Styling
313
GeoServer User Manual, Release 2.15.1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#0000800.5#FFFFFF2
Details
This example is similar to the Simple polygon with stroke example, save for defining the fill’s opacity in line
6. The value of 0.5 results in partially transparent fill that is 50% opaque. An opacity value of 1 would draw
the fill as 100% opaque, while an opacity value of 0 would result in a completely transparent (0% opaque)
fill. In this example, since the background is white, the dark blue looks lighter. Were the points imposed on
a dark background, the resulting color would be darker.
Offset inner lines
Shows how to draw inner buffer lines inside a polygon.
Fig. 6.51: Offset buffer
314
Chapter 6. Styling
GeoServer User Manual, Release 2.15.1
Code
View and download the full "Inner offset lines" SLD
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#0000002#AAAAAA3-2
Details
This example is similar to the Simple polygon with stroke example, save for defining adding a
> at line 9, where a light gray (line 11) 3 pixels wide (line 12) line is drawn as a
inner buffer inside the polygon. Line 14 controls the buffering distance, setting a inner buffer of 2 pixels.
Graphic fill
This example fills the polygons with a tiled graphic.
Fig. 6.52: Graphic fill
6.2. SLD Styling
315
GeoServer User Manual, Release 2.15.1
Code
View and download the full "Graphic fill" SLD
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
image/png93
Details
This style fills the polygon with a tiled graphic. This is known as an in SLD, to
distinguish it from commonly-used shapes such as squares and circles that are “internal” to the renderer.
Lines 7-12 specify details for the graphic, with line 10 setting the path and file name of the graphic and
line 11 indicating the file format (MIME type) of the graphic (image/png). Although a full URL could
be specified if desired, no path information is necessary in line 11 because this graphic is contained in the
same directory as the SLD. Line 13 determines the height of the displayed graphic in pixels; if the value
differs from the height of the graphic then it will be scaled accordingly while preserving the aspect ratio.
Fig. 6.53: Graphic used for fill
Hatching fill
This example fills the polygons with a hatching pattern.
Note: This example leverages an SLD extension in GeoServer. Hatching is not part of the standard SLD 1.0
specification.
316
Chapter 6. Styling
GeoServer User Manual, Release 2.15.1
Fig. 6.54: Hatching fill
Code
View and download the full "Hatching fill" SLD
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
shape://times#990099116
Details
In this example, there is a tag as in the Graphic fill example, but a (lines 7-13) is
used instead of an . Line 8 specifies a “times” symbol (an “x”) be tiled throughout
the polygon. Line 10 sets the color to purple (#990099), line 11 sets the width of the hatches to 1 pixel, and
line 14 sets the size of the tile to 16 pixels. Because hatch tiles are always square, the sets both the
6.2. SLD Styling
317
GeoServer User Manual, Release 2.15.1
width and the height.
Polygon with default label
This example shows a text label on the polygon. In the absence of any other customization, this is how a
label will be displayed.
Fig. 6.55: Polygon with default label
Code
View and download the full "Polygon with default label" SLD
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#40FF40#FFFFFF2
318
Chapter 6. Styling
GeoServer User Manual, Release 2.15.1
Details
In this example there is a and a . Lines 3-11 comprise the
. The fill of the polygon is set on line 5 to a light green (#40FF40) while the stroke
of the polygon is set on lines 8-9 to white (#FFFFFF) with a thickness of 2 pixels. The label is set in the
on lines 12-16, with line 14 determining what text to display, in this case the value
of the “name” attribute. (Refer to the attribute table in the Example polygons layer section if necessary.) All
other details about the label are set to the renderer default, which here is Times New Roman font, font color
black, and font size of 10 pixels.
Label halo
This example alters the look of the Polygon with default label by adding a white halo to the label.
Fig. 6.56: Label halo
Code
View and download the full "Label halo" SLD
1
2
3
4
5
6
7
8
9
10
11
12
#40FF40#FFFFFF2
6.2. SLD Styling
319
GeoServer User Manual, Release 2.15.1
13
14
15
16
17
18
19
20
21
22
23
24
3#FFFFFF
Details
This example is similar to the Polygon with default label, with the addition of a halo around the labels on
lines 16-21. A halo creates a color buffer around the label to improve label legibility. Line 17 sets the radius
of the halo, extending the halo 3 pixels around the edge of the label, and line 19 sets the color of the halo
to white (#FFFFFF). Since halos are most useful when set to a sharp contrast relative to the text color, this
example uses a white halo around black text to ensure optimum readability.
Polygon with styled label
This example improves the label style from the Polygon with default label example by centering the label on
the polygon, specifying a different font name and size, and setting additional label placement optimizations.
Note: The label placement optimizations discussed below (the tags) are SLD extensions
that are custom to GeoServer. They are not part of the SLD 1.0 specification.
Code
View and download the full "Polygon with styled label" SLD
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#40FF40#FFFFFF2Arial
320
Chapter 6. Styling
GeoServer User Manual, Release 2.15.1
Fig. 6.57: Polygon with styled label
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
11normalbold0.50.5#00000060150
Details
This example is similar to the Polygon with default label example, with additional styling options within the
on lines 12-35. Lines 16-21 set the font styling. Line 17 sets the font family to be
Arial, line 18 sets the font size to 11 pixels, line 19 sets the font style to “normal” (as opposed to “italic” or
“oblique”), and line 20 sets the font weight to “bold” (as opposed to “normal”).
The tag on lines 22-29 affects where the label is placed relative to the centroid of the
polygon. Line 21 centers the label by positioning it 50% (or 0.5) of the way horizontally along the centroid
of the polygon. Line 22 centers the label vertically in exactly the same way.
6.2. SLD Styling
321
GeoServer User Manual, Release 2.15.1
Finally, there are two added touches for label placement optimization: line 33 ensures that long labels are
split across multiple lines by setting line wrapping on the labels to 60 pixels, and line 34 allows the label to
be displaced by up to 150 pixels. This ensures that labels are compacted and less likely to spill over polygon
boundaries. Notice little Massive County in the corner, whose label is now displayed.”
Attribute-based polygon
This example styles the polygons differently based on the “pop” (Population) attribute.
Fig. 6.58: Attribute-based polygon
Code
View and download the full "Attribute-based polygon" SLD
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
SmallPopLess Than 200,000pop200000#66FF66MediumPop
322
Chapter 6. Styling
GeoServer User Manual, Release 2.15.1
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
200,000 to 500,000pop200000pop500000#33CC33LargePopGreater Than 500,000pop500000#009900
Details
Note: Refer to the Example polygons layer to see the attributes for the layer. This example has eschewed
labels in order to simplify the style, but you can refer to the example Polygon with styled label to see which
attributes correspond to which polygons.
Each polygon in our fictional country has a population that is represented by the population (“pop”) attribute. This style contains three rules that alter the fill based on the value of “pop” attribute, with smaller
values yielding a lighter color and larger values yielding a darker color.
The three rules are designed as follows:
Rule order
1
2
3
6.2. SLD Styling
Rule name
SmallPop
MediumPop
LargePop
Population (“pop”)
Less than 200,000
200,000 to 500,000
Greater than 500,000
Color
#66FF66
#33CC33
#009900
323
GeoServer User Manual, Release 2.15.1
The order of the rules does not matter in this case, since each shape is only rendered by a single rule.
The first rule, on lines 2-16, specifies the styling of polygons whose population attribute is less than 200,000.
Lines 5-10 set this filter, with lines 6-9 setting the “less than” filter, line 7 denoting the attribute (“pop”),
and line 8 the value of 200,000. The color of the polygon fill is set to a light green (#66FF66) on line 13.
The second rule, on lines 17-37, is similar, specifying a style for polygons whose population attribute is
greater than or equal to 200,000 but less than 500,000. The filter is set on lines 20-31. This filter is longer
than in the first rule because two criteria need to be specified instead of one: a “greater than or equal to”
and a “less than” filter. Notice the And on line 21 and line 30. This mandates that both filters need to be
true for the rule to be applicable. The color of the polygon fill is set to a medium green on (#33CC33) on
line 34.
The third rule, on lines 38-52, specifies a style for polygons whose population attribute is greater than or
equal to 500,000. The filter is set on lines 41-46. The color of the polygon fill is the only other difference in
this rule, which is set to a dark green (#009900) on line 49.
Zoom-based polygon
This example alters the style of the polygon at different zoom levels.
Fig. 6.59: Zoom-based polygon: Zoomed in
Code
View and download the full "Zoom-based polygon" SLD
1
2
3
4
5
6
Large100000000
324
Chapter 6. Styling
GeoServer User Manual, Release 2.15.1
Fig. 6.60: Zoom-based polygon: Partially zoomed
Fig. 6.61: Zoom-based polygon: Zoomed out
6.2. SLD Styling
325
GeoServer User Manual, Release 2.15.1
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#0000CC#0000007Arial14normalbold0.50.5#FFFFFFMedium100000000200000000#0000CC#0000004Small200000000#0000CC#0000001
326
Chapter 6. Styling
GeoServer User Manual, Release 2.15.1
Details
It is often desirable to make shapes larger at higher zoom levels when creating a natural-looking map. This
example varies the thickness of the lines according to the zoom level. Polygons already do this by nature of
being two dimensional, but another way to adjust styling of polygons based on zoom level is to adjust the
thickness of the stroke (to be larger as the map is zoomed in) or to limit labels to only certain zoom levels.
This is ensures that the size and quantity of strokes and labels remains legible and doesn’t overshadow the
polygons themselves.
Zoom levels (or more accurately, scale denominators) refer to the scale of the map. A scale denominator of
10,000 means the map has a scale of 1:10,000 in the units of the map projection.
Note: Determining the appropriate scale denominators (zoom levels) to use is beyond the scope of this
example.
This style contains three rules, defined as follows:
Rule order
Rule name
Scale denominator
1
2
3
Large
Medium
Small
1:100,000,000 or less
1:100,000,000 to 1:200,000,000
Greater than 1:200,000,000
Stroke
width
7
4
2
Label
play?
Yes
No
No
dis-
The first rule, on lines 2-36, is for the smallest scale denominator, corresponding to when the view is
“zoomed in”. The scale rule is set on line 40 such that the rule will apply only where the scale denominator is 100,000,000 or less. Line 7 defines the fill as blue (#0000CC). Note that the fill is kept constant
across all rules regardless of the scale denominator. As in the Polygon with default label or Polygon with styled
label examples, the rule also contains a at lines 14-35 for drawing a text label on top of
the polygon. Lines 19-22 set the font information to be Arial, 14 pixels, and bold with no italics. The label is
centered both horizontally and vertically along the centroid of the polygon on by setting
and to both be 0.5 (or 50%) on lines 27-28. Finally, the color of the font is set to white
(#FFFFFF) in line 33.
The second rule, on lines 37-50, is for the intermediate scale denominators, corresponding to when the view
is “partially zoomed”. The scale rules on lines 39-40 set the rule such that it will apply to any map with a
scale denominator between 100,000,000 and 200,000,000. (The is inclusive and
the is exclusive, so a zoom level of exactly 200,000,000 would not apply here.)
Aside from the scale, there are two differences between this rule and the first: the width of the stroke is set
to 4 pixels on line 47 and a is not present so that no labels will be displayed.
The third rule, on lines 51-63, is for the largest scale denominator, corresponding to when the map is
“zoomed out”. The scale rule is set on line 53 such that the rule will apply to any map with a scale denominator of 200,000,000 or greater. Again, the only differences between this rule and the others are the
width of the lines, which is set to 1 pixel on line 60, and the absence of a so that no
labels will be displayed.
The resulting style produces a polygon stroke that gets larger as one zooms in and labels that only display
when zoomed in to a sufficient level.
Rasters
Rasters are geographic data displayed in a grid. They are similar to image files such as PNG files, except
that instead of each point containing visual information, each point contains geographic information in
6.2. SLD Styling
327
GeoServer User Manual, Release 2.15.1
numerical form. Rasters can be thought of as a georeferenced table of numerical values.
One example of a raster is a Digital Elevation Model (DEM) layer, which has elevation data encoded numerically at each georeferenced data point.
Warning: The code examples shown on this page are not the full SLD code, as they omit the SLD
header and footer information for the sake of brevity. Please use the links to download the full SLD for
each example.
Example raster
The raster layer that is used in the examples below contains elevation data for a fictional world. The
data is stored in EPSG:4326 (longitude/latitude) and has a data range from 70 to 256. If rendered in
grayscale, where minimum values are colored black and maximum values are colored white, the raster
would look like this:
Fig. 6.62: Raster file as rendered in grayscale
Download the raster shapefile
Two-color gradient
This example shows a two-color style with green at lower elevations and brown at higher elevations.
Fig. 6.63: Two-color gradient
328
Chapter 6. Styling
GeoServer User Manual, Release 2.15.1
Code
View and download the full "Two-color gradient" SLD
1
2
3
4
5
6
7
8
9
10
Details
There is one in one for this example, which is the simplest possible
situation. All subsequent examples will share this characteristic. Styling of rasters is done via the
tag (lines 3-8).
This example creates a smooth gradient between two colors corresponding to two elevation values. The
gradient is created via the on lines 4-7. Each entry in the represents one entry or
anchor in the gradient. Line 5 sets the lower value of 70 via the quantity parameter, which is styled a dark
green (#008000). Line 6 sets the upper value of 256 via the quantity parameter again, which is styled
a dark brown (#663333). All data values in between these two quantities will be linearly interpolated: a
value of 163 (the midpoint between 70 and 256) will be colored as the midpoint between the two colors (in
this case approximately #335717, a muddy green).
Transparent gradient
This example creates the same two-color gradient as in the Two-color gradient as in the example above but
makes the entire layer mostly transparent by setting a 30% opacity.
Fig. 6.64: Transparent gradient
Code
View and download the full "Transparent gradient" SLD
6.2. SLD Styling
329
GeoServer User Manual, Release 2.15.1
1
2
3
4
5
6
7
8
9
10
11
0.3
Details
This example is similar to the Two-color gradient example save for the addition of line 4, which sets the
opacity of the layer to 0.3 (or 30% opaque). An opacity value of 1 means that the shape is drawn 100%
opaque, while an opacity value of 0 means that the shape is rendered as completely transparent. The value
of 0.3 means that the the raster partially takes on the color and style of whatever is drawn beneath it. Since
the background is white in this example, the colors generated from the look lighter, but were
the raster imposed on a dark background the resulting colors would be darker.
Brightness and contrast
This example normalizes the color output and then increases the brightness by a factor of 2.
Fig. 6.65: Brightness and contrast
Code
View and download the full "Brightness and contrast" SLD
1
2
3
4
5
6
7
8
0.5
330
Chapter 6. Styling
GeoServer User Manual, Release 2.15.1
9
10
11
12
13
14
Details
This example is similar to the Two-color gradient, save for the addition of the
tag on lines 4-7. Line 5 normalizes the output by increasing the contrast to its maximum extent. Line 6
then adjusts the brightness by a factor of 0.5. Since values less than 1 make the output brighter, a value of
0.5 makes the output twice as bright.
As with previous examples, lines 8-11 determine the , with line 9 setting the lower bound (70)
to be colored dark green (#008000) and line 10 setting the upper bound (256) to be colored dark brown
(#663333).
Three-color gradient
This example creates a three-color gradient in primary colors.
Fig. 6.66: Three-color gradient
Code
View and download the full "Three-color gradient" SLD
1
2
3
4
5
6
7
8
9
10
11
Details
This example creates a three-color gradient based on a with three entries on lines 4-8: line 5
specifies the lower bound (150) be styled in blue (#0000FF), line 6 specifies an intermediate point (200) be
6.2. SLD Styling
331
GeoServer User Manual, Release 2.15.1
styled in yellow (#FFFF00), and line 7 specifies the upper bound (250) be styled in red (#FF0000).
Since our data values run between 70 and 256, some data points are not accounted for in this style. Those
values below the lowest entry in the color map (the range from 70 to 149) are styled the same color as the
lower bound, in this case blue. Values above the upper bound in the color map (the range from 251 to 256)
are styled the same color as the upper bound, in this case red.
Alpha channel
This example creates an “alpha channel” effect such that higher values are increasingly transparent.
Fig. 6.67: Alpha channel
Code
View and download the full "Alpha channel" SLD
1
2
3
4
5
6
7
8
9
10
Details
An alpha channel is another way of referring to variable transparency. Much like how a gradient maps
values to colors, each entry in a can have a value for opacity (with the default being 1.0 or
completely opaque).
In this example, there is a with two entries: line 5 specifies the lower bound of 70 be colored
dark green (#008000), while line 6 specifies the upper bound of 256 also be colored dark green but with
an opacity value of 0. This means that values of 256 will be rendered at 0% opacity (entirely transparent).
Just like the gradient color, the opacity is also linearly interpolated such that a value of 163 (the midpoint
between 70 and 256) is rendered at 50% opacity.
332
Chapter 6. Styling
GeoServer User Manual, Release 2.15.1
Discrete colors
This example shows a gradient that is not linearly interpolated but instead has values mapped precisely to
one of three specific colors.
Note: This example leverages an SLD extension in GeoServer. Discrete colors are not part of the standard
SLD 1.0 specification.
Fig. 6.68: Discrete colors
Code
View and download the full "Discrete colors" SLD
1
2
3
4
5
6
7
8
9
10
Details
Sometimes color bands in discrete steps are more appropriate than a color gradient.
The
type="intervals" parameter added to the on line 4 sets the display to output discrete
colors instead of a gradient. The values in each entry correspond to the upper bound for the color band
such that colors are mapped to values less than the value of one entry but greater than or equal to the next
lower entry. For example, line 5 colors all values less than 150 to dark green (#008000) and line 6 colors
all values less than 256 but greater than or equal to 150 to dark brown (#663333).
Many color gradient
This example shows a gradient interpolated across eight different colors.
6.2. SLD Styling
333
GeoServer User Manual, Release 2.15.1
Fig. 6.69: Many color gradient
Code
View and download the full "Many color gradient" SLD
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
quantity="95" />
quantity="110" />
quantity="135" />
quantity="160" />
quantity="185" />
quantity="210" />
quantity="235" />
quantity="256" />
Details
A can include up to 255 elements. This example has eight entries (lines
4-13):
Entry number
1
2
3
4
5
6
7
8
334
Value
Color
RGB code
95
110
135
160
185
210
235
256
Black
Blue
Green
Red
Purple
Yellow
Cyan
White
#000000
#0000FF
#00FF00
#FF0000
#FF00FF
#FFFF00
#00FFFF
#FFFFFF
Chapter 6. Styling
GeoServer User Manual, Release 2.15.1
6.2.4 SLD Reference
The OGC Styled Layer Descriptor (SLD) standard defines a language for expressing styling of geospatial
data. GeoServer uses SLD as its primary styling language.
SLD 1.0.0 is defined in the following specification:
• OGC Styled Layer Descriptor Implementation Specification, Version 1.0.0
Subsequently the functionality of SLD has been split into two specifications:
• OGC Symbology Encoding Implementation Specification, Version 1.1.0
• OGC Styled Layer Descriptor profile of the Web Map Service Implementation Specification, Version
1.1.0
GeoServer implements the SLD 1.0.0 standard, as well as some parts of the SE 1.1.0 and WMS-SLD 1.1.0
standards.
Elements of SLD
The following sections describe the SLD elements implemented in GeoServer.
The root element for an SLD is . It contains a Layers and Styles elements
which describe how a map is to be composed and styled.
StyledLayerDescriptor
The root element for an SLD is . It contains a sequence of Layers defining the
styled map content.
The element contains the following elements:
Tag
Required?
0..N
0..N
Description
A reference to a named layer in the server catalog
A layer defined in the style itself
Layers
An SLD document contains a sequence of layer definitions indicating the layers to be styled. Each layer
definition is either a NamedLayer reference or a supplied UserLayer.
NamedLayer
A NamedLayer specifies an existing layer to be styled, and the styling to apply to it. The styling may be
any combination of catalog styles and explicitly-defined styles. If no style is specified, the default style for
the layer is used.
The element contains the following elements:
Tag
6.2. SLD Styling
Required?
Yes
No
0..N
0..N
Description
The name of the layer to be styled. (Ignored in catalog styles.)
The description for the layer.
The name of a catalog style to apply to the layer.
The definition of a style to apply to the layer. See Styles
335
GeoServer User Manual, Release 2.15.1
UserLayer
A UserLayer defines a new layer to be styled, and the styling to apply to it. The data for the layer is provided
directly in the layer definition using the element. Since the layer is not known to the
server, the styling must be explicitly specified as well.
The element contains the following elements:
Tag
Required?
No
No
No
1..N
Description
The name for the layer being defined
The description for the layer
One or more feature collections providing the layer data,
specified using GML.
The definition of the style(s) to use for the layer. See Styles
A common use is to define a geometry to be rendered to indicate an Area Of Interest.
InlineFeature
An InlineFeature element contains data defining a layer to be styled. The element contains one or more
elements defining the data. Each Feature Collection can contain any number of
elements, each containing a feature specified using GML markup. The features can
contain any type of geometry (point, line or polygon, and collections of these). They may also contain
scalar-valued attributes, which can be useful for labelling.
Example
The following style specifies a named layer using the default style, and a user-defined layer with inline data
and styling. It displays the US States layer, with a labelled red box surrounding the Pacific NW.
usa:statesInline
-127.0,51.0 -110.0,51.0 -110.0,41.0 -127.0,41.0 -127.0,51.0
336
Chapter 6. Styling
GeoServer User Manual, Release 2.15.1
Pacific NW #FF00002title#FF0000
Styles
The style elements specify the styling to be applied to a layer.
UserStyle
The UserStyle element defines styling for a layer.
The element contains the following elements:
Tag
Required?
No
No
No
No
1..N
Description
The name of the style, used to reference it externally. (Ignored
for catalog styles.)
The title of the style.
The description for the style.
Whether the style is the default one for a named layer. Used
in SLD Library Mode. Values are 1 or 0 (default).
Defines the symbology for rendering a single feature type.
FeatureTypeStyle
The FeatureTypeStyle element specifies the styling that is applied to a single feature type of a layer. It
contains a list of rules which determine the symbology to be applied to each feature of a layer.
6.2. SLD Styling
337
GeoServer User Manual, Release 2.15.1
The element contains the following elements:
Tag
Required?
No
No
No
No
1..N
Description
Not used at present
The title for the style.
The description for the style.
Identifies the feature type the style is to be applied to. Omitted if the style applies to all features in a layer.
A styling rule to be evaluated. See Rules
Usually a layer contains only a single feature type, so the is omitted.
Any number of elements can be specified in a style. In GeoServer each one is
rendered into a separate image buffer. After all features are rendered the buffers are composited to form
the final layer image. The compositing is done in the order the FeatureTypeStyles are given in the SLD,
with the first one on the bottom (the “Painter’s Model”). This effectively creates “virtual layers”, which can
be used to achieve styling effects such as cased lines.
Styles contain Rules and Filters to determine sets of features to be styled with specific symbology. Rules
may also specify the scale range in which the feature styling is visible.
Rules
Styling rules define the portrayal of features. A rule combines a filter with any number of symbolizers.
Features for which the filter condition evaluates as true are rendered using the the symbolizers in the rule.
Syntax
The element contains the following elements:
Tag
Required?
No
No
No
No
No
No
338
0..N
0..N
0..N
0..N
0..N
Description
Specifies a name for the rule.
Specifies a title for the rule. The title is used in display lists
and legends.
Specifies an abstract describing the rule.
Specifies a filter controlling when the rule is applied. See Filters
Specifies the minimum scale denominator (inclusive) for the
scale range in which this rule applies. If present, the rule applies at the given scale and all smaller scales.
Specifies the maximum scale denominator (exclusive) for the
scale range in which this rule applies. If present, the rule applies at scales larger than the given scale.
Specifies styling as points. See PointSymbolizer
Specifies styling as lines. See LineSymbolizer
Specifies styling as polygons. See PolygonSymbolizer
Specifies styling for text labels. See TextSymbolizer
Specifies styling for raster data. See RasterSymbolizer
Chapter 6. Styling
GeoServer User Manual, Release 2.15.1
Scale Selection
Rules support scale selection to allow specifying the scale range in which a rule may be applied (assuming
the filter condition is satisfied as well, if present). Scale selection allows for varying portrayal of features at
different map scales. In particular, at smaller scales it is common to use simpler styling for features, or even
prevent the display of some features altogether.
Scale ranges are specified by using scale denominators. These values correspond directly to the ground
distance covered by a map, but are inversely related to the common “large” and “small” terminology for
map scale. In other words:
• large scale maps cover less area and have a smaller scale denominator
• small scale maps cover more area and have a larger scale denominator
Two optional elements specify the scale range for a rule:
Tag
Required?
No
No
Description
Specifies the minimum scale denominator (inclusive)
for the scale range in which this rule applies. If present,
the rule applies at the given scale and all smaller scales.
Specifies the maximum scale denominator (exclusive)
for the scale range in which this rule applies. If present,
the rule applies at scales larger than the given scale.
Note: The current scale can also be obtained via the wms_scale_denominator SLD environment variable.
This allows including scale dependency in Filter Expressions.
The following example shows the use of scale selection in a pair of rules. The rules specify that:
• at scales above 1:20,000 (larger scales, with scale denominators smaller than 20,000) features are symbolized with 10-pixel red squares,
• at scales at or below 1:20,000 (smaller scales, with scale denominators larger than 20,000) features are
symbolized with 4-pixel blue triangles.
20000square#FF00001020000triangle#0000FF
6.2. SLD Styling
339
GeoServer User Manual, Release 2.15.1
4
Evaluation Order
Within an SLD document each can contain many rules. Multiple-rule SLDs are
the basis for thematic styling. In GeoServer each is evaluated once for each feature
processed. The rules within it are evaluated in the order they occur. A rule is applied when its filter
condition (if any) is true for a feature and the rule is enabled at the current map scale. The rule is applied by
rendering the feature using each symbolizer within the rule, in the order in which they occur. The rendering
is performed into the image buffer for the parent . Thus symbolizers earlier in a
FeatureTypeStyle and Rule are rendered before symbolizers occuring later in the document (this is the
“Painter’s Model” method of rendering).
Examples
The following rule applies only to features which have a POPULATION attribute greater than 100,000, and
symbolizes the features as red points.
POPULATION100000#FF0000
An additional rule can be added which applies to features whose POPULATION attribute is less than 100,000,
and symbolizes them as green points.
POPULATION100000#0000FF
340
Chapter 6. Styling
GeoServer User Manual, Release 2.15.1
Filters
A filter is the mechanism in SLD for specifying conditions. They are similar in functionality to the SQL
“WHERE” clause. Filters are used within Rules to determine which styles should be applied to which
features in a data set. The filter language used by SLD follows the OGC Filter Encoding standard. It is
described in detail in the Filter Encoding Reference.
A filter condition is specified by using a comparison operator or a spatial operator, or two or more of these
combined by logical operators. The operators are usually used to compare properties of the features being
filtered to other properties or to literal data.
Comparison operators
Comparison operators are used to specify conditions on the non-spatial attributes of a feature. The following binary comparison operators are available:
•
•
•
•
•
•
These operators contain two filter expressions to be compared.
The first operand is often a
, but both operands may be any expression, function or literal value.
Binary comparison operators may include a matchCase attribute with the value true or false. If this
attribute is true (which is the default), string comparisons are case-sensitive. If the attribute is specified
and has the value false strings comparisons do not check case.
Other available value comparison operators are:
•
•
• matches a string property value against a text pattern.
It contains a
element containing the name of the property containing the string to be matched and
a element containing the pattern. The pattern is specified by a sequence of regular characters
and three special pattern characters. The pattern characters are defined by the following required attributes
of the element:
• wildCard specifies a pattern character which matches any sequence of zero or more characters
• singleChar specifies a pattern character which matches any single character
• escapeChar specifies an escape character which can be used to escape these pattern characters
6.2. SLD Styling
341
GeoServer User Manual, Release 2.15.1
tests whether a property value is null. It contains a single element
containing the name of the property containing the value to be tested.
tests whether an expression value lies within a range. It contains a filter expression
providing the value to test, followed by the elements and , each
containing a filter expression.
Examples
• The following filter selects features whose NAME attribute has the value of “New York”:
NAMENew York
• The following filter selects features whose geometry area is greater than 1,000,000:
GEOMETRY1000000
Spatial operators
Spatial operators are used to specify conditions on the geometric attributes of a feature. The following
spatial operators are available:
Topological Operators
These operators test topological spatial relationships using the standard OGC Simple Features predicates:
•
•
•
•
•
•
•
•
•
The content for these operators is a element for a geometry-valued property and a GML
geometry literal.
Distance Operators
These operators compute distance relationships between geometries:
•
342
Chapter 6. Styling
GeoServer User Manual, Release 2.15.1
•
The content for these elements is a element for a geometry-valued property, a GML
geometry literal, and a element containing the value for the distance tolerance. The
element may include an optional units attribute.
Bounding Box Operator
This operator tests whether a feature geometry attribute intersects a given bounding box:
•
The content is an optional element, and a GML envelope literal. If the PropertyName
is omitted the default geometry attribute is assumed.
Examples
• The following filter selects features with a geometry that intersects the point (1,1):
GEOMETRY1 1
• The following filter selects features with a geometry that intersects the box [-10,0 : 10,10]:
GEOMETRY-1001010
Logical operators
Logical operators are used to create logical combinations of other filter operators. They may be nested to
any depth. The following logical operators are available:
•
•
•
The content for and is two filter operator elements. The content for is a single filter
operator element.
6.2. SLD Styling
343
GeoServer User Manual, Release 2.15.1
Examples
• The following filter uses to combine a comparison operator and a spatial operator:
NAMENew YorkGEOMETRY1 1
Filter Expressions
Filter expressions allow performing computation on data values. The following elements can be used to
form expressions.
Arithmetic Operators
These operators perform arithmetic on numeric values. Each contains two expressions as sub-elements.
•
•
•
•
Functions
The element specifies a filter function to be evaluated. The name attribute gives the function
name. The element contains a sequence of zero or more filter expressions providing the function arguments.
See the Filter Function Reference for details of the functions provided by GeoServer.
Feature Property Values
The element allows referring to the value of a given feature attribute. It contains a string
specifying the attribute name.
Literals
The element allows specifying constant values of numeric, boolean, string, date or geometry
type.
Rules contain Symbolizers to specify how features are styled. There are 5 types of symbolizers:
• PointSymbolizer, which styles features as points
• LineSymbolizer, which styles features as lines
• PolygonSymbolizer, which styles features as polygons
• TextSymbolizer, which styles text labels for features
344
Chapter 6. Styling
GeoServer User Manual, Release 2.15.1
• RasterSymbolizer, which styles raster coverages
Each symbolizer type has its own parameters to control styling.
PointSymbolizer
A PointSymbolizer styles features as points. Points are depicted as graphic symbols at a single location on
the map.
Syntax
A contains an optional element, and a required element
specifying the point symbology.
Tag
Required?
No
Yes
Description
Specifies the geometry to be rendered.
Specifies the styling for the point symbol.
Geometry
The element is optional. If present, it specifies the featuretype property from which to obtain
the geometry to style using a element. See also Geometry transformations in SLD for
GeoServer extensions for specifying geometry.
Any kind of geometry may be styled with a . For non-point geometries, a representative point is used (such as the centroid of a line or polygon).
Graphic
Symbology is specified using a element.
The symbol is specified by either an
or a element. External Graphics are image files (in a format such as PNG
or SVG) that contain the shape and color information defining how to render a symbol. Marks are vector
shapes whose stroke and fill are defined explicitly in the symbolizer.
There are five possible sub-elements of the element. One of or