Spatial Component


Software overview

In order to display and interact with spatial data efficiently, several specialized software solutions are required. Firstly, the data needs to be stored in a spatial database. A traditional relational database is ill equipped to handle multidimensional data such as 2D points. A spatial database uses specific data structures and algorithms to index and efficiently query spatial data. See the literature review for more detail. The Protected Areas Database uses PostGIS, a spatial extension to the open source ORDBMS PostgreSQL.

The JavaScript library OpenLayers was used to view the spatial data in the client (specifically in a web browser) as layers on a map.

Finally, GeoServer provides the link between client and database. It connects to the database and serves map data as PNG images or XML vector features using the WMS and WFS protocols defined by the Open Geospatial Consortium, which OpenLayers requests.


A summary of how these software components fit together and interact with each other in the overall system architecture is shown below:


Architecture diagram


Importing data

To allow the users to query any spatial data available, the system allows arbitrary shapefiles to be imported, provided that they are in the EPSG:4326 coordinate reference system. The user can upload a shapefile to the server over the web as a ZIP archive, or they can copy the files to the server directly if they are too large. The interface to add a new layer (a table in the database with a spatial column which is seen on the client as a map layer) to the system is shown below:


Interface for importing a shapefile


Once the user clicks the Import button, the system:

  • Adds the data in the shapefile to the database as a new table using the shp2pgsql tool,
  • Reprojects the geometry into an extra column to allow distance calculations to be performed, and
  • Sends an XML definition of a new layer to GeoServer's REST API to publish the new database table. In particular filtered layers are implemented by defining an SQL view on GeoServer.

Spatial query interface

The main interface page of the system allows the user to construct queries and view results on a map. Here is a quick tour of the features provided by means of example screenshots. For more details see the report.


The user constructs a condition by specifying a left-hand side, an operator, and a right-hand side in an expression. In the example below these are rivers, within, and 'the feature selected from the map' respectively. The user can control the visibility and rendering order of layers on the map using the layer switcher, which in this case has the 'biomes' layer showing but is hiding the full layer of rivers. Clicking on the map highlights features in visible layers near the mouse click as 'pre-selected features' (orange in this example) and shows their attributes in tables below the map. Clicking on a 'Select' button in the tables selects a feature as a right-hand-side for a condition. The results of the example query can be seen on the map: the rivers (dark blue lines) within the region from the biomes layer highlighted in light blue.


Condition for rivers within a selected region

Map output for rivers within a selected region


Instead of using a value in the database, the user can draw geometry on the map as a right-hand side, as below:


Condition for rivers within a drawn region

Map output for rivers within a drawn region


Another important operator allows the user to specify the minimum distance between the left and right-hand side. A common right-hand side for this operator is a single point. Points can be selected from the database or placed manually on the map, just like lines and polygons, or exact coordinates can be specified.


Condition for rivers within a distance from a point

Map output for rivers within a distance from a point


The remaining two operators are 'contain', which is simply the inverse of 'within', and 'intersects', which means the features overlap. The final possibility for the right-hand side is a field in the database.


Combining two spatial conditions

Map output for combining two spatial conditions