From b32fb8b3ffb536ec781153c80d635eb5507dc03d Mon Sep 17 00:00:00 2001 From: Philipe Riskalla Leal <32545466+PhilipeRLeal@users.noreply.github.com> Date: Fri, 1 Oct 2021 18:43:55 -0300 Subject: [PATCH 1/2] Update util.py The get_points_array_from_gdf function was updated so to support its applicability to a geopandas GeoDataFrame or a geopandas.GeoSeries object directly. --- libpysal/weights/util.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/libpysal/weights/util.py b/libpysal/weights/util.py index b3f2991cb..deb777ae5 100644 --- a/libpysal/weights/util.py +++ b/libpysal/weights/util.py @@ -1082,8 +1082,9 @@ def get_points_array_from_shapefile(shapefile): Parameters ---------- - shapefile : string - name of a shape file including suffix + shapefile : string/geopandas.GeoSeries/geopandas.GeoDataFrame + If a string, it must be a full pathname of + a shape file - including suffix Returns ------- @@ -1117,8 +1118,12 @@ def get_points_array_from_shapefile(shapefile): [ 8.33265837, 14.03162401], [ 9.01226541, 13.81971908]]) """ - - f = psopen(shapefile) + if isinstance(shapefile, str): + f = psopen(shapefile) + elif isinstance(shapefile, gpd.GeoDataFrame): + f = shapefile['geometry'] + elif isinstance(shapefile, gpd.GeoSeries): + f = shapefile data = get_points_array(f) return data From acbbb82bc62ecc9c3d6c5b0ef5460d81fe99e844 Mon Sep 17 00:00:00 2001 From: Philipe Riskalla Leal <32545466+PhilipeRLeal@users.noreply.github.com> Date: Mon, 4 Oct 2021 11:03:43 -0300 Subject: [PATCH 2/2] Update libpysal/weights/util.py Co-authored-by: Martin Fleischmann --- libpysal/weights/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libpysal/weights/util.py b/libpysal/weights/util.py index deb777ae5..781e99a35 100644 --- a/libpysal/weights/util.py +++ b/libpysal/weights/util.py @@ -1121,7 +1121,7 @@ def get_points_array_from_shapefile(shapefile): if isinstance(shapefile, str): f = psopen(shapefile) elif isinstance(shapefile, gpd.GeoDataFrame): - f = shapefile['geometry'] + f = shapefile.geometry elif isinstance(shapefile, gpd.GeoSeries): f = shapefile data = get_points_array(f)