3

I have a really simple and basic question.

First of all, I have to mention that I am pretty new to web applications and GIS. I am working on a web application using Openlayers, Postgresql/postGIS and pgrouting. I was wondering why use a database when I can insert all of my data into OpenLayers as Geometry Points, assuming I know the routing algorithms and I need only geometry points and linestrings?

What are the advantages of using a database in my case? Generally, what online GIS systems need a database?

  • 1
    if your data doesn't change, or you have a plan to bring updated data from its source back into your project, you may not need a database! – DPSSpatial Oct 10 '14 at 17:54
13

Why use a database?

  • Because it's not necessarily the case, especially with larger datasets, that you can expect to be able to push the entire thing to the client. If you're talking thousands of points, then sure, but for millions of points you probably don't want each and every one represented in RAM on your end users' client. Not everyone has a super fast connection, and not everyone is looking at a webapp via a beefy desktop PC. You have to consider users on older smartphones and the like as well.
  • A database acts as a way of sanitizing input data (via constraints and typed columns), storing that data efficiently, and providing a performant, sane, extensible way of querying subsets of that data. You could certainly SELECT * and dump it to GeoJSON or just start in GeoJSON if that's all you need, but you will eventually hit a wall. Maybe you'll get some bad data and having a schema would have caught it. Maybe the users only care about the points in bounding box X and your JSON dump has it for bounding box Y. Maybe you want to find all the points within a specific distance of a polygon and there's already an algorithm ready to go in PostGIS that you have to figure out how to replicate correctly in Javascript.
  • PGRouting has a lot of person-years behind it. It works quite well. It was developed by a large number of people who are collectively smarter than you and me. You could certainly reimplement the algorithms yourself in javascript and run it client side, but you may not do it in as efficient a manner and there's the inevitable trudge of increasingly byzantine bugs and corner cases you'll be on the hook to fix. If your area of expertise is not in routing algorithms, why write routing algorithms?

Certainly if your data is small enough to transmit across the network and simple enough to query and route against in javascript, then you are free to write your own. The quite nice Leaflet library was developed as a product of such hubris. But if you have large volumes of data or don't want to be on the hook for resource usage on your clients and the algorithmic correctness of software that you've written yourself, then use something off the shelf. We all have limited time on this earth and it's up to you how you choose to use that time: write your own or build with stuff that's already there.

  • 1
    You beat me to it. And since your answer contains everything I was going to say, I'll leave mine unposted. – John Powell Oct 10 '14 at 18:05
  • What's this about Leaflet? I am an OpenLayers person through and through, and have always thought Leaflet looks nice, but OL already does all I need (and more). But you use the term hubris which has piqued my interest. – John Powell Oct 10 '14 at 18:09
  • 2
    There are quite a few examples of hubris (one of the three virtues of the computer programmer) across the world of software. I just figured Leaflet was a good, relatable example for gis.stackexchange. See these slides for what I meant. A lot of software starts with the internal conversation "there's software that already does this but I don't like it so I'll do my own, how hard could it be?" – Jason Scheirer Oct 10 '14 at 18:13
  • Ha, ha, brilliant. OK, I am from the other camp, I have always wanted more in OpenLayers -- built in proj4js, jsts, with the ability to do custom builds and remove things, obviously. – John Powell Oct 10 '14 at 18:21
  • Defenetely a complete answer and what I was looking for. Thanks. – drizo Oct 10 '14 at 19:16
-3

What are the advantages of using a database and when are they needed?

If your web app is small enough, there is no advantage, and many disadvantages, to using a database/GIS server. What is missing from the other answer is that servers, especially GIS servers, cost $$. This is due partially to the 'off the shelf' solution being proprietary.

Databases and GIS servers are useful when more complex tasks are needed, such as editing and saving features in the browser, complex geometric analysis beyond what is possible in say turf.js, or when serving out millions or features.

If your app does not meet these conditions, you are probably better off with static data files such as geojson.

Here is an example of what is possible with static web mapping:

https://getbounds.com/blog/leaflet-and-geojson-tiles

  • 2
    While your point may be valid, this doesn't answer the questions of 'why use a database?', 'what are the advantages of using a database?' and 'what online GIS systems need a database?' – Adam Mar 9 '16 at 3:22

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.