This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
admin:optimization:geo:optimization [2010/07/28 19:52] els |
— (current) | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | {{page>:top_add&nofooter&noeditbtn}} | ||
| - | ====== Geographic Searches - Indexing ====== | ||
| - | |||
| - | [[admin:optimization:geo:home|Overview]] -> [[admin:optimization:geo:latlong|Latitude and Longitude]] -> [[admin:optimization:geo:radius|Radius Distance Searches]] -> [[admin:optimization:geo:indexing|Indexing]] -> **[[admin:optimization:geo:optimization|Optimization]]** | ||
| - | |||
| - | ===== Optimizing Geographic Searches ===== | ||
| - | |||
| - | Geographic searches are specified using a [[dev:sql:functions:distance|$distance function]]. As long as there is a multi-column Omnidex index containing the latitude and longitude, the $distance function will be automatically optimized. | ||
| - | |||
| - | ===== Examples ===== | ||
| - | |||
| - | The following are examples of several types of geographic searches that can be optimized using the $distance function. | ||
| - | |||
| - | ==== Example 1: Distance between two sets of coordinates ==== | ||
| - | |||
| - | <code> | ||
| - | > select $distance(40.0, -105.0, 41.0, -106.0) distance | ||
| - | >> from $omnidex; | ||
| - | |||
| - | DISTANCE | ||
| - | -------------------------------- | ||
| - | 86.798584 | ||
| - | </code> | ||
| - | |||
| - | ==== Example 2: Distance between two sets of coordinates using columns ==== | ||
| - | |||
| - | <code> | ||
| - | select zip, | ||
| - | $distance(40.0, -105.0, latitude, longitude) distance, | ||
| - | latitude, longitude, | ||
| - | from zipcodes | ||
| - | where $distance(40.0, -105.0, latitude, longitude) < 10; | ||
| - | |||
| - | ZIP DISTANCE LATITUDE LONGITUDE | ||
| - | --------- -------------------------------- --------- --------- | ||
| - | 80020 6.152414 39.9263 -105.0652 | ||
| - | 80026 5.205616 39.9976 -105.0983 | ||
| - | 80027 7.884606 39.9782 -105.1462 | ||
| - | 80028 7.123061 39.9778 -105.1314 | ||
| - | 80038 7.133593 39.9206 -105.0861 | ||
| - | 80233 7.277603 39.9004 -104.9553 | ||
| - | 80234 6.909988 39.9001 -105.0061 | ||
| - | 80241 5.813214 39.9275 -104.9443 | ||
| - | 80260 5.813214 39.9275 -104.9443 | ||
| - | 80514 6.954636 40.0853 -104.9302 | ||
| - | 80520 8.475827 40.1125 -104.9361 | ||
| - | 80530 7.628036 40.0992 -104.9367 | ||
| - | 80602 9.650129 39.9886 -104.8183 | ||
| - | 80603 9.650129 39.9886 -104.8183 | ||
| - | 80614 5.652985 39.9239 -104.9608 | ||
| - | 80640 9.788716 39.8830 -104.8958 | ||
| - | |||
| - | </code> | ||
| - | |||
| - | ==== Example 3: Distance between an origin and multiple sets of destination coordinates ==== | ||
| - | |||
| - | <code> | ||
| - | > select state, zip, latitude, longitude | ||
| - | >> from zipcodes | ||
| - | >> where $distance(latitude, longitude, | ||
| - | >> (select latitude, longitude | ||
| - | >> from zipcodes | ||
| - | >> where state = 'CO')) < 5; | ||
| - | |||
| - | ST ZIP LATITUDE LONGITUDE | ||
| - | -- --------- --------- --------- | ||
| - | CO 80001 39.8028 -105.0869 | ||
| - | CO 80002 39.7959 -105.0982 | ||
| - | CO 80003 39.8280 -105.0653 | ||
| - | CO 80004 39.8136 -105.1178 | ||
| - | CO 80005 39.8409 -105.1108 | ||
| - | CO 80006 39.8028 -105.0869 | ||
| - | CO 80007 39.8029 -105.0876 | ||
| - | CO 80010 39.7373 -104.8638 | ||
| - | CO 80011 39.7377 -104.8121 | ||
| - | ... | ||
| - | </code> | ||
| - | |||
| - | {{page>:bottom_add&nofooter&noeditbtn}} | ||