The Wayback Machine - https://waybackassets.bk21.net/20141011072842/http://gis.stackexchange.com:80/questions/116894/why-use-a-database-when-you-can-have-all-of-your-data-in-javascript-openlayers
Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question
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! –  mapBaker 13 hours ago

1 Answer 1

up vote 7 down vote accepted

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.

share|improve this answer
    
You beat me to it. And since your answer contains everything I was going to say, I'll leave mine unposted. –  John Barça 13 hours ago
    
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 Barça 13 hours ago
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 13 hours ago
    
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 Barça 13 hours ago
    
Defenetely a complete answer and what I was looking for. Thanks. –  drizo 12 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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