How to use the timezonefinder.global_settings.TIMEZONE_NAMES_FILE function in timezonefinder

To help you get started, we’ve selected a few timezonefinder examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github MrMinimal64 / timezonefinder / timezonefinder / timezonefinder.py View on Github external
from .global_settings import (
    DTYPE_FORMAT_B_NUMPY, DTYPE_FORMAT_F_NUMPY, DTYPE_FORMAT_H, DTYPE_FORMAT_H_NUMPY, DTYPE_FORMAT_I,
    DTYPE_FORMAT_SIGNED_I_NUMPY, MAX_HAVERSINE_DISTANCE, NR_BYTES_H, NR_BYTES_I, NR_LAT_SHORTCUTS, NR_SHORTCUTS_PER_LAT,
    NR_SHORTCUTS_PER_LNG, TIMEZONE_NAMES_FILE,
)

try:
    import numba
    from .helpers_numba import coord2int, distance_to_polygon_exact, distance_to_polygon, inside_polygon, \
        all_the_same, rectify_coordinates, coord2shortcut, convert2coord_pairs, convert2coords
except ImportError:
    numba = None
    from .helpers import coord2int, distance_to_polygon_exact, distance_to_polygon, inside_polygon, \
        all_the_same, rectify_coordinates, coord2shortcut, convert2coord_pairs, convert2coords

with open(abspath(join(__file__, pardir, TIMEZONE_NAMES_FILE)), 'r') as f:
    timezone_names = json.loads(f.read())


def fromfile_memory(file, **kwargs):
    # res = np.frombuffer(file.getbuffer(), offset=file.tell(), **kwargs)
    # faster:
    res = np.frombuffer(file.getbuffer(), offset=file.tell(), **kwargs)
    file.seek(dtype(kwargs['dtype']).itemsize * kwargs['count'], SEEK_CUR)
    return res


class TimezoneFinder:
    """
    This class lets you quickly find the timezone of a point on earth.
    It keeps the binary files open in reading mode to enable fast consequent access.
    currently per half degree of latitude and per degree of longitude a set of candidate polygons are stored
github MrMinimal64 / timezonefinder / timezonefinder / file_converter.py View on Github external
def update_zone_names(path=TIMEZONE_NAMES_FILE):
    global poly_zone_ids
    global list_of_pointers
    global all_boundaries
    global all_coords
    global all_lengths
    global polynrs_of_holes
    print('updating the zone names in {} now...'.format(path))
    # pickle the zone names (python array)
    with open(abspath(path), 'w') as f:
        f.write(json.dumps(all_tz_names))
    print('...Done.\n\nComputing where zones start and end...')
    i = 0
    last_id = -1
    for zone_id in poly_zone_ids:
        if zone_id != last_id:
            poly_nr2zone_id.append(i)
github MrMinimal64 / timezonefinder / timezonefinder / file_converter.py View on Github external
polygon_space = nr_of_floats * NR_BYTES_I
    total_space = polygon_space + hole_space + shortcut_space

    print('the polygon data makes up', percent(polygon_space, total_space), '% of the data')
    print('the shortcuts make up', percent(shortcut_space, total_space), '% of the data')
    print('holes make up', percent(hole_space, total_space), '% of the data')
    print('Success!')
    return


if __name__ == '__main__':
    # parsing the data from the .json into RAM
    parse_polygons_from_json(path=INPUT_JSON_FILE_NAME)
    # update all the zone names and set the right ids to be written in the poly_zone_ids.bin
    # sort data according to zone_id
    update_zone_names(path=TIMEZONE_NAMES_FILE)

    # IMPORTANT: import the newly compiled timezone_names pickle!
    # the compilation process needs the new version of the timezone names
    with open(abspath(join(__file__, pardir, TIMEZONE_NAMES_FILE)), 'r') as f:
        timezone_names = json.loads(f.read())

    # compute shortcuts and write everything into the binaries
    compile_binaries()
github MrMinimal64 / timezonefinder / timezonefinder / file_converter.py View on Github external
print('the shortcuts make up', percent(shortcut_space, total_space), '% of the data')
    print('holes make up', percent(hole_space, total_space), '% of the data')
    print('Success!')
    return


if __name__ == '__main__':
    # parsing the data from the .json into RAM
    parse_polygons_from_json(path=INPUT_JSON_FILE_NAME)
    # update all the zone names and set the right ids to be written in the poly_zone_ids.bin
    # sort data according to zone_id
    update_zone_names(path=TIMEZONE_NAMES_FILE)

    # IMPORTANT: import the newly compiled timezone_names pickle!
    # the compilation process needs the new version of the timezone names
    with open(abspath(join(__file__, pardir, TIMEZONE_NAMES_FILE)), 'r') as f:
        timezone_names = json.loads(f.read())

    # compute shortcuts and write everything into the binaries
    compile_binaries()