Click here to get back home

Quick and dirty spatial index

 HomeNewsGroups | Search | About
 comp.infosystems.gis    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Quick and dirty spatial index Chris 04-17-2007
Posted by Chris on April 17, 2007, 9:37 pm
Please log in for more thread options
I need to search a database table of locations to find all with X miles
of a certain point. Each location has a latitude and longitude.
Unfortunately, this particular database does not have the ability to
create spatial indexes.

Is there a quick and dirty way for me to create my own spatial index and
store it in the database?

It doesn't have to be most efficient method. It just has to reduce the
search space enough to speed things up. I don't think that creating a
simple index on lat+long is going to cut it, though.

Posted by user923005 on April 17, 2007, 10:52 pm
Please log in for more thread options
> I need to search a database table of locations to find all with X miles
> of a certain point. Each location has a latitude and longitude.
> Unfortunately, this particular database does not have the ability to
> create spatial indexes.
>
> Is there a quick and dirty way for me to create my own spatial index and
> store it in the database?
>
> It doesn't have to be most efficient method. It just has to reduce the
> search space enough to speed things up. I don't think that creating a
> simple index on lat+long is going to cut it, though.

PostgreSQL has spatial indexes, if you choose the PostGIS option.
What database are you using?

Alternatively, you could create an index on lat+lon, and then do your
own cookie cutter on coordinates that would fit into a box around the
data (a circle {or ellipse for eccentricty} is correct, but you will
need a larger region since the index will not be aware).

Something like this:

given: someLat, someLon
given: radius somRad

calculate the box of dimention 2* someRad that has someLat, someLon at
its center. Use great circles north, south, east, and west from
(someLat, someLon) to generate the coordinates. Then search inside of
this box with your query. You will need to individually filter the
resultant data set, but it should only be a small fraction of the data
you would have had to examine otherwise. Having a key on the lat+lon
will help some. It might also be a good idea to have a key on lat and
a key on lon for some difficult queries so that you can always do some
restrictions of the data set.



Posted by Chris on April 18, 2007, 12:31 pm
Please log in for more thread options
user923005 wrote:
>> I need to search a database table of locations to find all with X miles
>> of a certain point. Each location has a latitude and longitude.
>> Unfortunately, this particular database does not have the ability to
>> create spatial indexes.
>>
>> Is there a quick and dirty way for me to create my own spatial index and
>> store it in the database?
>>
>> It doesn't have to be most efficient method. It just has to reduce the
>> search space enough to speed things up. I don't think that creating a
>> simple index on lat+long is going to cut it, though.
>
> PostgreSQL has spatial indexes, if you choose the PostGIS option.
> What database are you using?
>
> Alternatively, you could create an index on lat+lon, and then do your
> own cookie cutter on coordinates that would fit into a box around the
> data (a circle {or ellipse for eccentricty} is correct, but you will
> need a larger region since the index will not be aware).
>
> Something like this:
>
> given: someLat, someLon
> given: radius somRad
>
> calculate the box of dimention 2* someRad that has someLat, someLon at
> its center. Use great circles north, south, east, and west from
> (someLat, someLon) to generate the coordinates. Then search inside of
> this box with your query. You will need to individually filter the
> resultant data set, but it should only be a small fraction of the data
> you would have had to examine otherwise. Having a key on the lat+lon
> will help some. It might also be a good idea to have a key on lat and
> a key on lon for some difficult queries so that you can always do some
> restrictions of the data set.
>
>

Thanks. Unfortunately, the database I'm using is specialized and
proprietary, and spatial indexes are not available. It's not possible to
switch to another database.

My sense is that the lat+long index won't work well when the dataset is
large. It reduces the search space, but not enough. For example, let's
say you're searching for all data points +- 10 miles of a given point.
The lat+long index will make you examine all points within a 20 mile
band across the whole area.

I read somewhere that you can create a combined lat/long value that
interleaves the digits of each, and that this can reduce the search
space. I can't find any references to it, though. Have you heard of such
a thing?



Posted by user923005 on April 18, 2007, 2:36 pm
Please log in for more thread options
> user923005 wrote:
> >> I need to search a database table of locations to find all with X miles
> >> of a certain point. Each location has a latitude and longitude.
> >> Unfortunately, this particular database does not have the ability to
> >> create spatial indexes.
>
> >> Is there a quick and dirty way for me to create my own spatial index and
> >> store it in the database?
>
> >> It doesn't have to be most efficient method. It just has to reduce the
> >> search space enough to speed things up. I don't think that creating a
> >> simple index on lat+long is going to cut it, though.
>
> > PostgreSQL has spatial indexes, if you choose the PostGIS option.
> > What database are you using?
>
> > Alternatively, you could create an index on lat+lon, and then do your
> > own cookie cutter on coordinates that would fit into a box around the
> > data (a circle {or ellipse for eccentricty} is correct, but you will
> > need a larger region since the index will not be aware).
>
> > Something like this:
>
> > given: someLat, someLon
> > given: radius somRad
>
> > calculate the box of dimention 2* someRad that has someLat, someLon at
> > its center. Use great circles north, south, east, and west from
> > (someLat, someLon) to generate the coordinates. Then search inside of
> > this box with your query. You will need to individually filter the
> > resultant data set, but it should only be a small fraction of the data
> > you would have had to examine otherwise. Having a key on the lat+lon
> > will help some. It might also be a good idea to have a key on lat and
> > a key on lon for some difficult queries so that you can always do some
> > restrictions of the data set.
>
> Thanks. Unfortunately, the database I'm using is specialized and
> proprietary, and spatial indexes are not available. It's not possible to
> switch to another database.
>
> My sense is that the lat+long index won't work well when the dataset is
> large. It reduces the search space, but not enough. For example, let's
> say you're searching for all data points +- 10 miles of a given point.
> The lat+long index will make you examine all points within a 20 mile
> band across the whole area.
>
> I read somewhere that you can create a combined lat/long value that
> interleaves the digits of each, and that this can reduce the search
> space. I can't find any references to it, though. Have you heard of such
> a thing?

The right kind of index is a K-D tree, a trie, a quadtree and things
of that nature. A B-Tree index is not going to cut the mustard. Even
an R-Tree index is marginal.
PostgreSQLs indexes are open source. Perhaps the GIS stuff can be
adapted to your proprietary database, if you are able to modify the
source (but that will clearly be a BIG project). If not, your queries
will crawl like a slug through molasses.
Perhaps you can add a ton of RAM to the machine so it will mostly be
cached in RAM. With 64 bit chips and operating systems you can do
some remarkable things if you throw enough money at it.


Posted by Chris on April 18, 2007, 4:48 pm
Please log in for more thread options
user923005 wrote:
>> user923005 wrote:
>>>> I need to search a database table of locations to find all with X miles
>>>> of a certain point. Each location has a latitude and longitude.
>>>> Unfortunately, this particular database does not have the ability to
>>>> create spatial indexes.
>>>> Is there a quick and dirty way for me to create my own spatial index and
>>>> store it in the database?
>>>> It doesn't have to be most efficient method. It just has to reduce the
>>>> search space enough to speed things up. I don't think that creating a
>>>> simple index on lat+long is going to cut it, though.
>>> PostgreSQL has spatial indexes, if you choose the PostGIS option.
>>> What database are you using?
>>> Alternatively, you could create an index on lat+lon, and then do your
>>> own cookie cutter on coordinates that would fit into a box around the
>>> data (a circle {or ellipse for eccentricty} is correct, but you will
>>> need a larger region since the index will not be aware).
>>> Something like this:
>>> given: someLat, someLon
>>> given: radius somRad
>>> calculate the box of dimention 2* someRad that has someLat, someLon at
>>> its center. Use great circles north, south, east, and west from
>>> (someLat, someLon) to generate the coordinates. Then search inside of
>>> this box with your query. You will need to individually filter the
>>> resultant data set, but it should only be a small fraction of the data
>>> you would have had to examine otherwise. Having a key on the lat+lon
>>> will help some. It might also be a good idea to have a key on lat and
>>> a key on lon for some difficult queries so that you can always do some
>>> restrictions of the data set.
>> Thanks. Unfortunately, the database I'm using is specialized and
>> proprietary, and spatial indexes are not available. It's not possible to
>> switch to another database.
>>
>> My sense is that the lat+long index won't work well when the dataset is
>> large. It reduces the search space, but not enough. For example, let's
>> say you're searching for all data points +- 10 miles of a given point.
>> The lat+long index will make you examine all points within a 20 mile
>> band across the whole area.
>>
>> I read somewhere that you can create a combined lat/long value that
>> interleaves the digits of each, and that this can reduce the search
>> space. I can't find any references to it, though. Have you heard of such
>> a thing?
>
> The right kind of index is a K-D tree, a trie, a quadtree and things
> of that nature. A B-Tree index is not going to cut the mustard. Even
> an R-Tree index is marginal.
> PostgreSQLs indexes are open source. Perhaps the GIS stuff can be
> adapted to your proprietary database, if you are able to modify the
> source (but that will clearly be a BIG project). If not, your queries
> will crawl like a slug through molasses.
> Perhaps you can add a ton of RAM to the machine so it will mostly be
> cached in RAM. With 64 bit chips and operating systems you can do
> some remarkable things if you throw enough money at it.
>

Just for reference, I've found these papers:

http://citeseer.ist.psu.edu/234227.html
http://www.dcs.bbk.ac.uk/TriStarp/pubs/bncod17.pdf

They both purport to provide a way to do two-dimensional indexing in
one-dimensional space. Slogging through them now...

Similar ThreadsPosted
Oracle Spatial (9i or 10g) vs Informix Spatial Datablade ? June 13, 2006, 7:52 am
NDVI index October 18, 2007, 5:49 am
Cutting A Quick bird image in Erdas imagine October 27, 2005, 8:19 am
Has anybody found a quick way to make tiles for Google Maps from within ESRI 9.0? October 17, 2006, 10:28 am
Seeking Index Map for NTS Canada mapsheets February 6, 2005, 10:05 pm
visit http://www.real-article.com/gis/index.php April 30, 2007, 10:22 am
spatial indexing April 25, 2005, 12:14 am
Non-Overlapping Spatial Indexing August 23, 2004, 11:09 am
implementing Spatial Indexing in VB April 25, 2005, 2:11 am
Spatial Conflation techniques May 25, 2005, 2:48 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap