From 7782f6a00fbfb46d660f23e0ae8228fa2e4f3451 Mon Sep 17 00:00:00 2001 From: sgillies Date: Sun, 7 Jul 2013 22:00:22 -0600 Subject: [PATCH] Add kwargs to from_file that turn on extra fiona features. Also try to import setup from setuptools to get the 'develop' feature. --- geopandas/geodataframe.py | 11 ++++++++--- setup.py | 5 ++++- tests/test_geodataframe.py | 9 +++++++++ 3 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 tests/test_geodataframe.py diff --git a/geopandas/geodataframe.py b/geopandas/geodataframe.py index b8de384..c976407 100644 --- a/geopandas/geodataframe.py +++ b/geopandas/geodataframe.py @@ -16,9 +16,13 @@ class GeoDataFrame(DataFrame): self.crs = None @classmethod - def from_file(cls, filename): + def from_file(cls, filename, **kwargs): """ - Alternate constructor to create a GeoDataFrame from a file + Alternate constructor to create a GeoDataFrame from a file. + + *filename* is either the absolute or relative path to the file to be + opened and *kwargs* are keyword args to be passed to the method when + opening the file. Note: This method does not attempt to align rows. Properties that are not present in all features of the source @@ -26,7 +30,8 @@ class GeoDataFrame(DataFrame): """ geoms = [] columns = defaultdict(lambda: []) - with fiona.open(filename) as f: + + with fiona.open(filename, **kwargs) as f: crs = f.crs for rec in f: geoms.append(shape(rec['geometry'])) diff --git a/setup.py b/setup.py index 438b3ba..a009910 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,7 @@ -from distutils.core import setup +try: + from setuptools import setup +except ImportError: + from distutils.core import setup setup(name='geopandas', version='0.1dev', diff --git a/tests/test_geodataframe.py b/tests/test_geodataframe.py new file mode 100644 index 0000000..5288f39 --- /dev/null +++ b/tests/test_geodataframe.py @@ -0,0 +1,9 @@ +from geopandas import GeoDataFrame + +def test_from_file_(): + # Data from http://www.nyc.gov/html/dcp/download/bytes/nybb_13a.zip + # saved as geopandas/examples/nybb_13a.zip. + df = GeoDataFrame.from_file( + '/nybb_13a/nybb.shp', vfs='zip://examples/nybb_13a.zip') + assert 'geometry' in df + assert len(df) == 5