diff --git a/README.md b/README.md index 744836b..4a410bc 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ GeoPandas objects also know how to plot themselves. GeoPandas uses [descartes]( >>> g.plot() -GeoPandas also implements alternate constructors that can read any data format recognized by [fiona](http://toblerity.github.io/fiona). To read a [file containing the boroughs of New York City](http://www.nyc.gov/html/dcp/download/bytes/nybb_14aav.zip): +GeoPandas also implements alternate constructors that can read any data format recognized by [fiona](http://toblerity.github.io/fiona). To read a [file containing the boroughs of New York City](http://www1.nyc.gov/assets/planning/download/zip/data-maps/open-data/nybb_16a.zip): >>> boros = GeoDataFrame.from_file('nybb.shp') >>> boros.set_index('BoroCode', inplace=True) diff --git a/examples/nyc_boros.py b/examples/nyc_boros.py index 6db6ec5..3e70210 100644 --- a/examples/nyc_boros.py +++ b/examples/nyc_boros.py @@ -14,7 +14,7 @@ from geopandas import GeoSeries, GeoDataFrame np.random.seed(1) DPI = 100 -# http://www.nyc.gov/html/dcp/download/bytes/nybb_14aav.zip +# http://www1.nyc.gov/assets/planning/download/zip/data-maps/open-data/nybb_16a.zip boros = GeoDataFrame.from_file('nybb.shp') boros.set_index('BoroCode', inplace=True) boros.sort() diff --git a/tests/test_geodataframe.py b/tests/test_geodataframe.py index ea4a59e..9bc1bf7 100644 --- a/tests/test_geodataframe.py +++ b/tests/test_geodataframe.py @@ -21,10 +21,10 @@ class TestDataFrame(unittest.TestCase): def setUp(self): N = 10 - nybb_filename = download_nybb() + nybb_filename, nybb_zip_path = download_nybb() - self.df = read_file('/nybb_14a_av/nybb.shp', vfs='zip://' + nybb_filename) - with fiona.open('/nybb_14a_av/nybb.shp', vfs='zip://' + nybb_filename) as f: + self.df = read_file(nybb_zip_path, vfs='zip://' + nybb_filename) + with fiona.open(nybb_zip_path, vfs='zip://' + nybb_filename) as f: self.schema = f.schema self.tempdir = tempfile.mkdtemp() self.boros = self.df['BoroName'] @@ -373,8 +373,8 @@ class TestDataFrame(unittest.TestCase): self.assertTrue(all(df2['geometry'].geom_almost_equals(utm['geometry'], decimal=2))) def test_from_features(self): - nybb_filename = download_nybb() - with fiona.open('/nybb_14a_av/nybb.shp', + nybb_filename, nybb_zip_path = download_nybb() + with fiona.open(nybb_zip_path, vfs='zip://' + nybb_filename) as f: features = list(f) crs = f.crs diff --git a/tests/test_io.py b/tests/test_io.py index ec04bd7..3e838aa 100644 --- a/tests/test_io.py +++ b/tests/test_io.py @@ -9,11 +9,10 @@ from .util import PANDAS_NEW_SQL_API, unittest class TestIO(unittest.TestCase): def setUp(self): - nybb_filename = tests.util.download_nybb() - path = '/nybb_14a_av/nybb.shp' + nybb_filename, nybb_zip_path = tests.util.download_nybb() vfs = 'zip://' + nybb_filename - self.df = read_file(path, vfs=vfs) - with fiona.open(path, vfs=vfs) as f: + self.df = read_file(nybb_zip_path, vfs=vfs) + with fiona.open(nybb_zip_path, vfs=vfs) as f: self.crs = f.crs def test_read_postgis_default(self): diff --git a/tests/test_overlay.py b/tests/test_overlay.py index 4d0961f..2ac7c1c 100644 --- a/tests/test_overlay.py +++ b/tests/test_overlay.py @@ -12,9 +12,9 @@ class TestDataFrame(unittest.TestCase): def setUp(self): N = 10 - nybb_filename = download_nybb() + nybb_filename, nybb_zip_path = download_nybb() - self.polydf = read_file('/nybb_14a_av/nybb.shp', vfs='zip://' + nybb_filename) + self.polydf = read_file(nybb_zip_path, vfs='zip://' + nybb_filename) self.tempdir = tempfile.mkdtemp() self.crs = {'init': 'epsg:4326'} b = [int(x) for x in self.polydf.total_bounds] diff --git a/tests/test_sindex.py b/tests/test_sindex.py index 3ed3201..8a91865 100644 --- a/tests/test_sindex.py +++ b/tests/test_sindex.py @@ -7,7 +7,7 @@ from shapely.geometry import (Polygon, Point, LineString, MultiPoint, MultiLineString, MultiPolygon) from shapely.geometry.base import BaseGeometry from geopandas import GeoSeries, GeoDataFrame, base, read_file -from .util import unittest, geom_equals, geom_almost_equals +from .util import unittest, geom_equals, geom_almost_equals, download_nybb @unittest.skipIf(not base.HAS_SINDEX, 'Rtree absent, skipping') @@ -85,9 +85,8 @@ class TestFrameSindex(unittest.TestCase): class TestJoinSindex(unittest.TestCase): def setUp(self): - self.boros = read_file( - "/nybb_14a_av/nybb.shp", - vfs="zip://examples/nybb_14aav.zip") + nybb_filename, nybb_zip_path = download_nybb() + self.boros = read_file(nybb_zip_path, vfs='zip://' + nybb_filename) def test_merge_geo(self): # First check that we gets hits from the boros frame. diff --git a/tests/test_sjoin.py b/tests/test_sjoin.py index c7a8d71..63bd685 100644 --- a/tests/test_sjoin.py +++ b/tests/test_sjoin.py @@ -14,8 +14,8 @@ from geopandas.tools import sjoin class TestSpatialJoin(unittest.TestCase): def setUp(self): - nybb_filename = download_nybb() - self.polydf = read_file('/nybb_14a_av/nybb.shp', vfs='zip://' + nybb_filename) + nybb_filename, nybb_zip_path = download_nybb() + self.polydf = read_file(nybb_zip_path, vfs='zip://' + nybb_filename) self.tempdir = tempfile.mkdtemp() self.crs = {'init': 'epsg:4326'} N = 20 @@ -55,7 +55,7 @@ class TestSpatialJoin(unittest.TestCase): # points within polygons df = sjoin(self.pointdf, self.polydf, how="left", op="within") self.assertEquals(df.shape, (21,8)) - self.assertAlmostEquals(df.ix[1]['Shape_Leng'], 330454.175933) + self.assertEquals(df.ix[1]['BoroName'], 'Staten Island') # points contain polygons? never happens so we should have nulls df = sjoin(self.pointdf, self.polydf, how="left", op="contains") diff --git a/tests/util.py b/tests/util.py index b619a1f..b118c9f 100644 --- a/tests/util.py +++ b/tests/util.py @@ -1,5 +1,6 @@ import io import os.path +import zipfile from six.moves.urllib.request import urlopen from geopandas import GeoDataFrame, GeoSeries @@ -36,16 +37,26 @@ else: def download_nybb(): - """ Returns the path to the NYC boroughs file. Downloads if necessary. """ + """ Returns the path to the NYC boroughs file. Downloads if necessary. + + returns tuple (zip file name, shapefile's name and path within zip file)""" # Data from http://www.nyc.gov/html/dcp/download/bytes/nybb_14aav.zip # saved as geopandas/examples/nybb_14aav.zip. - filename = 'nybb_14aav.zip' + filename = 'nybb_16a.zip' full_path_name = os.path.join('examples', filename) if not os.path.exists(full_path_name): with io.open(full_path_name, 'wb') as f: - response = urlopen('http://www.nyc.gov/html/dcp/download/bytes/{0}'.format(filename)) + response = urlopen('http://www1.nyc.gov/assets/planning/download/zip/data-maps/open-data/{0}'.format(filename)) f.write(response.read()) - return full_path_name + + shp_zip_path = None + zf = zipfile.ZipFile(full_path_name, 'r') + # finds path name in zip file + for zip_filename_path in zf.namelist(): + if zip_filename_path.endswith('nybb.shp'): + break + + return full_path_name, ('/' + zip_filename_path) def validate_boro_df(test, df):