From cf6c1f25a24ec01bf4764fc22696b62f490b035d Mon Sep 17 00:00:00 2001 From: nickwg03 Date: Fri, 28 Oct 2016 10:42:51 -0600 Subject: [PATCH] BUG: fixed fiona filter results where bbox is not None (#372) * fixed fiona filter resulsts where bbox is not None * adds test to ensure bbox used in read_file returns a filtered subset of features --- geopandas/io/file.py | 2 +- geopandas/io/tests/test_io.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/geopandas/io/file.py b/geopandas/io/file.py index d407615..1ac2f88 100644 --- a/geopandas/io/file.py +++ b/geopandas/io/file.py @@ -25,7 +25,7 @@ def read_file(filename, **kwargs): f_filt = f.filter(bbox=bbox) else: f_filt = f - gdf = GeoDataFrame.from_features(f, crs=crs) + gdf = GeoDataFrame.from_features(f_filt, crs=crs) return gdf diff --git a/geopandas/io/tests/test_io.py b/geopandas/io/tests/test_io.py index e8e87f9..c6a1cf5 100644 --- a/geopandas/io/tests/test_io.py +++ b/geopandas/io/tests/test_io.py @@ -54,3 +54,15 @@ class TestIO(unittest.TestCase): df = self.df.rename(columns=lambda x: x.lower()) validate_boro_df(self, df) self.assert_(df.crs == self.crs) + + def test_filtered_read_file(self): + full_df_shape = self.df.shape + nybb_filename, nybb_zip_path = download_nybb() + vfs = 'zip://' + nybb_filename + bbox = (1031051.7879884212, 224272.49231459625, 1047224.3104931959, 244317.30894023244) + filtered_df = read_file(nybb_zip_path, vfs=vfs, bbox=bbox) + filtered_df_shape = filtered_df.shape + assert(full_df_shape != filtered_df_shape) + assert(filtered_df_shape == (2, 5)) + +