Creating external locations#

In this example, we show how to use Polaris-Studio and GeoPandas to create external locations along roads that traverse the boundary of the modelling area.

Imports#

from pathlib import Path

import geopandas as gpd

from polaris.network.consistency.network_objects.location import Location
from polaris.network.consistency.network_objects.location_links import link_types_for_ext
from polaris.network.network import Network
from polaris.utils.database.db_utils import commit_and_close
project_file = Path("/tmp/Bloomington_external_locations/Bloomington-Supply.sqlite")

net = Network.from_file(project_file, False)

Create the new model supply and open it We would normally use the national network as the source of roads entering and exiting the model area For the sake of an example, let’s use the Bloomington network itself

national_file = Path("/tmp/Bloomington_external_locations/Bloomington-Supply.sqlite")

national_net = Network.from_file(national_file, False)

Grabbing the necessary layers#

We also make sure that the layers are in the same projection

zone_layer = net.data_tables.get_geo_layer("zone")

national_links = national_net.data_tables.get_geo_layer("link").to_crs(zone_layer.crs)

We can be a little fancier and put a little buffer around all zones before we dissolve them This avoids problems with all sorts of imprecisions in the zone boundaries All Polaris models have projections in meters, so we can just go ahead and add a 10m buffer This would be a disaster if we were working in lat/lon

zone_polygon = zone_layer.buffer(10).union_all()
model_boundary = zone_polygon.boundary

Closes project#

net.close(False)

Total running time of the script: (0 minutes 14.103 seconds)

Gallery generated by Sphinx-Gallery