3

I have a raster layer and a polygon layer overlaying the raster. The thing is that I want to make a new raster as follows: 1) the extents of the new raster should be the same as the old raster. 2) The cells which are overlain by polygons should have a value of 1 and the parts which are not overlain by polygons, should have the value of zero.

enter image description here

1
  • 1
    Don't forget to take the Tour which is designed to introduce all users to this site and its protocols. If you are not using R, then please ask a new question, and specify the GIS software that you are using.
    – PolyGeo
    Jan 24, 2018 at 5:11

2 Answers 2

6

You do not specify the software you are using, so I assume it is R. Here is how you can do it:

Some example data

library(raster)
pols <- shapefile(system.file("external/lux.shp", package="raster"))[1:3, ]
r <- raster(extent(pols), res=.01)

Solution

r <- rasterize(pols, r, field=1, background=0)
plot(r)
1
  • Thanks a lot. I forgot to say I'm using ArcGIS but I tried your advice in R and it worked :)
    – Arsalan
    Jan 24, 2018 at 18:37
0

You need to convert the polygon to raster with class 1 (raster1). and reclassify your raster to have class zero(raster2). Then using "raster calculator", write this:

Con(IsNull(raster1),raster2, raster1)

So whenever the value exists in raster 1, it will be assigned to the cell; if no data in raster 1, it will take value from raster 2.

Your Answer

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

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