Skip to content

Commit

Permalink
Merge branch 'develop' into renata/docs
Browse files Browse the repository at this point in the history
  • Loading branch information
r-akemii authored Sep 12, 2024
2 parents c7106b4 + 684b561 commit 0408db7
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 12 deletions.
12 changes: 6 additions & 6 deletions aequilibrae/paths/sub_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ def __init__(
Construct a sub-area matrix from a provided sub-area GeoDataFrame using route choice.
This class aims to provide a semi-automated method for constructing the sub-area matrix. The user should provide
the Graph object, demand matrix, and a GeoDataFrame whose `unary_union` represents the desired sub-area. Perform
a route choice assignment, then call the `post_process` method to obtain a sub-area matrix.
the Graph object, demand matrix, and a GeoDataFrame whose geometry union represents the desired sub-area.
Perform a route choice assignment, then call the ``post_process`` method to obtain a sub-area matrix.
:Arguments:
**graph** (:obj:`Graph`): AequilibraE graph object to use
**subarea** (:obj:`geopandas.GeoDataFrame`): A GeoPandas GeoDataFrame whose `unary_union` represents the
**subarea** (:obj:`gpd.GeoDataFrame`): A GeoPandas GeoDataFrame whose geometry union represents the
sub-area.
**demand** (:obj:`Union[pandas.DataFrame, AequilibraeMatrix]`): The demand matrix to provide to the route
choice assignment.
Expand Down Expand Up @@ -66,7 +66,7 @@ def __init__(
self.sub_area_demand = None

links = gpd.GeoDataFrame(project.network.links.data)
self.interior_links = links[links.crosses(subarea.unary_union.boundary)].sort_index()
self.interior_links = links[links.crosses(subarea.union_all().boundary)].sort_index()

nodes = gpd.GeoDataFrame(project.network.nodes.data).set_index("node_id")
self.interior_nodes = nodes.sjoin(subarea, how="inner").sort_index()
Expand Down
1 change: 1 addition & 0 deletions aequilibrae/project/network/gmns_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ def maybe_transform_srid(self, srid):

# For node table
lons, lats = transformer.transform(self.node_df.loc[:, "x_coord"], self.node_df.loc[:, "y_coord"])
self.node_df = self.node_df.astype({"x_coord": np.float64, "y_coord": np.float64})
self.node_df.loc[:, "x_coord"] = np.around(lons, decimals=10)
self.node_df.loc[:, "y_coord"] = np.around(lats, decimals=10)

Expand Down
3 changes: 2 additions & 1 deletion aequilibrae/project/network/link_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,10 @@ def get_by_name(self, link_type: str) -> LinkType:
if lt.link_type.lower() == link_type.lower():
return lt

@property
def fields(self) -> FieldEditor:
"""Returns a FieldEditor class instance to edit the Link_Types table fields and their metadata"""
return FieldEditor(self.project.project_base_path, "link_types")
return FieldEditor(self.project, "link_types")

def all_types(self) -> dict:
"""Returns a dictionary with all LinkType objects available in the model. link_type_id as key"""
Expand Down
7 changes: 4 additions & 3 deletions aequilibrae/project/network/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import shapely.wkb
import shapely.wkt
from shapely.geometry import Polygon, box
from shapely.ops import unary_union
from shapely import union_all

from aequilibrae.context import get_logger
from aequilibrae.parameters import Parameters
Expand Down Expand Up @@ -324,7 +324,8 @@ def build_graphs(self, fields: list = None, modes: list = None) -> None:

sql = f"select {','.join(all_fields)} from links"

df = pd.read_sql(sql, conn).fillna(value=np.nan)
with pd.option_context("future.no_silent_downcasting", True):
df = pd.read_sql(sql, conn).fillna(value=np.nan).infer_objects(False)
valid_fields = list(df.select_dtypes(np.number).columns) + ["modes"]
sql = "select node_id from nodes where is_centroid=1 order by node_id;"
centroids = np.array([i[0] for i in conn.execute(sql).fetchall()], np.uint32)
Expand Down Expand Up @@ -409,7 +410,7 @@ def convex_hull(self) -> Polygon:
with commit_and_close(connect_spatialite(self.project.path_to_file)) as conn:
sql = 'Select ST_asBinary("geometry") from Links where ST_Length("geometry") > 0;'
links = [shapely.wkb.loads(x[0]) for x in conn.execute(sql).fetchall()]
return unary_union(links).convex_hull
return union_all(links).convex_hull

def __count_items(self, field: str, table: str, condition: str) -> int:
with commit_and_close(connect_spatialite(self.project.path_to_file)) as conn:
Expand Down
4 changes: 2 additions & 2 deletions aequilibrae/project/zoning.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import geopandas as gpd
import shapely.wkb
from shapely.geometry import Point, Polygon, LineString, MultiLineString
from shapely.ops import unary_union
from shapely import union_all

from aequilibrae.project.basic_table import BasicTable
from aequilibrae.project.data_loader import DataLoader
Expand Down Expand Up @@ -85,7 +85,7 @@ def coverage(self) -> Polygon:
with commit_and_close(connect_spatialite(self.project.path_to_file)) as conn:
dt = conn.execute('Select ST_asBinary("geometry") from zones;').fetchall()
polygons = [shapely.wkb.loads(x[0]) for x in dt]
return unary_union(polygons)
return union_all(polygons)

def get(self, zone_id: str) -> Zone:
"""Get a zone from the model by its ``zone_id``"""
Expand Down

0 comments on commit 0408db7

Please sign in to comment.