import unittest import geopandas as gpd from shapely.geometry import Point, LineString from context import measprocess as mpc import numpy as np 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.project_onto_streets( self._point_series.set_crs("EPSG:3416"), self._street_series.set_crs("EPSG:3416"), epsg="EPSG:3416" ) def test_exception_epsg(self): with self.assertRaises(ValueError): mpc.geospatial.project_onto_streets( self._point_series, self._street_series, epsg="EPSG:31287" ) mpc.geospatial.project_onto_streets( self._point_series.set_crs("EPSG:31287"), self._street_series.set_crs("EPSG:31287"), epsg="EPSG:3416" ) def test_basic_projection(self): projected, deviation = mpc.geospatial.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 )