0

For this work Data are obtained from:- For Raster:-https://download.hermes.com.np/land-cover-map-of-nepal-2010/. For Vector :-https://cellapp.co/download-nepals-new-map-vector-image/. Rupandehi District was then selected and exported as a part of this work (named here as RupandehiLocalPlace).

Then, I clipped a raster file based on vector shapefile. The code I used as shown:-

library(sf)
library(rgdal)
library(raster)
setwd("C:/Users/lenovo/Desktop/EM")
LCN<-raster("np_lc_2010_v2f.tif")
RLU<-shapefile("RupandehiLocalPlace")
proj4string(RLU)
proj4string(LCN)
plot(LCN)
plot(RLU)
proj4string(LCN)<-CRS("+proj=utm +zone=44 +datum=WGS84 +units=m 
+no_defs")
raster::projection(LCN)
LCN<-crop(LCN,RLU)
plot(LCN,main="Forest Area in 2019")
plot(LCN,
main="Forest Area in 2019",
axes=TRUE)
plot(RLU,add= TRUE)

The result obtained is shown below:- enter image description here

But, I don't have an idea of masking data. Could someone let me know how to mask these data (raster based on vector). Also, I couldn't see spatial scale in either of direction. How can this be solved? I would be thankful for your answers.

5
  • How are you reprojecting the file?
    – aldo_tapia
    Jun 11, 2022 at 17:33
  • @aldo_tapia-I tried cropping raster with vector and don't have an idea of masking. I have edited my questions little bit. Please have a look. Hope for your constructive answers. Thank you.
    – Walker
    Jun 11, 2022 at 19:59
  • I recommend you to upload sample files to see what's happening
    – aldo_tapia
    Jun 12, 2022 at 0:07
  • BTW, check ?raster::mask and read the documentation. Since that could be a slow process, change the functions to terra package which is an improved (faster) raster package
    – aldo_tapia
    Jun 12, 2022 at 0:18
  • @aldo_tapia, For this work Data are obtained from:- For Raster:-download.hermes.com.np/land-cover-map-of-nepal-2010. For Vector :-cellapp.co/download-nepals-new-map-vector-image. Rupandehi District was then selected and exported as a part of this work (named here as RupandehiLocalPlace).
    – Walker
    Jun 12, 2022 at 0:28

1 Answer 1

1

First mask, then crop. This is using terra package (although I think you shared the wrong raster). Also you can select the district and reproject easily:

library(terra)

r <- rast('~/Downloads/Land%20Cover%20Map%20of%20Nepal%202010/np_lc_2010_v2f.tif')
v <- vect('~/Downloads/Local Unit/local_unit.shp')

v <- v[v$DISTRICT == "RUPANDEHI",]

v <- project(v,r)

plot(mask(crop(r,v),v))
plot(v, add = T)

enter image description here

3
  • Thanks its happening. But, can we display or reclassify the map into 2 classes i.e. forest and other woodland in one classes and remaining land-use in other classes. This will help in making map more meaning to look at and classify according to land-uses. Thanks in advance.
    – Walker
    Jun 12, 2022 at 2:37
  • 1
    Yes, you can. But that's a different question. One question per post.
    – aldo_tapia
    Jun 12, 2022 at 2:57
  • 1
    It should be first crop, then mask (and that is what you show). It is prettier to do crop(r, v, mask=TRUE) Jun 17, 2022 at 10:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.