I have two datasets:
- A raster file containing per-pixel vegetation classifications across Australia.
The file is described to have projection of EPSG:3577 https://epsg.io/3577. All additional meta data, along with data itself can be found at http://www.agriculture.gov.au/abares/forestsaustralia/forest-data-maps-and-tools/spatial-data/forest-cover
- A csv file containing data a latitude column, a longitude column, and various other variables.
As this is a large dataset also, I will only provide the head of this:
firms <- structure(list(latitude = c(-20.5897, -22.4119, -21.132, -23.9083,
-23.5908, -23.689), longitude = c(147.6421, 148.8484, 148.1897,
147.2966, 150.1676, 150.0994), brightness = c(320.7, 316.7, 320.5,
320.1, 315.8, 314.3), scan = c(1.6, 2.1, 1.8, 1.7, 2.7, 2.7),
track = c(1.3, 1.4, 1.3, 1.3, 1.6, 1.6), acq_date = c("2017-01-01",
"2017-01-01", "2017-01-01", "2017-01-01", "2017-01-01", "2017-01-01"
), acq_time = c(47L, 47L, 47L, 47L, 47L, 47L), satellite = c("Terra",
"Terra", "Terra", "Terra", "Terra", "Terra"), instrument = c("MODIS",
"MODIS", "MODIS", "MODIS", "MODIS", "MODIS"), confidence = c(34L,
26L, 36L, 53L, 33L, 22L), version = c(6.2, 6.2, 6.2, 6.2,
6.2, 6.2), bright_t31 = c(299.6, 295.3, 299.7, 296.6, 291.7,
289.3), frp = c(19, 25.8, 22.9, 17.6, 35.4, 30), daynight = c("D",
"D", "D", "D", "D", "D"), type = c(0L, 0L, 0L, 0L, 0L, 0L
)), row.names = c(NA, -6L), class = c("data.table", "data.frame"
), .internal.selfref = <pointer: 0x10200e2e0>)
My goal is simple:
Plot the raster data and then plot the each row from the csv file as a point on top of the raster.
I am happy with plot()
, levelplot()
, or ggplot()
although the latter seems silly as it takes too much time to convert this massive raster to a data.frame.
So far my code looks like this:
library(rgdal)
library(raster)
library(rasterVis)
library(sp)
- Load in the raster file
test <- raster('w001000.adf')
- Then create coordinates for the data.frame and make it a SpatialPoints format
coordinates(firms) <- ~longitude + latitude
firms_pts <- SpatialPoints(coords=coordinates(firms), proj4string = CRS("+proj=aea +lat_1=-18 +lat_2=-36 +lat_0=0 +lon_0=132 +x_0=0 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs"))
- Transform the points data into the same
crs
as the raster
firms_lyr <- spTransform(firms_pts, crs(test))
When I try to plot the data at this point, I cannot see any of the points.
- So I use the same extent in both datasets and now then plot roughly on top of each other.
extent(test) <- extent(firms)
- plot
plot(test)
points(firms_lyr, pch=16, cex=0.1)
NOW... annoyingly, the data sets are not properly aligned spatially
Clearly this is something to do with the projection.
I am pretty sure I am doing something wrong in steps 3 and/or 4