New notebook section.

This commit is contained in:
Sean Gillies 2014-09-13 21:22:25 -07:00
parent 210fe503ce
commit 68b6a7e76a

View File

@ -1,7 +1,7 @@
{
"metadata": {
"name": "",
"signature": "sha256:9c5860eecfa65f7a3892acd0ea0bbd0d8bdf4776f00b9d0d406f1df74aa2402c"
"signature": "sha256:5a6908bb26106597e34dd231b1a5f453aaa6e8a3e4c9298d8c3baaf3c3e0c4a1"
},
"nbformat": 3,
"nbformat_minor": 0,
@ -14,9 +14,13 @@
"source": [
"# An introduction to Rasterio\n",
"\n",
"The smallest interesting problems [1] addressed by Rasterio are reading raster data from files as Numpy arrays and writing such arrays back to files. In between, you can use the world of scientific python software to analyze and process the data. Rasterio provides a few operations that are described in the next notebooks.\n",
"The smallest interesting problems [1] addressed by Rasterio are reading raster data from files as [Numpy](http://www.numpy.org/) arrays and writing such arrays back to files. In between, you can use the world of scientific python software to analyze and process the data. Rasterio also provides a few operations that are described in the next notebooks in this series.\n",
"\n",
"## Structure of a dataset\n",
"This notebook demonstrates the basics of reading and writing raster data with Rasterio.\n",
"\n",
"## Overview of a dataset\n",
"\n",
"A raster dataset consists of one or more dense (as opposed to sparse) 2-D arrays of scalar values. An RGB TIFF image file is a good example of a raster dataset. It has 3 bands (or channels \u2013 we'll call them bands here) and each has a number of rows (its `height`) and columns (its `width`) and a uniform data type (unsigned 8-bit integers, 64-bit floats, etc). Geospatially referenced datasets will also possess a mapping from image to world coordinates (a `transform`) in a specific coordinate reference system (`crs`). This metadata about a dataset is readily accessible using Rasterio.\n",
"\n",
"The Scientific Python community often imports numpy as `np`. Do this and also import rasterio."
]
@ -32,13 +36,13 @@
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 1
"prompt_number": 9
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now open the GeoTIFF file \"RGB.byte.tif\" using `rasterio.open()`."
"Rasterio uses for many of its tests a small 3-band GeoTIFF file named \"RGB.byte.tif\". Open it using the function `rasterio.open()`."
]
},
{
@ -50,7 +54,7 @@
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 2
"prompt_number": 10
},
{
"cell_type": "markdown",
@ -71,13 +75,13 @@
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 3,
"prompt_number": 11,
"text": [
"'../tests/data/RGB.byte.tif'"
]
}
],
"prompt_number": 3
"prompt_number": 11
},
{
"cell_type": "code",
@ -91,13 +95,13 @@
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 4,
"prompt_number": 12,
"text": [
"'r'"
]
}
],
"prompt_number": 4
"prompt_number": 12
},
{
"cell_type": "code",
@ -111,13 +115,13 @@
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 5,
"prompt_number": 13,
"text": [
"False"
]
}
],
"prompt_number": 5
"prompt_number": 13
},
{
"cell_type": "markdown",
@ -138,7 +142,7 @@
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 6,
"prompt_number": 14,
"text": [
"{'affine': Affine(300.0379266750948, 0.0, 101985.0,\n",
" 0.0, -300.041782729805, 2826915.0),\n",
@ -158,7 +162,7 @@
]
}
],
"prompt_number": 6
"prompt_number": 14
},
{
"cell_type": "code",
@ -172,13 +176,13 @@
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 7,
"prompt_number": 15,
"text": [
"{'init': u'epsg:32618'}"
]
}
],
"prompt_number": 7
"prompt_number": 15
},
{
"cell_type": "markdown",
@ -200,13 +204,13 @@
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 8,
"prompt_number": 16,
"text": [
"True"
]
}
],
"prompt_number": 8
"prompt_number": 16
},
{
"cell_type": "markdown",
@ -235,6 +239,146 @@
],
"prompt_number": 23
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Dataset layout\n",
"\n",
"Three properties of a Rasterio dataset tell you a lot about it in Numpy terms. The `shape` of a dataset is a `height, width` tuple and is exactly the shape of Numpy arrays that would be read from it. The testing dataset has 718 rows and 791 columns."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"src.shape"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 26,
"text": [
"(718, 791)"
]
}
],
"prompt_number": 26
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The `count` of bands in the dataset is 3."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"src.count"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 27,
"text": [
"3"
]
}
],
"prompt_number": 27
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"All three of its bands contain 8-bit unsigned integers."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"src.dtypes"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 28,
"text": [
"['uint8', 'uint8', 'uint8']"
]
}
],
"prompt_number": 28
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Numpy concepts are the model here. If you wanted to create a 3-D Numpy array into which the testing data file's bands would fit without any resampling, you would use the following Python code."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"dest = np.empty((src.count,) + src.shape, dtype='uint8')\n",
"dest"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 25,
"text": [
"array([[[0, 0, 0, ..., 0, 0, 0],\n",
" [0, 0, 0, ..., 0, 0, 0],\n",
" [0, 0, 0, ..., 0, 0, 0],\n",
" ..., \n",
" [0, 0, 0, ..., 0, 0, 0],\n",
" [0, 0, 0, ..., 0, 0, 0],\n",
" [0, 0, 0, ..., 0, 0, 0]],\n",
"\n",
" [[0, 0, 0, ..., 0, 0, 0],\n",
" [0, 0, 0, ..., 0, 0, 0],\n",
" [0, 0, 0, ..., 0, 0, 0],\n",
" ..., \n",
" [0, 0, 0, ..., 0, 0, 0],\n",
" [0, 0, 0, ..., 0, 0, 0],\n",
" [0, 0, 0, ..., 0, 0, 0]],\n",
"\n",
" [[0, 0, 0, ..., 0, 0, 0],\n",
" [0, 0, 0, ..., 0, 0, 0],\n",
" [0, 0, 0, ..., 0, 0, 0],\n",
" ..., \n",
" [0, 0, 0, ..., 0, 0, 0],\n",
" [0, 0, 0, ..., 0, 0, 0],\n",
" [0, 0, 0, ..., 0, 0, 0]]], dtype=uint8)"
]
}
],
"prompt_number": 25
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## References"
]
},
{
"cell_type": "markdown",
"metadata": {},