How to use the timezonefinder.helpers_numba.inside_polygon 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
assert abs(km2deg(distance) - sqrt(2) / 2) < 0.00001


class HelperTestNumba(HelperTest):
    # all Numba compiled functions have to receive their arguments in the proper data type (and numpy array shape)
    try:
        import timezonefinder.helpers_numba 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('\nNumba installation found.\ntesting helpers_numba.py functions...')

    except ImportError:
        fct_dict = {
            "all_the_same": None,
            "coord2int": None,
            "int2coord": None,
            "distance_to_point_on_equator": None,
            "distance_to_polygon": None,
            "distance_to_polygon_exact": None,
            "haversine": None,
github MrMinimal64 / timezonefinder / timezonefinder / timezonefinder.py View on Github external
for polygon_nr in possible_polygons:

            # get boundaries
            self.poly_max_values.seek(4 * NR_BYTES_I * polygon_nr)
            boundaries = self.fromfile(self.poly_max_values, dtype=DTYPE_FORMAT_SIGNED_I_NUMPY, count=4)
            if not (x > boundaries[0] or x < boundaries[1] or y > boundaries[2] or y < boundaries[3]):

                outside_all_holes = True
                # when the point is within a hole of the polygon this timezone doesn't need to be checked
                for hole_coordinates in self._holes_of_line(polygon_nr):
                    if inside_polygon(x, y, hole_coordinates):
                        outside_all_holes = False
                        break

                if outside_all_holes:
                    if inside_polygon(x, y, self.coords_of(line=polygon_nr)):
                        return timezone_names[self.id_of(polygon_nr)]

        # no polygon has been matched
        return None
github MrMinimal64 / timezonefinder / timezonefinder / timezonefinder.py View on Github external
if same_element != -1:
                    # return the name of that zone
                    return timezone_names[same_element]

                polygon_nr = possible_polygons[i]

                # get the boundaries of the polygon = (lng_max, lng_min, lat_max, lat_min)
                self.poly_max_values.seek(4 * NR_BYTES_I * polygon_nr)
                boundaries = self.fromfile(self.poly_max_values, dtype=DTYPE_FORMAT_SIGNED_I_NUMPY, count=4)
                # only run the expensive algorithm if the point is withing the boundaries
                if not (x > boundaries[0] or x < boundaries[1] or y > boundaries[2] or y < boundaries[3]):

                    outside_all_holes = True
                    # when the point is within a hole of the polygon, this timezone must not be returned
                    for hole_coordinates in self._holes_of_line(polygon_nr):
                        if inside_polygon(x, y, hole_coordinates):
                            outside_all_holes = False
                            break

                    if outside_all_holes:
                        if inside_polygon(x, y, self.coords_of(line=polygon_nr)):
                            # the point is included in this polygon. return its timezone name without further checks
                            return timezone_names[ids[i]]

            # the timezone name of the last polygon should always be returned
            # if no other polygon has been matched beforehand.
            raise ValueError('BUG: this statement should never be reached. Please open up an issue on Github!')
github MrMinimal64 / timezonefinder / timezonefinder / timezonefinder.py View on Github external
# x = longitude  y = latitude  both converted to 8byte int
        x = coord2int(lng)
        y = coord2int(lat)

        # check if the point is actually included in one of the polygons
        for polygon_nr in possible_polygons:

            # get boundaries
            self.poly_max_values.seek(4 * NR_BYTES_I * polygon_nr)
            boundaries = self.fromfile(self.poly_max_values, dtype=DTYPE_FORMAT_SIGNED_I_NUMPY, count=4)
            if not (x > boundaries[0] or x < boundaries[1] or y > boundaries[2] or y < boundaries[3]):

                outside_all_holes = True
                # when the point is within a hole of the polygon this timezone doesn't need to be checked
                for hole_coordinates in self._holes_of_line(polygon_nr):
                    if inside_polygon(x, y, hole_coordinates):
                        outside_all_holes = False
                        break

                if outside_all_holes:
                    if inside_polygon(x, y, self.coords_of(line=polygon_nr)):
                        return timezone_names[self.id_of(polygon_nr)]

        # no polygon has been matched
        return None
github MrMinimal64 / timezonefinder / timezonefinder / timezonefinder.py View on Github external
# get the boundaries of the polygon = (lng_max, lng_min, lat_max, lat_min)
                self.poly_max_values.seek(4 * NR_BYTES_I * polygon_nr)
                boundaries = self.fromfile(self.poly_max_values, dtype=DTYPE_FORMAT_SIGNED_I_NUMPY, count=4)
                # only run the expensive algorithm if the point is withing the boundaries
                if not (x > boundaries[0] or x < boundaries[1] or y > boundaries[2] or y < boundaries[3]):

                    outside_all_holes = True
                    # when the point is within a hole of the polygon, this timezone must not be returned
                    for hole_coordinates in self._holes_of_line(polygon_nr):
                        if inside_polygon(x, y, hole_coordinates):
                            outside_all_holes = False
                            break

                    if outside_all_holes:
                        if inside_polygon(x, y, self.coords_of(line=polygon_nr)):
                            # the point is included in this polygon. return its timezone name without further checks
                            return timezone_names[ids[i]]

            # the timezone name of the last polygon should always be returned
            # if no other polygon has been matched beforehand.
            raise ValueError('BUG: this statement should never be reached. Please open up an issue on Github!')