Code Duplication    Length = 27-27 lines in 2 locations

src/senaite/core/api/geo.py 2 locations

@@ 274-300 (lines=27) @@
271
    return dms
272
273
274
def to_longitude_dms(degrees, precision=4, default=_marker):
275
    """Converts a geographical longitude in decimal degrees to a dict with
276
    degrees, minutes, seconds and bearing as the keys
277
278
    :param degrees: longitude in decimal degrees
279
    :type degrees: string,int,float
280
    :param precision: number of decimals for seconds
281
    :type precision: int
282
    :return: a dict with degrees, minutes, seconds and bearing as keys
283
    """
284
    if not is_floatable(degrees):
285
        if default is _marker:
286
            raise ValueError("Expected decimal degrees to be a floatable, but "
287
                             "got %r" % degrees)
288
        return default
289
290
    # check longitude is in range
291
    longitude = to_float(degrees)
292
    if abs(longitude) > 180:
293
        if default is _marker:
294
            raise ValueError("Longitude must be within -180 and 180 degrees")
295
        return default
296
297
    # calculate the DMS
298
    dms = to_dms(abs(longitude), precision=precision)
299
    dms["bearing"] = "E" if longitude >= 0 else "W"
300
    return dms
301
302
303
def to_decimal_degrees(dms, precision=7, default=_marker):
@@ 245-271 (lines=27) @@
242
    }
243
244
245
def to_latitude_dms(degrees, precision=4, default=_marker):
246
    """Converts a geographical latitude in decimal degrees to a dict with
247
    degrees, minutes, seconds and bearing as the keys
248
249
    :param degrees: latitude in decimal degrees
250
    :type degrees: string,int,float
251
    :param precision: number of decimals for seconds
252
    :type precision: int
253
    :return: a dict with degrees, minutes, seconds and bearing as keys
254
    """
255
    if not is_floatable(degrees):
256
        if default is _marker:
257
            raise ValueError("Expected decimal degrees to be a floatable, but "
258
                             "got %r" % degrees)
259
        return default
260
261
    # check latitude is in range
262
    latitude = to_float(degrees)
263
    if abs(latitude) > 90:
264
        if default is _marker:
265
            raise ValueError("Latitude must be within -90 and 90 degrees")
266
        return default
267
268
    # calculate the DMS
269
    dms = to_dms(abs(latitude), precision=precision)
270
    dms["bearing"] = "N" if latitude >= 0 else "S"
271
    return dms
272
273
274
def to_longitude_dms(degrees, precision=4, default=_marker):