Skip to content

Commit a354940

Browse files
committed
putting examples on distances module
1 parent 8dacf7b commit a354940

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

pymove/utils/distances.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ def haversine(
5555
float or ndarray
5656
Represents distance between points in meters
5757
58+
Example
59+
-------
60+
>>> from pymove.utils.distances import haversine
61+
>>> lat_fortaleza, lon_fortaleza = [-3.71839 ,-38.5434]
62+
>>> lat_quixada, lon_quixada = [-4.979224744401671, -39.056434302570665]
63+
>>> haversine(lat_fortaleza, lon_fortaleza, lat_quixada, lon_quixada)
64+
151298.02548428564
65+
5866
References
5967
----------
6068
Vectorized haversine function:
@@ -98,6 +106,15 @@ def euclidean_distance_in_meters(
98106
-------
99107
float or ndarray
100108
euclidean distance in meters between the two points.
109+
110+
Example
111+
-------
112+
>>> from pymove.utils.distances import euclidean_distance_in_meters
113+
>>> lat_fortaleza, lon_fortaleza = [-3.71839 ,-38.5434]
114+
>>> lat_quixada, lon_quixada = [-4.979224744401671, -39.056434302570665]
115+
>>> euclidean_distance_in_meters(lat_fortaleza, lon_fortaleza,
116+
lat_quixada, lon_quixada)
117+
151907.9670136588
101118
"""
102119
y1 = utils.conversions.lat_to_y_spherical(lat=lat1)
103120
y2 = utils.conversions.lat_to_y_spherical(lat=lat2)
@@ -136,6 +153,21 @@ def nearest_points(
136153
DataFrame
137154
dataframe with closest points
138155
156+
Example
157+
-------
158+
>>> from pymove.utils.distances import nearest_points
159+
>>> df_a
160+
lat lon datetime id
161+
0 39.984198 116.319322 2008-10-23 05:53:06 1
162+
1 39.984224 116.319402 2008-10-23 05:53:11 1
163+
>>> df_b
164+
lat lon datetime id
165+
0 39.984211 116.319389 2008-10-23 05:53:16 1
166+
1 39.984217 116.319422 2008-10-23 05:53:21 1
167+
>>> nearest_points(df_a,df_b)
168+
lat lon datetime id
169+
0 39.984211 116.319389 2008-10-23 05:53:16 1
170+
1 39.984211 116.319389 2008-10-23 05:53:16 1
139171
"""
140172
result = pd.DataFrame(columns=traj1.columns)
141173

@@ -184,6 +216,18 @@ def medp(
184216
-------
185217
float
186218
total distance
219+
220+
Example
221+
-------
222+
>>> from pymove.utils.distances import medp
223+
>>> traj_1
224+
lat lon datetime id
225+
0 39.98471 116.319865 2008-10-23 05:53:23 1
226+
>>> traj_2
227+
lat lon datetime id
228+
0 39.984674 116.31981 2008-10-23 05:53:28 1
229+
>>> medp(traj_1, traj_2)
230+
6.573431370981577e-05
187231
"""
188232
soma = 0
189233
traj2 = nearest_points(traj1, traj2, latitude, longitude)
@@ -230,6 +274,17 @@ def medt(
230274
float
231275
total distance
232276
277+
Example
278+
-------
279+
>>> from pymove.utils.distances import medt
280+
>>> traj_1
281+
lat lon datetime id
282+
0 39.98471 116.319865 2008-10-23 05:53:23 1
283+
>>> traj_2
284+
lat lon datetime id
285+
0 39.984674 116.31981 2008-10-23 05:53:28 1
286+
>>> medt(traj_1, traj_2)
287+
6.592419887747872e-05
233288
"""
234289
soma = 0
235290
proportion = 1000000000

0 commit comments

Comments
 (0)