Haversine (exp)
De Wiki1000
Version du 6 janvier 2014 à 16:44 par Syfre (discuter | contributions)
function haversine(geoloc:TGeolocation; lat,long:Double):Double;
Retourne la distance entre l'attribut Geolocation et un jeu de coordonnées.
Exemple :
Utilisation d'arguments
//Procedure TestGeolocation; var sel:TSelector; S:string; stag:string; inst:WFAddress; dd:double; lat,long:double; begin // looks for address in 100 meters range from a point. // lat := 38.897147; long := -77.043934; sel := WFAddress.CreateSelector('haversine(geoloc,%2,%3) < %1','-haversine(geoloc,%2,%3)',true,[0.1,lat,long]); foreach inst in sel.AsCursor do begin dd := inst.Geoloc.haversine(38.897147,-77.043934); showMessage(Format('%s %0.4f',[inst.Address1,dd])); end; end;
Utilisation de constantes
//Procedure TestGeolocation; var sel:TSelector; S:string; stag:string; inst:WFAddress; dd:double; begin // looks for address in 100 meters range from a point. // sel := WFAddress.CreateSelector('haversine(geoloc,38.897147,-77.043934) < %1','',true,[0.1]); foreach inst in sel.AsCursor do begin dd := inst.Geoloc.haversine(38.897147,-77.043934); showMessage(Format('%s %0.4f',[inst.Address1,dd])); end; end;
Requête SQL générée par ces exemple:
select t0.* from dbo.WFADDRESS t0 where dbo.udf_haversine(t0.Geoloc_lat,t0.Geoloc_long,38.897147,-77.043934) < 1.000000000000000060E-001 order by t0.oid
Voir aussi: