How can (PostGIS) spatial operations be exposed as web services?

e.g. if we wanted a web service end point that would return a data set with the top 5 schools nearest to a location

NOTE: can I make it clear that this is NOT for presentation on a map. Rather it is for use in a server-side workflow, where next stages in the workflow will be using the list of schools for additional actions.

I could write a .NET WCF web service, and maybe somehow call the PostGIS system, but this seems a bit overkill. And I seriously can't believe we're the first place that wants to do this.

  • I don't see how that would be "overkill." You need a web service with some SQL calls inside of it -- it couldn't be simpler. For the example you gave, you can just pass the x and y in a query string and make the DB call directly. No need to even work with spatial objects. – Rob Skelly Apr 1 '16 at 16:08
  • @RobSkelly I'm more than happy to write the code, but other people in the team are not C# developers, so I was hoping for something more "off the shelf" that they can use. Plus writing a web service for every query doesn't sound very sustainable – SteveC Apr 1 '16 at 16:12
  • Oh, I see. Fair enough. – Rob Skelly Apr 1 '16 at 16:17

The response is obviously yes and there is probably a bunch of good solutions.

Picking a favorite one with Geoserver, for example:

  1. create a sql function with "location point" as parameters witch returns 5 rows (nearest schools) using order by st_distance and limit 5

  2. create a geoserver sql view and use your above pg function;

  3. Use WFS queries;


You might want to consider using GeoServer and the Web Processing Service (WPS) extension. This would allow the use of arbitrary workflows constructed from the existing processes (things like buffering, filtering etc) and new processes constructed in Java using GeoTools.

If you prefer python there is PyWPS or ZooWPS which have similar capabilities and an identical interface so switching between the different services would have no effect on your other workflows.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.