You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cassandra.apache.org by philip andrew <ph...@gmail.com> on 2010/04/17 14:14:30 UTC

How to model 2D data in Cassandra?

Hi,

Lets say I wanted to store 2 dimensional data in the database, each object
has a X and Y location in a very large space.

I want to query Cassandra for all objects within a rectangle.

My understanding is that my objects can only be indexed by one key, one key
for each single object in my table. The key can be string or number or time,
which is supported by the index.

So I guess I could find all objects in the range of 500<x<510 if x is my
key. Also if I had another table with y as the key, then I could find all
objects with 800<y<810 range, then bring them into my program and search
through them to find the intersection of both conditions for those objects.

Am I miss-understanding anything?

Thanks! Philip

How to model 2D data in Cassandra?

Posted by Mason Hale <ma...@onespot.com>.
On Saturday, April 17, 2010, philip andrew <ph...@gmail.com> wrote:
> Hi,
> Lets say I wanted to store 2 dimensional data in the database, each object has a X and Y location in a very large space.
> I want to query Cassandra for all objects within a rectangle.
>

You should look into Geohash (http://en.m.wikipedia.org/wiki/Geohash)
or one of the similar alternatives. They map geographic coordinates to
lexigraphically sortable identifiers which can be used to find all
entities in a geographic region or to test whether two entities are in
the same region by comparing a single key per entity. No geometry
calulations required. ;-)

This page provides a good description of the technique:
http://code.google.com/apis/maps/articles/geospatial.html

Mason



-- 

Mason Hale
http://www.onespot.com
direct +1 800.618.0768 ext 701