Merge pull request #296 from micahcochran/nybb-fix

Update nybb url.
This commit is contained in:
Joris Van den Bossche
2016-04-10 22:58:53 +02:00
8 changed files with 33 additions and 24 deletions
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -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()
+5 -5
View File
@@ -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
+3 -4
View File
@@ -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):
+2 -2
View File
@@ -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]
+3 -4
View File
@@ -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.
+3 -3
View File
@@ -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")
+15 -4
View File
@@ -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):