0

My task is to extract values from raster A and B from point location file A and B, respectively. Both point location files have 375152482 obs. of 2 variables. The only different is A is in XY coordinates and B is in lat-long.

# point locations A
> pts.xy[1:5,]
     X        Y
1 330763.5 612830.1
2 330788.5 612830.1
3 330813.5 612830.1
4 330838.5 612830.1
5 330863.5 612830.1

# raster A   
> grespace_500 
class       : RasterLayer 
dimensions  : 48600, 26020, 1264572000  (nrow, ncol, ncell)
resolution  : 25, 25  (x, y)
extent      : 5500.998, 656001, 5333.603, 1220334  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +datum=OSGB36 +units=m +no_defs +ellps=airy +towgs84=446.448,-125.157,542.060,0.1502,0.2470,0.8421,-20.4894 
data source : C:\2.raster\grespace_500.tif 
names       : grespace_500 
values      : 0, 78.5625  (min, max)

# exatrct function A
grespace_500_pt <- extract(grespace_500, pts.xy, method = "simple") # took 10 days

# point locations B
> pts.latlon[1:5,]
     lon      lat
1  -3.094922 55.40450
2  -3.094527 55.40450
3  -3.094132 55.40450
4  -3.093738 55.40451
5  -3.093343 55.40451

# raster B
> no22015
class       : RasterBrick 
dimensions  : 401, 701, 281101, 365  (nrow, ncol, ncell, nlayers)
resolution  : 0.1, 0.1  (x, y)
extent      : -25.05, 45.05, 29.95, 70.05  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0 
data source : C:\2.raster\4.ENSa.2015.NO2.yearlyrea.daymean.nc 
names       : X20150101.4791667, X20150102.4791667, X20150103.4791667, X20150104.4791667, X20150105.4791667, X20150106.4791667, X20150107.4791667, X20150108.4791667, X20150109.4791667, X20150110.4791667, X20150111.4791667, X20150112.4791667, X20150113.4791667, X20150114.4791667, X20150115.4791667, ... 
z-value     : 20150101.4791667, 20151231.4791667 (min, max)
varname     : NO2 

# extract function B
vars <- extract(no22015, pts.latlon, method = "simple") # under 30 mins

The 2nd dataset finished fairly quickly (under 30min), but the 1st dataset has stuck at the extract function for over 10 days... although the resolution of the raster B (~10km) is much smaller than raster A, the number of locations to be extracted was the same so I would assume they should take similar time? Plus raster B is a raster stack of 365 raster layers which mean the function performed 365 times.

Any idea why the 1st dataset is taking so long and any ways to make it quicker?

  • I would suggest you to look at the velox package, which provide functions analogous to those from teh raster package but remarkably more efficient. – Bruno Conte Leite Apr 2 at 13:14
  • 1
    @BrunoConteLeite Thanks for pointing this out! The extract function in velox pkg is much quicker than raster::extract, only velox('raster') takes some time. Still very useful though! – veonly Apr 6 at 18:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.