How to use the timezonefinder.helpers.int2coord 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 / test / test_helpers.py View on Github external
def poly_conversion_fct(coords):
    array = np.array(coords)
    array *= COORD2INT_FACTOR
    assert (not np.any(array > MAX_ALLOWED_COORD_VAL))
    array = np.ndarray.astype(array, dtype=DTYPE_FORMAT_SIGNED_I_NUMPY)
    return array


class HelperTest(unittest.TestCase):
    import timezonefinder.helpers as helpers
    fct_dict = {
        "all_the_same": helpers.all_the_same,
        "coord2int": helpers.coord2int,
        "int2coord": helpers.int2coord,
        "distance_to_point_on_equator": helpers.distance_to_point_on_equator,
        "distance_to_polygon": helpers.distance_to_polygon,
        "distance_to_polygon_exact": helpers.distance_to_polygon_exact,
        "haversine": helpers.haversine,
        "inside_polygon": helpers.inside_polygon,
        "coord2shortcut": helpers.coord2shortcut,
        "rectify_coordinates": helpers.rectify_coordinates,
        'convert2coords': helpers.convert2coords,
        'convert2coord_pairs': helpers.convert2coord_pairs,
    }
    print('\ntesting helpers.py functions...')

    def test_coord2shortcut(self):

        coord2shortcut = self.fct_dict['coord2shortcut']
        if coord2shortcut is None:
github MrMinimal64 / timezonefinder / timezonefinder / file_converter.py View on Github external
# x_longs = binary_reader.x_coords_of(line)
        x_longs, y_longs = ints_of(line)

        # y_longs = binary_reader.y_coords_of(line)
        y_longs.append(y_longs[0])
        x_longs.append(x_longs[0])

        step = 1 / NR_SHORTCUTS_PER_LAT
        # print('checking the latitudes')
        for lat in latitudes_to_check(ymax, ymin):
            # print(lat)
            # print(coordinate_to_longlong(lat))
            # print(y_longs)
            # print(x_intersections(coordinate_to_longlong(lat), x_longs, y_longs))
            # raise ValueError
            intersects = sorted([int2coord(x) for x in
                                 x_intersections(coord2int(lat), x_longs, y_longs)])
            # print(intersects)

            nr_of_intersects = len(intersects)
            if nr_of_intersects % 2 != 0:
                raise ValueError('an uneven number of intersections has been accounted')

            for i in range(0, nr_of_intersects, 2):
                possible_longitudes = []
                # collect all the zones between two intersections [in,out,in,out,...]
                iplus = i + 1
                intersection_in = intersects[i]
                intersection_out = intersects[iplus]
                if intersection_in == intersection_out:
                    # the polygon has a point exactly on the border of a shortcut zone here!
                    # only select the top shortcut if it is actually inside the polygon (point a little up is inside)
github MrMinimal64 / timezonefinder / timezonefinder / file_converter.py View on Github external
possible_longitudes.append(intersection_out)

                        # only the shortcut above of the intersection should be selected!
                        for possible_x_coord in possible_longitudes:
                            shortcuts_for_line.add((x_shortcut(possible_x_coord), possible_y_shortcut))

        # print('now all the longitudes to check')
        # same procedure horizontally
        step = 1 / NR_SHORTCUTS_PER_LAT
        for lng in longitudes_to_check(xmax, xmin):
            # print(lng)
            # print(coordinate_to_longlong(lng))
            # print(x_longs)
            # print(x_intersections(coordinate_to_longlong(lng), x_longs, y_longs))
            intersects = sorted([int2coord(y) for y in
                                 y_intersections(coord2int(lng), x_longs, y_longs)])
            # print(intersects)

            nr_of_intersects = len(intersects)
            if nr_of_intersects % 2 != 0:
                raise ValueError('an uneven number of intersections has been accounted')

            possible_latitudes = []
            for i in range(0, nr_of_intersects, 2):
                # collect all the zones between two intersections [in,out,in,out,...]
                iplus = i + 1
                intersection_in = intersects[i]
                intersection_out = intersects[iplus]
                if intersection_in == intersection_out:
                    # the polygon has a point exactly on the border of a shortcut here!
                    # only select the left shortcut if it is actually inside the polygon (point a little left is inside)