Repository: rasterio/rasterio

Issue:
error reading band in 0.16 (worked with 0.15.1)
After upgrading from 0.15.1 to 0.16 I get this error:

```
Python 2.7.8 (default, Jun 30 2014, 16:08:48) [MSC v.1500 64 bit (AMD64)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> import rasterio
>>> rasterio.__version__
'0.16'
>>> r = rasterio.open('LE72300072013169EDC00_B1.TIF')
>>> a = r.read_band(1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "rasterio\_io.pyx", line 548, in rasterio._io.RasterReader.read_band (ras
terio/_io.c:6639)
  File "rasterio\_io.pyx", line 654, in rasterio._io.RasterReader.read (rasterio
/_io.c:8080)
TypeError: long() argument must be a string or a number, not 'NoneType'
>>>
```

This and all Landsat files I tried used to work with previous versions. If needed, the file is here: https://www.dropbox.com/s/7cr2u0osofzx55a/LE72300072013169EDC00_B1.TIF?dl=0

shade.tif and RGB.byte.tif from rasterio's test data do not produce this error.

The binaries I'm using are Christoph Gohlke's rasterio-0.15.1.win-amd64-py2.7.exe and rasterio-0.16-cp27-none-win_amd64.whl but Travis fails on linux too (https://travis-ci.org/citterio/rasterio/builds/46138951) when I add a test using the above file. The same error message is slightly different on py3: 

```
TypeError: int() argument must be a string or a number, not 'NoneType'
```



Discussion:

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -1,6 +1,17 @@
 #!/usr/bin/env python
+
+# Two environmental variables influence this script.
+#
+# GDAL_CONFIG: the path to a gdal-config program that points to GDAL headers,
+# libraries, and data files.
+#
+# PACKAGE_DATA: if defined, GDAL and PROJ4 data files will be copied into the
+# source or binary distribution. This is essential when creating self-contained
+# binary wheels.
+
 import logging
 import os
+import shutil
 import subprocess
 import sys
 from setuptools import setup
@@ -43,13 +54,15 @@
     sys.exit(1)
 
 try:
-    gdal_config = "gdal-config"
+    gdal_config = os.environ.get('GDAL_CONFIG', 'gdal-config')
     with open("gdal-config.txt", "w") as gcfg:
         subprocess.call([gdal_config, "--cflags"], stdout=gcfg)
         subprocess.call([gdal_config, "--libs"], stdout=gcfg)
+        subprocess.call([gdal_config, "--datadir"], stdout=gcfg)
     with open("gdal-config.txt", "r") as gcfg:
         cflags = gcfg.readline().strip()
         libs = gcfg.readline().strip()
+        datadir = gcfg.readline().strip()
     for item in cflags.split():
         if item.startswith("-I"):
             include_dirs.extend(item[2:].split(":"))
@@ -61,9 +74,30 @@
         else:
             # e.g. -framework GDAL
             extra_link_args.append(item)
+
+    # Conditionally copy the GDAL data. To be used in conjunction with
+    # the bdist_wheel command to make self-contained binary wheels.
+    if os.environ.get('PACKAGE_DATA'):
+        try:
+            shutil.rmtree('rasterio/gdal_data')
+        except OSError:
+            pass
+        shutil.copytree(datadir, 'rasterio/gdal_data')
+
 except Exception as e:
     log.warning("Failed to get options via gdal-config: %s", str(e))
 
+# Conditionally copy PROJ.4 data. Presumes PROJ.4 is installed locally
+# with --prefix=/usr/local.
+if os.environ.get('PACKAGE_DATA'):
+    projdatadir = '/usr/local/share/proj'
+    if os.path.exists(projdatadir):
+        try:
+            shutil.rmtree('rasterio/proj_data')
+        except OSError:
+            pass
+        shutil.copytree(projdatadir, 'rasterio/proj_data')
+
 ext_options = dict(
     include_dirs=include_dirs,
     library_dirs=library_dirs,
@@ -130,37 +164,41 @@
 if sys.version_info < (3, 4):
     inst_reqs.append('enum34')
 
-setup(name='rasterio',
-      version=version,
-      description=(
-          "Fast and direct raster I/O for Python programmers who use Numpy"),
-      long_description=readme,
-      classifiers=[
-          'Development Status :: 4 - Beta',
-          'Intended Audience :: Developers',
-          'Intended Audience :: Information Technology',
-          'Intended Audience :: Science/Research',
-          'License :: OSI Approved :: BSD License',
-          'Programming Language :: C',
-          'Programming Language :: Python :: 2.6',
-          'Programming Language :: Python :: 2.7',
-          'Programming Language :: Python :: 3.3',
-          'Programming Language :: Python :: 3.4',
-          'Topic :: Multimedia :: Graphics :: Graphics Conversion',
-          'Topic :: Scientific/Engineering :: GIS'
-          ],
-      keywords='raster gdal',
-      author='Sean Gillies',
-      author_email='sean@mapbox.com',
-      url='https://github.com/mapbox/rasterio',
-      license='BSD',
-      package_dir={'': '.'},
-      packages=['rasterio', 'rasterio.rio'],
-      entry_points='''
+setup_args = dict(
+    name='rasterio',
+    version=version,
+    description="Fast and direct raster I/O for use with Numpy and SciPy",
+    long_description=readme,
+    classifiers=[
+        'Development Status :: 4 - Beta',
+        'Intended Audience :: Developers',
+        'Intended Audience :: Information Technology',
+        'Intended Audience :: Science/Research',
+        'License :: OSI Approved :: BSD License',
+        'Programming Language :: C',
+        'Programming Language :: Python :: 2.6',
+        'Programming Language :: Python :: 2.7',
+        'Programming Language :: Python :: 3.3',
+        'Programming Language :: Python :: 3.4',
+        'Topic :: Multimedia :: Graphics :: Graphics Conversion',
+        'Topic :: Scientific/Engineering :: GIS'],
+    keywords='raster gdal',
+    author='Sean Gillies',
+    author_email='sean@mapbox.com',
+    url='https://github.com/mapbox/rasterio',
+    license='BSD',
+    package_dir={'': '.'},
+    packages=['rasterio', 'rasterio.rio'],
+    entry_points='''
         [console_scripts]
         rio=rasterio.rio.main:cli
-      ''',
-      include_package_data=True,
-      ext_modules=ext_modules,
-      zip_safe=False,
-      install_requires=inst_reqs )
+    ''',
+    include_package_data=True,
+    ext_modules=ext_modules,
+    zip_safe=False,
+    install_requires=inst_reqs)
+
+if os.environ.get('PACKAGE_DATA'):
+    setup_args['package_data'] = {'rasterio': ['gdal_data/*', 'proj_data/*']}
+
+setup(**setup_args)


Test patch: