2014-08-29 6 views
3

S'il vous plaît, pouvez-vous m'expliquer ce comportement de la fonction earth_box ... ou ce que je fais mal?Postgresql earthdistance - earth_box avec rayon

données utilisées

40.749276, -73.985643 = Empire State Building - is in my table 
40.689266, -74.044512 = Statue of Liberty - is my current position in select - 8324m far from Empire State Building 

ma table

=> select id, latitude, longitude, title from requests; 
id | latitude | longitude |   title 
----+-----------+------------+----------------------- 
    1 | 40.749276 | -73.985643 | Empire State Building 

distance de l'Empire State Building Statue de la Liberté

=> SELECT id, latitude, longitude, title, earth_distance(ll_to_earth(40.689266, -74.044512), ll_to_earth(latitude, longitude)) as distance_from_current_location FROM requests ORDER BY distance_from_current_location ASC; 
id | latitude | longitude |   title   | distance_from_current_location 
----+-----------+------------+-----------------------+-------------------------------- 
    1 | 40.749276 | -73.985643 | Empire State Building |    8324.42998846164 

Ma position actuelle est Statue de Libery qui est plus de 8000m loin de Empire State Buildng, mais select return h id 1 même lorsque le rayon est seulement 5558m! Pouvez-vous m'expliquer ce comportement ou ce qui ne va pas?

=> SELECT id,latitude,longitude,title FROM requests WHERE earth_box(ll_to_earth(40.689266, -74.044512), 5558) @> ll_to_earth(requests.latitude, requests.longitude); 
id | latitude | longitude |   title 
----+-----------+------------+----------------------- 
    1 | 40.749276 | -73.985643 | Empire State Building 

versions des extensions et postgresql

=> \dx 
            List of installed extensions 
     Name  | Version | Schema |       Description 
---------------+---------+------------+-------------------------------------------------------------- cube   | 1.0  | public  | data type for multidimensional 
cubes earthdistance | 1.0  | public  | calculate great-circle 
distances on the surface of the Earth plpgsql  | 1.0  | 
pg_catalog | PL/pgSQL procedural language 

=> select version(); 
                   version 
-------------------------------------------------------------------------------------------------------------------------------------- PostgreSQL 9.4beta2 on x86_64-apple-darwin13.3.0, compiled by Apple 
LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn), 64-bit 

Merci NOE

Répondre

5

Le problème ici est que earth_box obtient Miles Statut. 8324,42998846164 mètres près 5.172560986623845 miles de lois Unit Converter

La solution: convertir le rayon en unités Miles Statut

earth_box(ll_to_earth(40.689266, -74.044512), 5558/1.609) //doesn't return results

earth_box(ll_to_earth(40.689266, -74.044512), 9000/1.609) //does.

Questions connexes