Haversine (exp)
De Wiki1000
(Différences entre les versions)
(Page créée avec « <source lang='delphi'>function haversine(geoloc:TGeolocation; lat,long:Double):Double;</source> Retourne la distance entre l'attribut Geolocation et un jeu de coordonnée... ») |
|||
(9 révisions intermédiaires par un utilisateur sont masquées) | |||
Ligne 1 : | Ligne 1 : | ||
+ | {{Version700}} | ||
<source lang='delphi'>function haversine(geoloc:TGeolocation; lat,long:Double):Double;</source> | <source lang='delphi'>function haversine(geoloc:TGeolocation; lat,long:Double):Double;</source> | ||
− | Retourne la distance entre l'attribut Geolocation et un jeu de coordonnées. | + | Retourne la distance entre l'attribut [[Geolocation (type)|Geolocation]] et un jeu de coordonnées. |
Exemple : | Exemple : | ||
+ | |||
+ | '''Utilisation d'arguments''' | ||
<source lang="delphi"> | <source lang="delphi"> | ||
+ | //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; | ||
</source> | </source> | ||
+ | |||
+ | '''Utilisation de constantes''' | ||
+ | |||
+ | <source lang="delphi"> | ||
+ | //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; | ||
+ | </source> | ||
+ | |||
+ | '''Requête SQL générée par ces exemple:''' | ||
+ | |||
+ | <pre> | ||
+ | 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 | ||
+ | </pre> | ||
Voir aussi: | Voir aussi: | ||
Ligne 13 : | Ligne 57 : | ||
{{Footer|Expressions objets (code)}} | {{Footer|Expressions objets (code)}} | ||
[[Category:Expressions]] | [[Category:Expressions]] | ||
+ | [[Category:TGeolocation]] | ||
+ | [[Category:Version700]] |
Version actuelle en date du 13 janvier 2015 à 10:49
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: