Commit ab5ec454 authored by Lukas Eller's avatar Lukas Eller

Implemented RTR extractors.

Added docstrings to project onto streets.
parent 75ca44ff
...@@ -19,6 +19,8 @@ def fetch_rtr_details(open_test_uuids: List[str]) -> List[dict]: ...@@ -19,6 +19,8 @@ def fetch_rtr_details(open_test_uuids: List[str]) -> List[dict]:
""" """
Fetch test details from RTR-Opendata for a list of open_test_uuids. Fetch test details from RTR-Opendata for a list of open_test_uuids.
These open_test_uuids can for instance be obtained via data_extractor.fetch_rtr_overview() These open_test_uuids can for instance be obtained via data_extractor.fetch_rtr_overview()
Detailed information about the API endpoint and the meaning of returned parameters is available under:
https://www.netztest.at/en/OpenDataSpecification.html.
:param open_test_uuids: List of open_test_uuids for which test details will be fetched :param open_test_uuids: List of open_test_uuids for which test details will be fetched
...@@ -55,20 +57,29 @@ def fetch_rtr_overview( ...@@ -55,20 +57,29 @@ def fetch_rtr_overview(
raw_params: List[Tuple[str, str]] = [], raw_params: List[Tuple[str, str]] = [],
) -> pd.DataFrame: ) -> pd.DataFrame:
""" """
#Todo work on documentation! --> cat_technology, also filter not nan filters, test raw parameters Queries the RTR-Netztest API according to the passed filters.
Detailed information about the API endpoint and the meaning of returned parameters is available under:
https://www.netztest.at/en/OpenDataSpecification.html.
Comprehensive results for each test can be obtained by passing the
open_test_uuids of the fetched measurements to fetch_rtr_details.
raw params are a list of parameters that will be concateneated and passed to the request :param time_min: Lower bound for time-filter. Passed Datetime objects will be interpreted as UTC.
:param time_max: Upper bound for time-filter. Passed Datetime objects will be interpreted as UTC.
An examplary raw filter would be "cat_technology=4G" :gps_boundaries: GeoSeries in EPSG:4326 of the boundaries to filter for.
Detailed information about the possible filters is available under: https://www.netztest.at/en/OpenDataSpecification.html :cat_technology: CatTechnology to filter for. Examples are 3G and 4G.
:max_results: Upper limit of measurements to fetch.
:raw_params: Passed raw parameter tuples will be appended to the request url as key, value pairs.
:return: A pandas dataframe consisting of all the fetched measurements.
""" """
url = f"{BASE_URL}/{SUBDOMAIN_OVERVIEW}" url = f"{BASE_URL}/{SUBDOMAIN_OVERVIEW}"
request_params = MultiDict() request_params = MultiDict()
""" #Build the request parameters
Build request params
"""
if gps_boundaries is not None: if gps_boundaries is not None:
if gps_boundaries.crs != "EPSG:4326": if gps_boundaries.crs != "EPSG:4326":
......
...@@ -118,14 +118,32 @@ def project_onto_streets( ...@@ -118,14 +118,32 @@ def project_onto_streets(
plot: bool = False, plot: bool = False,
) -> (gpd.GeoSeries, gpd.GeoSeries): ) -> (gpd.GeoSeries, gpd.GeoSeries):
""" """
Todo: Not completed Projects each point from the point_series onto the closest element of
street_series according to a normal projection. For that, both
series will be transformed into a 2D projection (default EPSG:31287).
:param point_series: GeoSeries of all points to project onto streets.
:param street_series: GeoSeries of linestrings representing the streets.
:param epsg: EPSG projection to use during the projection operation.
:param plot: Boolean to indiceate whether the result of the operation shall be plotted.
:return: A tuple of two GeoSeries containing the result of the operation as well as the deviation introduced.
""" """
if point_series.crs != epsg or street_series.crs != epsg: if epsg == "EPSG:4326":
raise ValueError( raise ValueError(
"GeoSeries does not match value set by epsg argument (Default EPSG:31287)" "Projection cannot be conducted using geographical coordinates such as EPSG:4326. Select 2D projection instead."
) )
if point_series.crs is None or street_series.crs is None:
raise ValueError(
"CRS needs to be set explicitly for passed Geoseries: Use .set_crs()."
)
point_original_crs, street_original_crs = point_series.crs, street_series.crs
point_series = point_series.to_crs(epsg)
street_series = street_series.to_crs(epsg)
projected = [] projected = []
for point in point_series: for point in point_series:
street_ind = street_series.distance(point).argmin() street_ind = street_series.distance(point).argmin()
...@@ -161,6 +179,11 @@ def project_onto_streets( ...@@ -161,6 +179,11 @@ def project_onto_streets(
ax2.legend() ax2.legend()
plt.show() plt.show()
#Reset Street and Point Series CRS
street_series.to_crs(street_original_crs)
point_series.to_crs(point_original_crs)
projected.to_crs(point_original_crs)
return projected, deviation_projection return projected, deviation_projection
......
...@@ -31,11 +31,12 @@ class TestProjections(unittest.TestCase): ...@@ -31,11 +31,12 @@ class TestProjections(unittest.TestCase):
def test_other_projection(self): def test_other_projection(self):
mpc.geospatial.project_onto_streets( mpc.geospatial.project_onto_streets(
self._point_series.set_crs("EPSG:3416"), self._point_series.set_crs("EPSG:4326"),
self._street_series.set_crs("EPSG:3416"), self._street_series.set_crs("EPSG:4326"),
epsg="EPSG:3416" epsg="EPSG:31287"
) )
def test_exception_epsg(self): def test_exception_epsg(self):
with self.assertRaises(ValueError): with self.assertRaises(ValueError):
mpc.geospatial.project_onto_streets( mpc.geospatial.project_onto_streets(
...@@ -44,10 +45,11 @@ class TestProjections(unittest.TestCase): ...@@ -44,10 +45,11 @@ class TestProjections(unittest.TestCase):
epsg="EPSG:31287" epsg="EPSG:31287"
) )
with self.assertRaises(ValueError):
mpc.geospatial.project_onto_streets( mpc.geospatial.project_onto_streets(
self._point_series.set_crs("EPSG:31287"), self._point_series.set_crs("EPSG:4326"),
self._street_series.set_crs("EPSG:31287"), self._street_series.set_crs("EPSG:4326"),
epsg="EPSG:3416" epsg="EPSG:4326"
) )
def test_basic_projection(self): def test_basic_projection(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment