From 42fc6109d30315efa2fd4e674341e4ab8bd97f8f Mon Sep 17 00:00:00 2001 From: Renata Imai Date: Wed, 11 Sep 2024 16:13:25 -0300 Subject: [PATCH] removes warnings --- aequilibrae/paths/sub_area.py | 8 ++++---- aequilibrae/project/network/gmns_builder.py | 1 + aequilibrae/project/network/network.py | 7 ++++--- aequilibrae/project/zoning.py | 4 ++-- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/aequilibrae/paths/sub_area.py b/aequilibrae/paths/sub_area.py index da3623459..52093a63e 100644 --- a/aequilibrae/paths/sub_area.py +++ b/aequilibrae/paths/sub_area.py @@ -23,12 +23,12 @@ 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. @@ -63,7 +63,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() diff --git a/aequilibrae/project/network/gmns_builder.py b/aequilibrae/project/network/gmns_builder.py index 398d6bc28..c9d426705 100644 --- a/aequilibrae/project/network/gmns_builder.py +++ b/aequilibrae/project/network/gmns_builder.py @@ -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) diff --git a/aequilibrae/project/network/network.py b/aequilibrae/project/network/network.py index fa229f68a..a79785d4c 100644 --- a/aequilibrae/project/network/network.py +++ b/aequilibrae/project/network/network.py @@ -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 @@ -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) @@ -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: diff --git a/aequilibrae/project/zoning.py b/aequilibrae/project/zoning.py index 0970c591c..ce98a1bfe 100644 --- a/aequilibrae/project/zoning.py +++ b/aequilibrae/project/zoning.py @@ -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 @@ -90,7 +90,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**"""