I’ve been working with a mix of technologies lately that includes Node and GeoServer. I’ve recently begun integrating the two by using Node to manipulate GeoServer’s configuration through the REST API it provides for that purpose. One task I’ve been working on automating is the registration of vector layers stored in PostGIS with GeoServer to make them available via WMS, WFS, and the various other services provided by GeoServer.
One could legitimately ask why such a thing would need to be automated. GeoServer provides a perfectly serviceable administration interface (shown above) and such functions are not traditionally the domain of external applications. I’ve been doing a lot of technical work lately in support of open data requirements for some government users. While, in a perfect world, all data would just be open, reality is a bit more complicated. Data typically needs to be taken through a process to ensure that it does not contain sensitive information, such as personal identification or financial information and the like. A good example of these kinds of requirements is available in the text of Maryland’s Open Data Act (PDF), for example.
These requirements imply configuration management and publication workflows, and this is where external applications come into play. Many governments also have requirements that spatial data be exposed as OGC-compliant services and this is where GeoServer is unsurpassed.
So let’s get started. What I need my application to do is to expose an existing PostGIS table to GeoServer, which means adding a new feature type. For purposes of this discussion, we will assume that a workspace and a data store have already been created.
The following code snippet shows how I used the GeoServer REST API to accomplish this with Node. The API is well-documented so I see that a 201 response code indicates success. For this example, I don’t do much with a failure, but my callback function gives me the ability to do so if I choose. The API supports XML or JSON, but I am using JSON since it is native to JavaScript. (Also, I detest working with XML and will avoid it at all costs.)
This example is fairly straightforward. As I move along, I’ll deal with raster data sources as well as removing layers. Although the need to integrate administrative functions for external software can seem a little counter-intuitive at time, it’s good that GeoServer exposes such function via an API, to make it easier to automate higher-level business workflows. With this type of automation, GeoServer can be a full-fledged citizen in automated business processes.