Tree-based algorithm in Scala vs Earth Box

87 Views Asked by At

I need to find is point located in a given radius. Now I have a two choices, first is to write my own algorithm for it(or using existing library) second is use postgresql earth_box utility and I can select it directly from db, using stored procedure. What is pros/cons of both in context of web application?

1

There are 1 best solutions below

5
Paul Sasik On

I would think that using the earth_box procedure in postgres would be better for the following reasons:

  • The database already contains the data and procedures to work with it
  • The database server , given a properly indexed table, should be quite efficient at executing a spatial query on its own spatial data
  • Using the server there's no need to query for the spatial information, transfer it to wherever you're processing it, creating a tree structure and other overhead (ties into the first bullet)
  • You're using code that already exists and, presumably, has been thoroughly tested and vetted
  • You could reuse the code in other server-side SQL from a broader number of applications such as reporting

I would definitely suggest trying the earthbox approach first and going with a custom solution only if the earthbox absolutely sucks performance-wise.

Here's a more succinct meta-reasoning from a blog post you may want to check out:

[...] the earthbox function allows us to perform a simple compare to find all records in a certain radius. This is done by the function by returning the great circle distance between the points, a more thorough explanation is located at http://en.wikipedia.org/wiki/Greatcircle.

(By meta-reasoning I mean that the simplicity of the use of earthbox makes using it a no-brainer.)