Spatial Select -- Finding the nearest points

M5 m5 at RENEFOURNIER.COM
Thu Feb 8 01:51:07 EST 2007


Just getting my feet wet with MySQL's spatial extensions. I posted  
this question on the MySQL list, but got no answer. Maybe you guys  
(and girls!) can help. It's probably the easiest GIS problem posted  
on this list for quite a while.

Here's the table:

CREATE TABLE `lsd` (
   `id` mediumint(8) unsigned NOT NULL auto_increment,
   `latitude` decimal(10,8) NOT NULL,
   `longitude` decimal(12,8) NOT NULL,
   `coordinates` point NOT NULL,
   PRIMARY KEY  (`id`),
   SPATIAL KEY `latlng` (`coordinates`(32))
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci  
AUTO_INCREMENT=100534 ;

I want to select the records with the coordinates (which are latitude/ 
longitude points) closest to a given latitude/longitude (the latitude  
and longitude is duplicated as a geometry point in the "coordinates"  
column). Easy, right? But I'm stuck here... None of the examples in  
the MySQL docs seem to do this precisely. Any ideas? (One lister  
showed me how to perform a SELECT on the latitude, longitude columns,  
but with hundreds of thousands of rows, the query takes several  
seconds. I figure with a spatial index on that coordinates POINT  
column, it could be much faster.)

...Rene



More information about the mapserver-users mailing list