Skip to content

Commit acd8aba

Browse files
committed
fix conflicts
2 parents 313db10 + 465d253 commit acd8aba

File tree

2 files changed

+381
-379
lines changed

2 files changed

+381
-379
lines changed

index.Rmd

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ with open('data/AHN3_05m_DTM.tif', 'wb') as file:
144144
file.write(response.read())
145145
```
146146

147-
Before continuing, please check if this step was successful.
147+
Before continuing, please check if this step was successful (*Hint: you can check if files have been written into corresponding directory*).
148148

149149
## From a file with GDAL
150150
[GDAL](https://gdal.org/) handles raster and vector geospatial data formats with Python, Java, R and C APIs. When opening a raster file in gdal, the object has a hierarchical structure starting at the Dataset level. A Dataset has a Geotransform (metadata) and can contain one or more Bands. Each Band has a Data array and potentially Overviews.
@@ -156,6 +156,7 @@ Before continuing, please check if this step was successful.
156156
</center>
157157
</figure>
158158

159+
159160
Let us open the file we just saved. You will see you first get the dataset, and need to access the band (even though there is only one), before the data array can be accessed.
160161

161162
```{python, eval=FALSE}
@@ -177,13 +178,14 @@ ds = None
177178

178179
```{block, type="alert alert-success"}
179180
> **Question 1**: Why do we set ds to None at the end of your script? What may happen if you do not do that?
180-
181181
<details>
182-
<summary>**Click for answer**</summary>
182+
<summary>*Click for answer*</summary>
183183
Keeping files open may leave you vulnerable to losing data, (Geo)Pandas manage resources under the hood so you don't explicitly need to close files, but for the case of GDAL, and as you will later see, Rasterio, it's important to close your files or open them with a context manager `with open ...`
184184
</details>
185-
186185
```
186+
187+
188+
187189
The GDAL Python API is not the best documented Python module. Therefore, Rasterio is explained as an alternative raster data handling module.
188190

189191
## From a file with Rasterio
@@ -216,14 +218,14 @@ show(dsm, title='Digital Surface Model', cmap='gist_ncar')
216218

217219
```{block, type="alert alert-success"}
218220
> **Question 2**: Adjust the code above to take a look at the DTM. Note the gaps that appear. What are these gaps?
219-
220221
<details>
221-
<summary>**Click for answer**</summary>
222+
<summary>*Click for answer*</summary>
222223
These are buildings.
223224
</details>
224225
```
225226

226227

228+
227229
The metadata shows the driver (GDAL's way of knowing how to function with a specific file format), datatype, nodata value, width of raster in number of cells, height of raster in number of cells, number of raster bands in the dataset, coordinate reference system, and transformation values.
228230

229231
In the back-end, raster layers in Rasterio are stored as NumPy arrays, which appear when the data are read with the method `.read()`:
@@ -289,9 +291,8 @@ with rasterio.open('data/AHN3_05m_CHM.tif', 'w', **kwargs) as file:
289291

290292
```{block, type="alert alert-success"}
291293
> **Question 3**: Where is the CHM the highest in the study area? Is it what you expected?
292-
293294
<details>
294-
<summary>**Click for answer**</summary>
295+
<summary>*Click for answer*</summary>
295296
Think about where you have the most forests on campus.
296297
</details>
297298
```
@@ -370,14 +371,14 @@ plt.show()
370371

371372
```{block, type="alert alert-success"}
372373
> **Question 4**: Why do we want an equal scale in the x and y direction for this figure?
373-
374374
<details>
375-
<summary>**Click for answer**</summary>
375+
<summary>*Click for answer*</summary>
376376
To visualize the buildings properly, otherwise their geometries will be skewed.
377377
</details>
378-
379378
```
380379

380+
381+
381382
## Other functionality
382383
Note that this tutorial only scratches the surface of the possibilities of Rasterio. It can do most if not all things you did in `R` in the Vector - Raster tutorial. Rasterio for example also allows you to do [masking](https://rasterio.readthedocs.io/en/latest/topics/masking-by-shapefile.html), [reprojecting](https://rasterio.readthedocs.io/en/latest/topics/reproject.html), and [resampling](https://rasterio.readthedocs.io/en/latest/topics/resampling.html).
383384

@@ -474,14 +475,14 @@ plt.show()
474475

475476
```{block, type="alert alert-success"}
476477
> **Question 5**: What is represented on the x and y axis? The default axis labels are DN (x) and Frequency (y); if you were to change them, what labels would you pick to better reflect the content of the plots?
477-
478478
<details>
479-
<summary>**Click for answer**</summary>
480-
The y axis represents the count of pixels. Meanwhile the x axis represents the pixel's DN(digital value), in this tutorial since we are looking at elevation this value is actually meters. For example, in the first plot (DSM) you can see that most pixel values are in the 10 to 15 meter range
479+
<summary>*Click for answer*</summary>
480+
The y axis represents the count of pixels. Meanwhile the x axis represents the pixel's DN (digital value), in this tutorial since we are looking at elevation this value is actually meters. For example, in the first plot (DSM) you can see that most pixel values are in the 10 to 15 meter range
481481
</details>
482482
```
483483

484484

485+
485486
# More info
486487
* [Tutorial working with rasters in Python with Rasterio](https://geohackweek.github.io/raster/04-workingwithrasters/)
487488
* [Tutorial working with raster in Python with GDAL (for Python 2)](https://pcjericks.github.io/py-gdalogr-cookbook/raster_layers.html)

index.html

Lines changed: 366 additions & 365 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)