To begin, navigate to Stores ‣ Add a new store ‣ PostGIS NG.
Fill in the Basic Store Info used to identify the database when managing layers.
Basic Store Info
Description
Workspace
Name of the workspace to contain the database. This will also be the prefix of any layer names created from tables in the database.
Data Source Name
Name of the database. This can be different from the name as known to PostgreSQL/PostGIS.
Description
Description of the database/store.
Enabled
Enables the store. If disabled, no data in the database will be served.
Move on to the connection parameters used to connect and interact with the database.
The dbtype and namespace connection parameters are not directly editable. The dbtype parameter is for internal use only (and only accessible via the REST API).
Connection Parameter
Description
dbtype
Type of database. Internal value, leave this value as the default.
namespace
Namespace to be associated with the database. This field is altered by changing the workspace name.
GeoServer can also connect to a PostGIS database using JNDI (Java Naming and Directory Interface). This is used to allow a PostGIS DataStore to share a named connection pool of PostGIS connections configured in your application server.
To begin, navigate to Stores ‣ Add a new store ‣ PostGIS NG (JNDI).
Option
Description
Workspace
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 database. This can be different from the name as known to PostgreSQL/PostGIS.
Description
Description of the database/store.
Enabled
Enables the store. If disabled, no data in the database will be served.
dbtype
Type of database. Leave this value as the default.
jndiReferenceName
JNDI path to the database.
schema
Schema for the above database.
namespace
Namespace to be associated with the database. This field is altered by changing the workspace name.
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.
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 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.
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.
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.
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.
GeoServer is able to translate the jsonPointer function to a query using PostgreSQL support for JSON types.
The following are the main characteristics of the implementation:
The jsonPointer function syntax is like the following: jsonPointer(attributeName,'/path/to/json/attribute').
The function is able to select attributes inside json arrays by specifying the index of the target element in the json path eg. '/path/to/array/element/0'.
When accessing a JSON property it is implicitly assumed that the same property will have the same type on all features, otherwise a cast exception will be thrown by the database.
GeoServer will perform a cast automatically to the expect type from the evaluation; the cast is completely delegated to the database.
If the property doesn’t exists no errors will be issued, but the features that have that property will be excluded; hence the property we wish to query is not mandatory in all features.
Having a json column storing jsonvalues like the following,
{"name":"city name","description":"the city description","districts":[{"name":"district1","population":2000},{"name":"district2","population":5000}]"population":{"average_age":35,"toal":50000}}
and assuming an attribute name as city, valid jsonPointer functions would be:
jsonPointer(city,'/name').
jsonPointer(city,'/population/average_age').
jsonPointer(city,'/districts/0/name').
An example cql_filter would then be jsonPointer(city,'/population/average_age')>30.
While an example rule in a sld style sheet could be:
jsonb which store the value in a decomposed binary format.
The jsonPointer function supports both, as well as the text format if it contains a valid json representation.
Anyways, the PostgreSQL documentation recommends usage of jsonb, as it is faster to process.
PostgreSQL supports also indexing on json types. And index on a specific json attribute can be created as follow: