overpy_series_test.py 2.11 KB
Newer Older
1
import unittest
2

3
import geopandas as gpd
4 5 6 7
from shapely.geometry import LineString, Point

from context import measprocess as mpc

Lukas Eller's avatar
Lukas Eller committed
8 9

class TestOSMAPI(unittest.TestCase):
10 11 12 13 14
    def setUp(self):
        self._coords = [
            (48.201914, 16.363859),
            (48.194170, 16.385466)
        ]
Lukas Eller's avatar
Lukas Eller committed
15

16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
        self._measurement_coords_not_set = gpd.GeoSeries(
            (Point(lon, lat) for lat, lon in self._coords)
        )

        self._measurement_coords_set = gpd.GeoSeries(
            (Point(lon, lat) for lat, lon in self._coords)
        ).set_crs("EPSG:4326")

    def test_basic_API(self):
        street_series = mpc.geospatial.get_geoseries_streets(
            self._measurement_coords_set
        )

        blockage_series = mpc.geospatial.get_geoseries_blockages(
            self._measurement_coords_set
        )

        self.assertTrue(
            "EPSG:4326" == street_series.crs
        )

        self.assertTrue(
            "EPSG:4326" == blockage_series.crs
        )

    def test_raise_error_if_crs_not_set(self):

        with self.assertRaises(ValueError):
            mpc.geospatial.get_geoseries_blockages(
                self._measurement_coords_not_set
            )

            mpc.geospatial.get_geoseries_streets(
                self._measurement_coords_not_set
            )

    def test_output_coordinates_streets(self):

        street_series = mpc.geospatial.get_geoseries_streets(
            self._measurement_coords_set
        )

        street_series = street_series.to_crs("EPSG:31287")
        projected = self._measurement_coords_set.to_crs("EPSG:31287")

        self.assertTrue(
            street_series.distance(projected[0]).mean() < 1000
        )

    def test_output_coordinates_blockages(self):

        blockage_series = mpc.geospatial.get_geoseries_blockages(
            self._measurement_coords_set
        )

        blockage_series = blockage_series.to_crs("EPSG:31287")
        projected = self._measurement_coords_set.to_crs("EPSG:31287")

        self.assertTrue(
            blockage_series.distance(projected[0]).mean() < 1000
        )
77 78 79

if __name__ == '__main__':
    unittest.main()