English 中文(简体)
Do I need a spatial index in my database?
原标题:

I am designing an application that needs to save geometric shapes in a database. I haven t choosen the database management system yet.

In my application, all database queries will have an bounding box as input, and as output I want all shapes within that database. I know that databases with a spatial index is used for this kind of application. But in my application there will not be any queries of type "give me objects nearby x/y" or other more complex queries that are useful in a GIS application.

I am planning of having a database without a spatial index and have queries looking like:

SELECT * FROM shapes WHERE x < max_x AND x > min_x AND y < max_y AND y > min_y

And have an index on the columns x (double) and y (double). As long I can see, I don t really need a database with an spatial index, howsoever my application is close to that kind of applications.

And even if I would like to have nearby queries, then I could create a big enough bounding box around that point. Or will this lead to poor performance?

Do I really need a spatial database? And when is a spatial index needed?

EDIT: The search queries will actually be a little bit more advanced than the one I wrote above, since I deal with geometric shapes I will input an Bounding box that will return multiple shapes (with bounding box) that are inside or interfere with the box in the query. But I still think I can do this without a spatial index, after been reading all good answers.

最佳回答

Do I really need a spatial database?

It looks like what you are doing will work fine for your application.

And even if I would like to have nearby queries, then I could create a big enough bounding box around that point.

You may want to consider creating an index on a Geohash instead. This method is recommended for indexing geo-spatial points on the Google App Engine, for example, where the indexing features are limited. (Source)

And when is a spatial index needed?

There are many scenarios where a spatial index is useful. First of all, spatial indexes can deal with not just points, but with polylines, polygons, and other shapes. In addition, as you already mentioned, there are many complex query operations that can be applied on spatial data, where a proper spatial index would be essential.

问题回答

No, you don t need a spatial index for this.

Spatial indices are needed for calculating distance between objects, seeing if a point is within a certain radius of another point, etc... mostly when you need to take geographical coordinates into consideration with. Southern hemisphere, northern hemisphere, etc... it all changes the distance a bit when you have to take the curve of the earth into consideration.

If you re always looking for both x and y than you would benefit from having an index on both items at the same time. So... not an index on column x and an index on column y, but an index on column x and y combined.

To add to existing excellent answers, performance might or might be not important here.

If you simulate a spatial index range query by doing two range queries for x and y axes and taking the intersection of results, you are, well, doing two queries which might return much more data than needed before the intersection.

On the other hand, such query is natively supported by a spatial index and as such will be answered efficiently.

All in all, if your spatial queries are the bottleneck, you will need to use a spatial index.

If you do not go beyond what you are already doing, you do not need a spatial index nor a GIS for that matter. However, I would carefully consider what your requirements are and chances of the application growing to need a GIS system. It is better than plan earlier than later for this transition.

GIS gives you several advantages. First, a GIS has special shape column for storing everything needed about a geometry. It manages spatial reference, coordinate metadata, etc. A GIS provides powerful methods for querying the data based on spatial relationships and modifying the geometries (unions, extractions, buffers, etc). It handles points, lines, polygons, etc. You can derive new shapes from topological operations. Additionally, almost all GIS systems provide means for rendering the data (this really depends on what GIS you choose but when it is present it saves you TONS of work).

You will only need spatial indexes if you have a true GIS environment. If you do choose a GIS environment, yes, use spatial indexes - you just really don t want to work without them.





相关问题
what is wrong with this mysql code

$db_user="root"; $db_host="localhost"; $db_password="root"; $db_name = "fayer"; $conn = mysqli_connect($db_host,$db_user,$db_password,$db_name) or die ("couldn t connect to server"); // perform query ...

Users asking for denormalized database

I am in the early stages of developing a database-driven system and the largest part of the system revolves around an inheritance type of relationship. There is a parent entity with about 10 columns ...

Easiest way to deal with sample data in Java web apps?

I m writing a Java web app in my free time to learn more about development. I m using the Stripes framework and eventually intend to use hibernate and MySQL For the moment, whilst creating the pages ...

join across databases with nhibernate

I am trying to join two tables that reside in two different databases. Every time, I try to join I get the following error: An association from the table xxx refers to an unmapped class. If the ...

How can I know if such value exists in database? (ADO.NET)

For example, I have a table, and there is a column named Tags . I want to know if value programming exists in this column. How can I do this in ADO.NET? I did this: OleDbCommand cmd = new ...

Convert date to string upon saving a doctrine record

I m trying to migrate one of my PHP projects to Doctrine. I ve never used it before so there are a few things I don t understand. In my current code, I have a class similar to this: class ...

热门标签