import unittest import geopandas as gpd import numpy as np from shapely.geometry import LineString, Point from context import measprocess as mpc class TestProjections(unittest.TestCase): def setUp(self): self._street_series = gpd.GeoSeries( [ LineString([(0, 0), (10, 0), (10, 10)]), LineString([(100, 100), (200, 200)]), ] ) self._point_series = gpd.GeoSeries( [ Point(0, -10), # Should be mapped to 0, 0 Point(10, -1), # Should be mapped to 10, 0 Point(20, 20), # Should be mapped to 10, 10 ] ) def test_other_projection(self): mpc.geospatial.process.project_onto_streets( self._point_series.set_crs("EPSG:4326"), self._street_series.set_crs("EPSG:4326"), epsg="EPSG:31287", ) def test_exception_epsg(self): with self.assertRaises(ValueError): mpc.geospatial.process.project_onto_streets( self._point_series, self._street_series, epsg="EPSG:31287" ) with self.assertRaises(ValueError): mpc.geospatial.process.project_onto_streets( self._point_series.set_crs("EPSG:4326"), self._street_series.set_crs("EPSG:4326"), epsg="EPSG:4326", ) def test_basic_projection(self): projected, deviation = mpc.geospatial.process.project_onto_streets( self._point_series.set_crs("EPSG:31287"), self._street_series.set_crs("EPSG:31287"), ) distances = projected.distance( gpd.GeoSeries( (Point(x, y) for x, y in [(0, 0), (10, 0), (10, 10)]) ).set_crs("EPSG:31287") ) self.assertTrue(distances.max() < 1e-1) self.assertTrue( np.max(deviation.values - np.array([10, 1, np.sqrt(10 ** 2 + 10 ** 2)])) < 1e-1 ) if __name__ == "__main__": unittest.main()