Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added static method to directly retrieve a network based on a polygon #362

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,24 @@ def with_polygon(
_wrapper.polygon_graph = _clean_graph
return _wrapper

@staticmethod
def get_network_from_polygon(
config_data: NetworkConfigData, polygon: BaseGeometry
) -> tuple[MultiGraph, GeoDataFrame]:
"""
Gets a valid network (`MultiGraph` and `GeoDataFrame`) for the given configuration and
boundary box (represented by a `shapely.BaseGeometry`).

Args:
config_data (NetworkConfigData): Network data configuration required for OSM download.
polygon (BaseGeometry): Polygon representing the boundary box.

Returns:
tuple[MultiGraph, GeoDataFrame]: Resulting network representations.
"""
_network_wrapper = OsmNetworkWrapper.with_polygon(config_data, polygon)
return _network_wrapper.get_network()

def get_network(self) -> tuple[MultiGraph, GeoDataFrame]:
logging.info("Start downloading a network from OSM.")

Expand Down
21 changes: 21 additions & 0 deletions tests/network/network_wrappers/test_osm_network_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,3 +326,24 @@ def test_given_no_output_graph_dir_when_get_network(self):
assert isinstance(_wrapper.polygon_graph, MultiDiGraph)
assert isinstance(_result_mg, MultiGraph)
assert isinstance(_result_gdf, GeoDataFrame)

@slow_test
def test_get_network_from_polygon_with_valid_data(
self, _valid_network_polygon_fixture: BaseGeometry
):
# 1. Define test data.
_network_config_data = self._get_dummy_network_config_data()
_network_config_data.network.network_type = NetworkTypeEnum.DRIVE
_network_config_data.network.road_types = []

# 2. Run test.
_network_tuple = OsmNetworkWrapper.get_network_from_polygon(
_network_config_data, _valid_network_polygon_fixture
)

# 3. Verify expectations.
assert isinstance(_network_tuple, tuple)

_result_graph, _result_gdf = _network_tuple
assert isinstance(_result_graph, MultiGraph)
assert isinstance(_result_gdf, GeoDataFrame)