Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chapter 3 #80

Merged
merged 31 commits into from
Aug 31, 2017
Merged

Chapter 3 #80

merged 31 commits into from
Aug 31, 2017

Conversation

jannes-m
Copy link
Collaborator

Work on #69

Note that the corresponding functions also have a geographical equivalent.
Sometimes you can even use the same functions for attribute and spatial operations.
This is, for example, the case for subsetting as base R's `[` and tidyverse's `filter()` let you also subset spatial data based on the spatial extent of another spatial object (see Chapter \@ref(spatial-data-operations)).
That is, the skills you learn here are cross-transferable which is also why this chapter lays the foundation for the next chapter (Chapter \@ref(spatial-data-operations)) which extends the here presented methods to the spatial world.

In the case of raster data we will learn how to create, and how to extract cell values from one layer and multiple layers at once (subsetting).
Finally, we will introduce the concept of map algebra.
Since the underlying mathematics is basically matrix algebra (see above), we present them in this chapter (non-spatial attribute operations).
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Robinlovelace @Nowosad
I think this is justified but might be controversial. What is your opinion on this matter? Of course, one could also argue to present map algebra in chapter 4. Or we could also think about rearranging the chapter structure. For instance, instead of chapter 3 Non-spatial attributes and 4 Spatial operations, we could have chapter 3 on vector data including non-spatial and spatial operations and chapter 4 on just raster data.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That a tough decision to make. Extracting values is definitely "non-spatial" thing, I would assume that zonal operations are "spatial", and map algebra is somewhat in the grey zone...

@Robinlovelace, what do you think about this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Somewhere above in the text I explain:
The raster header simply gives the matrix a spatial dimension which we need when plotting the raster or when we want to combine two rasters, think, for instance, of adding the values of one raster to another. Before such an operation, the corresponding algorithm simply checks if the two rasters share the same extent, projection and resolution, that is the raster headers. Hence, the spatial dimension of raster data is (often) of no importance at the processing level. Then, raster processing uses in fact matrix algebra which is why it is so much faster compared to vector processing.
It doesn't matter if is local, focal, zonal or global (all of these operations are part of the map algebra definition), it is just matrix algebra. Zones are not identified via coordinates but via indices, say mat[c(1:3, 4:7, 12:18), c(24:28, 77:100)] or cell IDs - nothing spatial about this.
But yes, you are right, might be controversial. On the other hand, when we can explain why we putting it here, you can't really argue with it.
Anyways, it's a tough call as you say, and that's why I also proposed to simply separate vector and raster into two chapters.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting discussion and sorry for arriving late to it. I agree that matrix algebra is important when thinking about rasters in depth but it's not essential to know that that's why raster datasets are conducive to fast, scalable and parallel processing. I agree that a raster is a very different beast compared with a vector dataset however, having given it some thought, I suggest we don't split-out the raster stuff into a new chapter at this stage.

I think the amount of effort to restructure and re-word everything around this new way of doing things would take-up a fair amount of time, while there are clearly 'lower hanging fruit' in terms of finishing a cohesive draft ready for the reviewers (Chapter 4 is in a sorrier state than Chapter 3 atm, and Chapter 5 could definitely benefit from some work). I think it's a rather 'GIS-y' structure to cover the vector and raster data separately but I think it's good to consider them all as spatial datasets which you can do.

It does make me think about the importance of raster-vector conversion and operations - (see https://stat.ethz.ch/pipermail/r-sig-geo/2017-August/025937.html ) - and suggest we put in a section on Raster-vector operations in Chapter 4 - would fit nicely in there now I've re-ordered things there is plenty of space (I would say 9 sections per chapter is enough).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plus have just added a question to reviewers on this: de26707

In Chapter 13 we will learn how to access GIS functionality from within R.
<!-- Reference 13-gis chapter -->

**Zonal and global operations**
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not finished the rest yet, still have to write this. Will do so tomorrow.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great piece of continuous technical prose.

as(., "Spatial")

#**********************************************************
# 2 FOCAL EXAMPLE------------------------------------------
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Nowosad Yes, I have also looked at visualraster but was not entirely convinced. But I admit, I am a bit biased towards lattice. But I guess it doesn't matter which code we use here, lattice or ggplot2, since we don't show it in the book, and the results of both packages should be identical.

A focal operation applies an aggregation function to all cells within the specified neighborhood, uses the corresponding output as the new value for the the central cell, and moves on to the next central cell (Figure @ref(fig:focal_example)).
Other names for this operation are spatial filtering and convolution [@burrough_principles_2015].

In R, we can use the `focal()` function to perform spatial filtering.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good description of focal operations (are they spatial or attribute thought ; ) I think they are fine here but could also fit in Chapter 4. Let me know when your teeth into that chapter if you think it fits...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we could add them to Chapter 4 as well. In any case, I would recommend not to spread the different pillars of map algebra into different chapters, i.e. if we put the focal stuff into c4 we should do so with the local, zonal and global operations. I guess, this is also what most readers would expect.
Thanks for adding the raster question to the list for the reviewers. Good idea to move on in the meantime 😃

```

```{r focal_example, echo = FALSE, fig.cap = "Input raster (left) and resulting output raster (right) due to a focal operation - summing up 3-by-3 windows"}
knitr::include_graphics("figures/03_focal_example.png")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an excellent figure, great work.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, glad you like it!

@Robinlovelace
Copy link
Collaborator

Just looking over this PR and thinking it's looking great. It would be great to have this ready for the workshop on Monday so would like to merge this Friday morning. Great to see you getting stuck-in with writing too - there will be much more of that after these first 5 chapters are off to reviewers and that will be really fun.

@jannes-m
Copy link
Collaborator Author

Ok, I have also written the paragraphs on zonal and global operations. I also added a few raster exercises. I think this should be enough here? Or do you have any further recommendations? I think I will refine tiny bits tomorrow but I can always issue an new PR if you are in a hurry.

@Nowosad Nowosad merged commit 93a40f4 into geocompx:master Aug 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants