How to use the pyowm.utils.geo.Point function in pyowm

To help you get started, we’ve selected a few pyowm 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 csparpa / pyowm / tests / unit / alertapi30 / test_alert_manager.py View on Github external
def test_create_trigger_fails_with_wrong_inputs(self):
        instance = self.factory(MockHttpClient)
        with self.assertRaises(AssertionError):
            instance.create_trigger(None, 1527809375, [self._cond1, self._cond2], [geo.Point(13.6, 46.9)], alert_channels=None)
        with self.assertRaises(AssertionError):
            instance.create_trigger(1526809375, None, [self._cond1, self._cond2], [geo.Point(13.6, 46.9)], alert_channels=None)
        with self.assertRaises(ValueError):
            instance.create_trigger(1526809375, 1327809375, [self._cond1, self._cond2], [geo.Point(13.6, 46.9)], alert_channels=None)
        with self.assertRaises(AssertionError):
            instance.create_trigger(1526809375, 1527809375, None, [geo.Point(13.6, 46.9)], alert_channels=None)
        with self.assertRaises(ValueError):
            instance.create_trigger(1526809375, 1527809375, [], [geo.Point(13.6, 46.9)], alert_channels=None)
        with self.assertRaises(AssertionError):
            instance.create_trigger(1526809375, 1527809375, [self._cond1, self._cond2], None, alert_channels=None)
        with self.assertRaises(ValueError):
            instance.create_trigger(1526809375, 1527809375, [self._cond1, self._cond2], [], alert_channels=None)
github csparpa / pyowm / tests / unit / utils / test_geo.py View on Github external
def test_point_from_dict(self):
        the_dict = {
            "coordinates": [34, -56.3],
            "type": "Point"
        }
        expected = geo.Point(34, -56.3)
        result = geo.Point.from_dict(the_dict)
        self.assertIsInstance(result, geo.Point)
        self.assertEqual(expected.lat, result.lat)
        self.assertEqual(expected.lon, result.lon)
github csparpa / pyowm / tests / unit / utils / test_alerting.py View on Github external
def test_trigger_fails_with_wrong_parameters(self):
        start = 1526809375
        end = 1527809375
        conditions = [alerting.Condition('humidity', 'LESS_THAN', 10)]
        area = [geo.Point(13.6, 46.9)]

        self.assertRaises(AssertionError, alerting.Trigger,
                          None, end, conditions, area, alerts=None, alert_channels=None, id=None)
        self.assertRaises(AssertionError, alerting.Trigger,
                          start, None, conditions, area, alerts=None, alert_channels=None, id=None)
        self.assertRaises(ValueError, alerting.Trigger,
                          end, start, conditions, area, alerts=None, alert_channels=None, id=None)

        self.assertRaises(AssertionError, alerting.Trigger,
                          start, end, None, area, alerts=None, alert_channels=None, id=None)
        self.assertRaises(ValueError, alerting.Trigger,
                          start, end, [], area, alerts=None, alert_channels=None, id=None)

        self.assertRaises(AssertionError, alerting.Trigger,
                          start, end, conditions, None, alerts=None, alert_channels=None, id=None)
        self.assertRaises(ValueError, alerting.Trigger,
github csparpa / pyowm / tests / unit / alertapi30 / test_trigger.py View on Github external
)
        alert3 = Alert('alert3', 'trigger1', [{
                "current_value": 119.332,
                "condition": cond2
            }],
            {"lon": 37, "lat": 53}, 9000
        )
        alert4 = Alert('alert4', 'trigger1', [{
                "current_value": 7.332,
                "condition": cond1
            }],
            {"lon": 37, "lat": 53}, 12000
        )
        alerts = [alert1, alert2, alert3, alert4]
        instance = Trigger(1526809375, 1527809375, [cond1, cond2],
                           [geo.Point(13.6, 46.9)], alerts=alerts, alert_channels=None)
        result = instance.get_alerts_on('temp')
        self.assertEqual(2, len(result))
        self.assertTrue(alert2 in result)
        self.assertTrue(alert3 in result)

        result = instance.get_alerts_on('humidity')
        self.assertEqual(2, len(result))
        self.assertTrue(alert1 in result)
        self.assertTrue(alert4 in result)

        result = instance.get_alerts_on('wind_direction')
        self.assertEqual(0, len(result))
github csparpa / pyowm / tests / unit / utils / test_geo.py View on Github external
def test_multipoint_from_points(self):
        expected = geo.MultiPoint([(34, -56.3), (35, 8), (36, 12)])
        list_of_points = [
            geo.Point(34, -56.3),
            geo.Point(35, 8),
            geo.Point(36, 12)]
        result = geo.MultiPoint.from_points(list_of_points)
        self.assertIsInstance(result, geo.MultiPoint)
        self.assertEqual(expected.as_dict(), result.as_dict())
github csparpa / pyowm / tests / unit / alertapi30 / test_trigger.py View on Github external
def test_get_alert(self):
        cond = Condition('humidity', 'LESS_THAN', 10)
        alert = Alert('alert1', 'trigger1', [{
                "current_value": 263.576,
                "condition": cond
            }],
            {"lon": 37, "lat": 53}, 1481802090232
        )
        alerts = [alert]
        instance = Trigger(1526809375, 1527809375, [cond],
                           [geo.Point(13.6, 46.9)], alerts=alerts, alert_channels=None)
        self.assertEqual(alert, instance.get_alert('alert1'))
github csparpa / pyowm / tests / unit / utils / test_geo.py View on Github external
def test_multipoint_from_points(self):
        expected = geo.MultiPoint([(34, -56.3), (35, 8), (36, 12)])
        list_of_points = [
            geo.Point(34, -56.3),
            geo.Point(35, 8),
            geo.Point(36, 12)]
        result = geo.MultiPoint.from_points(list_of_points)
        self.assertIsInstance(result, geo.MultiPoint)
        self.assertEqual(expected.as_dict(), result.as_dict())
github csparpa / pyowm / pyowm / utils / geo.py View on Github external
def build(cls, the_dict):
        """
        Builds a `pyowm.utils.geo.Geometry` subtype based on the geoJSON geometry type specified on the input dictionary
        :param the_dict: a geoJSON compliant dict
        :return: a `pyowm.utils.geo.Geometry` subtype instance
        :raises `ValueError` if unable to the geometry type cannot be recognized
        """
        geom_type = the_dict.get('type', None)
        if geom_type == 'Point':
            return Point.from_dict(the_dict)
        elif geom_type == 'MultiPoint':
            return MultiPoint.from_dict(the_dict)
        elif geom_type == 'Polygon':
            return Polygon.from_dict(the_dict)
        elif geom_type == 'MultiPolygon':
            return MultiPolygon.from_dict(the_dict)
        else:
            raise ValueError('Unable to build a GeoType object: unrecognized geometry type')
github csparpa / pyowm / pyowm / agroapi10 / polygon.py View on Github external
def __init__(self, id, name=None, geopolygon=None, center=None, area=None, user_id=None):

        assert id is not None, 'Polygon ID cannot be None'
        if geopolygon is not None:
            assert isinstance(geopolygon, GeoPolygon), 'Polygon must be a valid geopolygon type'
        if center is not None:
            assert isinstance(center, GeoPoint), 'Polygon center must be a valid geopoint type'
        if area is not None:
            assert isinstance(area, float) or isinstance(area, int), 'Area must be a numeric type'
            assert area >= 0, 'Area must not be negative'
        self.id = id
        self.name = name
        self.geopolygon = geopolygon
        self.center = center
        self.area = area
        self.user_id = user_id