• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

docs/H11-Oct-2021-5,1703,705

examples/H11-Oct-2021-586362

rasterio/H11-Oct-2021-420,391267,070

tests/H11-Oct-2021-18,98314,291

PKG-INFOH A D11-Oct-202116.1 KiB448334

README.rstH A D11-Oct-202111.8 KiB416303

pyproject.tomlH A D11-Oct-202195 32

setup.cfgH A D01-Sep-2021352 1110

setup.pyH A D11-Oct-202114.7 KiB430329

README.rst

1========
2Rasterio
3========
4
5Rasterio reads and writes geospatial raster data.
6
7.. image:: https://travis-ci.com/mapbox/rasterio.png?branch=master
8   :target: https://travis-ci.com/mapbox/rasterio
9
10.. image:: https://coveralls.io/repos/github/mapbox/rasterio/badge.svg?branch=master
11   :target: https://coveralls.io/github/mapbox/rasterio?branch=master
12
13Geographic information systems use GeoTIFF and other formats to organize and
14store gridded, or raster, datasets. Rasterio reads and writes these formats and
15provides a Python API based on N-D arrays.
16
17Rasterio 1.2 works with Python versions 3.6 through 3.9, Numpy versions 1.15
18and newer, and GDAL versions 2.3 through 3.2. Official binary packages for
19Linux and Mac OS X are available on PyPI. Unofficial binary packages for
20Windows are available through other channels.
21
22Read the documentation for more details: https://rasterio.readthedocs.io/.
23
24Example
25=======
26
27Here's an example of some basic features that Rasterio provides. Three bands
28are read from an image and averaged to produce something like a panchromatic
29band.  This new band is then written to a new single band TIFF.
30
31.. code-block:: python
32
33    import numpy as np
34    import rasterio
35
36    # Read raster bands directly to Numpy arrays.
37    #
38    with rasterio.open('tests/data/RGB.byte.tif') as src:
39        r, g, b = src.read()
40
41    # Combine arrays in place. Expecting that the sum will
42    # temporarily exceed the 8-bit integer range, initialize it as
43    # a 64-bit float (the numpy default) array. Adding other
44    # arrays to it in-place converts those arrays "up" and
45    # preserves the type of the total array.
46    total = np.zeros(r.shape)
47    for band in r, g, b:
48        total += band
49    total /= 3
50
51    # Write the product as a raster band to a new 8-bit file. For
52    # the new file's profile, we start with the meta attributes of
53    # the source file, but then change the band count to 1, set the
54    # dtype to uint8, and specify LZW compression.
55    profile = src.profile
56    profile.update(dtype=rasterio.uint8, count=1, compress='lzw')
57
58    with rasterio.open('example-total.tif', 'w', **profile) as dst:
59        dst.write(total.astype(rasterio.uint8), 1)
60
61The output:
62
63.. image:: http://farm6.staticflickr.com/5501/11393054644_74f54484d9_z_d.jpg
64   :width: 640
65   :height: 581
66
67API Overview
68============
69
70Rasterio gives access to properties of a geospatial raster file.
71
72.. code-block:: python
73
74    with rasterio.open('tests/data/RGB.byte.tif') as src:
75        print(src.width, src.height)
76        print(src.crs)
77        print(src.transform)
78        print(src.count)
79        print(src.indexes)
80
81    # Printed:
82    # (791, 718)
83    # {u'units': u'm', u'no_defs': True, u'ellps': u'WGS84', u'proj': u'utm', u'zone': 18}
84    # Affine(300.0379266750948, 0.0, 101985.0,
85    #        0.0, -300.041782729805, 2826915.0)
86    # 3
87    # [1, 2, 3]
88
89A rasterio dataset also provides methods for getting extended array slices given
90georeferenced coordinates.
91
92
93.. code-block:: python
94
95    with rasterio.open('tests/data/RGB.byte.tif') as src:
96        print src.window(**src.window_bounds(((100, 200), (100, 200))))
97
98    # Printed:
99    # ((100, 200), (100, 200))
100
101Rasterio CLI
102============
103
104Rasterio's command line interface, named "rio", is documented at `cli.rst
105<https://github.com/mapbox/rasterio/blob/master/docs/cli.rst>`__. Its ``rio
106insp`` command opens the hood of any raster dataset so you can poke around
107using Python.
108
109.. code-block:: pycon
110
111    $ rio insp tests/data/RGB.byte.tif
112    Rasterio 0.10 Interactive Inspector (Python 3.4.1)
113    Type "src.meta", "src.read(1)", or "help(src)" for more information.
114    >>> src.name
115    'tests/data/RGB.byte.tif'
116    >>> src.closed
117    False
118    >>> src.shape
119    (718, 791)
120    >>> src.crs
121    {'init': 'epsg:32618'}
122    >>> b, g, r = src.read()
123    >>> b
124    masked_array(data =
125     [[-- -- -- ..., -- -- --]
126     [-- -- -- ..., -- -- --]
127     [-- -- -- ..., -- -- --]
128     ...,
129     [-- -- -- ..., -- -- --]
130     [-- -- -- ..., -- -- --]
131     [-- -- -- ..., -- -- --]],
132                 mask =
133     [[ True  True  True ...,  True  True  True]
134     [ True  True  True ...,  True  True  True]
135     [ True  True  True ...,  True  True  True]
136     ...,
137     [ True  True  True ...,  True  True  True]
138     [ True  True  True ...,  True  True  True]
139     [ True  True  True ...,  True  True  True]],
140           fill_value = 0)
141
142    >>> np.nanmin(b), np.nanmax(b), np.nanmean(b)
143    (0, 255, 29.94772668847656)
144
145Rio Plugins
146-----------
147
148Rio provides the ability to create subcommands using plugins.  See
149`cli.rst <https://github.com/mapbox/rasterio/blob/master/docs/cli.rst#rio-plugins>`__
150for more information on building plugins.
151
152See the
153`plugin registry <https://github.com/mapbox/rasterio/wiki/Rio-plugin-registry>`__
154for a list of available plugins.
155
156
157Installation
158============
159
160Please install Rasterio in a `virtual environment
161<https://www.python.org/dev/peps/pep-0405/>`__ so that its requirements don't
162tamper with your system's Python.
163
164SSL certs
165---------
166
167The Linux wheels on PyPI are built on CentOS and libcurl expects certs to be in
168/etc/pki/tls/certs/ca-bundle.crt. Ubuntu's certs, for example, are in
169a different location. You may need to use the CURL_CA_BUNDLE environment
170variable to specify the location of SSL certs on your computer. On an Ubuntu
171system set the variable as shown below.
172
173.. code-block:: console
174
175    $ export CURL_CA_BUNDLE=/etc/ssl/certs/ca-certificates.crt
176
177
178Dependencies
179------------
180
181Rasterio has a C library dependency: GDAL >= 2.3. GDAL itself depends on some
182other libraries provided by most major operating systems and also depends on
183the non standard GEOS and PROJ4 libraries. How to meet these requirement will
184be explained below.
185
186Rasterio's Python dependencies are (see the package metadata file):
187
188.. code-block::
189
190    affine
191    attrs
192    certifi
193    click>=4.0
194    cligj>=0.5
195    numpy
196    snuggs>=1.4.1
197    click-plugins
198    setuptools
199
200    [all]
201    hypothesis
202    pytest-cov>=2.2.0
203    matplotlib
204    boto3>=1.3.1
205    numpydoc
206    pytest>=2.8.2
207    shapely
208    ipython>=2.0
209    sphinx
210    packaging
211    ghp-import
212    sphinx-rtd-theme
213
214    [docs]
215    ghp-import
216    numpydoc
217    sphinx
218    sphinx-rtd-theme
219
220    [ipython]
221    ipython>=2.0
222
223    [plot]
224    matplotlib
225
226    [s3]
227    boto3>=1.3.1
228
229    [test]
230    boto3>=1.3.1
231    hypothesis
232    packaging
233    pytest-cov>=2.2.0
234    pytest>=2.8.2
235    shapely
236
237Development requires Cython and other packages.
238
239Binary Distributions
240--------------------
241
242Use a binary distributions that directly or indirectly provide GDAL if
243possible.
244
245Linux
246+++++
247
248Rasterio distributions are available from UbuntuGIS and Anaconda's conda-forge
249channel.
250
251`Manylinux1 <https://github.com/pypa/manylinux>`__ wheels are available on PyPI.
252
253OS X
254++++
255
256Binary distributions with GDAL, GEOS, and PROJ4 libraries included are
257available for OS X versions 10.9+. To install, run ``pip install rasterio``.
258These binary wheels are preferred by newer versions of pip.
259
260If you don't want these wheels and want to install from a source distribution,
261run ``pip install rasterio --no-binary rasterio`` instead.
262
263The included GDAL library is fairly minimal, providing only the format drivers
264that ship with GDAL and are enabled by default. To get access to more formats,
265you must build from a source distribution (see below).
266
267Windows
268+++++++
269
270Binary wheels for rasterio and GDAL are created by Christoph Gohlke and are
271available from his website.
272
273To install rasterio, simply download both binaries for your system (`rasterio
274<http://www.lfd.uci.edu/~gohlke/pythonlibs/#rasterio>`__ and `GDAL
275<http://www.lfd.uci.edu/~gohlke/pythonlibs/#gdal>`__) and run something like
276this from the downloads folder, adjusting for your Python version.
277
278.. code-block:: console
279
280    $ pip install -U pip
281    $ pip install GDAL-3.1.4-cp39-cp39‑win_amd64.whl
282    $ pip install rasterio‑1.1.8-cp39-cp39-win_amd64.whl
283
284You can also install rasterio with conda using Anaconda's conda-forge channel.
285
286.. code-block:: console
287
288    $ conda install -c conda-forge rasterio
289
290
291Source Distributions
292--------------------
293
294Rasterio is a Python C extension and to build you'll need a working compiler
295(XCode on OS X etc). You'll also need Numpy preinstalled; the Numpy headers are
296required to run the rasterio setup script. Numpy has to be installed (via the
297indicated requirements file) before rasterio can be installed. See rasterio's
298Travis `configuration
299<https://github.com/mapbox/rasterio/blob/master/.travis.yml>`__ for more
300guidance.
301
302Linux
303+++++
304
305The following commands are adapted from Rasterio's Travis-CI configuration.
306
307.. code-block:: console
308
309    $ sudo add-apt-repository ppa:ubuntugis/ppa
310    $ sudo apt-get update
311    $ sudo apt-get install gdal-bin libgdal-dev
312    $ pip install -U pip
313    $ pip install rasterio
314
315Adapt them as necessary for your Linux system.
316
317OS X
318++++
319
320For a Homebrew based Python environment, do the following.
321
322.. code-block:: console
323
324    $ brew update
325    $ brew install gdal
326    $ pip install -U pip
327    $ pip install --no-binary rasterio
328
329Windows
330+++++++
331
332You can download a binary distribution of GDAL from `here
333<http://www.gisinternals.com/release.php>`__.  You will also need to download
334the compiled libraries and headers (include files).
335
336When building from source on Windows, it is important to know that setup.py
337cannot rely on gdal-config, which is only present on UNIX systems, to discover
338the locations of header files and libraries that rasterio needs to compile its
339C extensions. On Windows, these paths need to be provided by the user. You
340will need to find the include files and the library files for gdal and use
341setup.py as follows. You will also need to specify the installed gdal version
342through the GDAL_VERSION environment variable.
343
344.. code-block:: console
345
346    $ python setup.py build_ext -I<path to gdal include files> -lgdal_i -L<path to gdal library> install
347
348With pip
349
350.. code-block:: console
351
352    $ pip install --no-use-pep517 --global-option -I<path to gdal include files> -lgdal_i -L<path to gdal library> .
353
354Note: :code:`--no-use-pep517` is required as pip currently hasn't implemented a
355way for optional arguments to be passed to the build backend when using PEP 517.
356See `here <https://github.com/pypa/pip/issues/5771>`__ for more details.
357
358Alternatively environment variables (e.g. INCLUDE and LINK) used by MSVC compiler can be used to point
359to include directories and library files.
360
361We have had success compiling code using the same version of Microsoft's
362Visual Studio used to compile the targeted version of Python (more info on
363versions used `here
364<https://docs.python.org/devguide/setup.html#windows>`__.).
365
366Note: The GDAL DLL and gdal-data directory need to be in your
367Windows PATH otherwise rasterio will fail to work.
368
369
370Support
371=======
372
373The primary forum for questions about installation and usage of Rasterio is
374https://rasterio.groups.io/g/main. The authors and other users will answer
375questions when they have expertise to share and time to explain. Please take
376the time to craft a clear question and be patient about responses.
377
378Please do not bring these questions to Rasterio's issue tracker, which we want
379to reserve for bug reports and other actionable issues.
380
381While Rasterio's repo is in the Mapbox GitHub organization, Mapbox's Support
382team is focused on customer support for its commercial platform and Rasterio
383support requests may be perfunctorily closed with or without a link to
384https://rasterio.groups.io/g/main. It's better to bring questions directly to
385the main Rasterio group at groups.io.
386
387Development and Testing
388=======================
389
390See `CONTRIBUTING.rst <CONTRIBUTING.rst/>`__.
391
392Documentation
393=============
394
395See `docs/ <docs/>`__.
396
397License
398=======
399
400See `LICENSE.txt <LICENSE.txt>`__.
401
402Authors
403=======
404
405See `AUTHORS.txt <AUTHORS.txt>`__.
406
407Changes
408=======
409
410See `CHANGES.txt <CHANGES.txt>`__.
411
412Who is Using Rasterio?
413======================
414
415See `here <https://libraries.io/pypi/rasterio/usage>`__.
416