r - Polygon to Raster not as expected: Missing Values and Polygon Border Retained? -
folks,
i'm in need of expert opinions. i've spent majority of day fighting problem , out of options.
i trying create map depicts time since last fire across landscape
obviously spots have never had fire, represented 0 here, it's arbitrary
my code see below:
data can found here
#example library(rgdal) library(raster) library(plotkml) ##load data fire <- readogr(dsn="***yourpathhere******/h_fire_poly_jan3_2105", "fire_poly_kootclip") ##build raster1 r<-raster(res=300,extent(fire)) pop<-rasterize(fire,r,"fire_year",fun="max",na.rm=true,background=2015) pop<-projectraster(pop,res=300, crs="+proj=utm +zone=11 +ellps=grs80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs") plot(pop) ##build raster 2 background<-raster(extent(pop),res=300,vals=2015) projection(background)<-crs(proj4string(pop)) ##make sure plot(background) plot(pop,add=t) ##algebra final<-background-pop ##plot plot(final) ##export plotkml(final)
if don't want run code, looks on google earth
this main issue, where:
1) looks polygon border information being retained, tan lines exact borders,
2)the "max" not being reported here, around edges appears?
3) goal is, use map in conjunction other rasters in species distribution modelling (so use raster stack, model , predict function make map). when try make map layer, end pile of holes due na's...where there should no na's.
if run models without time since fire layer, good. when include it, na's in resulting map see tan "polygon outlines" in first pic.
how raster layer have crisp edges , not such mess is???
this final map species map looks like, not missing data mirrors issues in fire map
i think confusion comes visualization in google earth, not computations. looks when plot in r. should not use projectraster, however.
library(rgdal) library(raster) fire <- shapefile("fire_poly_kootclip") r <- raster(res=300,extent(fire)) pop <- rasterize(fire, r, "fire_year", fun="max", na.rm=true, background=2015) x <- pop-2015 plot(x)
simpler do
fire$since <- fire$fire_year - 2015 x <- rasterize(fire, r, "fire_year", fun="max", na.rm=true, background=-100) plot(x)
not -100 no fire similar 'a long time ago', not 'just now'.
Comments
Post a Comment