[R-sig-Geo] Convert data.frame/SpatialPointsDataFrame to raster

Vijay Lulla v|j@y|u||@ @end|ng |rom gm@||@com
Wed Jul 31 21:20:47 CEST 2019


?`rasterFromXYZ` states that "x and y represent spatial coordinates and
must be on a regular grid."  And, it appears to me that you might be losing
values by rounding lon/lat values.  The help file further suggests that
`rasterize` might be the function you're looking for.  List members will
(certainly I will) find it more helpful to propose other solutions if you
post a small reproducible example of your original georeferenced dataset so
that we get an idea of what data you're using.

Sorry, I cannot be of more help.

On Wed, Jul 31, 2019 at 10:45 AM Miluji Sb <milujisb using gmail.com> wrote:

> Dear all,
>
> I have georeferenced dataset with multiple variables and years. The data is
> at ~100 km (1° × 1°) spatial resolution. I would like to convert this into
> a raster.
>
> I have filtered the data for one year and one variable and did the
> following;
>
> try <- subset(df, year==2010)
> try <- try[,c(1,2,4)]
> try$lon <- round(try$lon)
> try$lat <- round(try$lat)
> r_imp <- rasterFromXYZ(try)
>
> Two issues; is it possible to convert the original dataset with the
> multiple variables and years to a raster? If not, how can I avoid rounding
> the coordinates? Currently, I get this error "Error in rasterFromXYZ(try) :
> x cell sizes are not regular" without rounding.
>
> Any help will be greatly appreciated. Thank you!
>
> Sincerely,
>
> Shouro
>
> ## Data
> df <- structure(list(lon = c(180, 179.762810919291, 179.523658017568,
> 179.311342656601, 179.067616041778, 178.851382109362, 178.648816406322,
> 178.501097394651, 178.662722495847, 178.860599151485), lat =
> c(-16.1529296875,
> -16.21659020822, -16.266117894201, -16.393550535614, -16.4457378034442,
> -16.561653799838, -16.6533087696649, -16.7741069281329, -16.914110607613,
> -16.9049389730284), nsdec = structure(c(1L, 3L, 4L, 5L, 6L, 7L,
> 8L, 9L, 10L, 2L), .Label = c("1 of 10", "10 of 10", "2 of 10",
> "3 of 10", "4 of 10", "5 of 10", "6 of 10", "7 of 10", "8 of 10",
> "9 of 10"), class = "factor"), TWL_5 = c(2.13810426616849,
> 2.16767864033646,
> 2.16881240361846, 2.20727073247015, 2.27771608519709, 2.3649601141941,
> 2.44210984856767, 2.52466349543977, 2.63982954290745, 2.71828906773926
> ), TWL_50 = c(2.38302354555823, 2.43142793944275, 2.45733044901087,
> 2.53057109758284, 2.61391337469939, 2.71040967066483, 2.82546443373866,
> 2.9709907727849, 3.1785797371187, 3.33227647990861), TWL_95 =
> c(2.63753852023063,
> 2.7080249053612, 2.75483681166049, 2.86893038433795, 2.97758282474101,
> 3.14541928966618, 3.3986143008625, 3.68043269045659, 4.09571655859075,
> 4.57299670034984), year = c(2010, 2020, 2030, 2040, 2050, 2060,
> 2070, 2080, 2090, 2100)), row.names = c(NA, 10L), class = "data.frame")
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo using r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

	[[alternative HTML version deleted]]



More information about the R-sig-Geo mailing list