[R-sig-Geo] Raster map from data.frame

Maurizio Marchi mauriziomarchi85 at gmail.com
Sat Apr 11 12:19:57 CEST 2015


Hi Michael, many thanks for your answer. The raster::rasterFromXYZ function
works perfectly and you solved my problem!! Many thanks

Il giorno gio 9 apr 2015 alle ore 15:29 Michael Sumner <mdsumner at gmail.com>
ha scritto:

> raster::rasterFromXYZ  should do the trick. I always feel a little ill
> turning raw tabular data into a raster, it's so easy(!) but represents a
> ridiculous amount of redundancy that gets turned into a simple rule - which
> is what the data should have been in the first place.
>
> A somewhat more general solution exists in sp, you would do this ("d" is
> your data frame with "x", "y", "z" columns):
>
> library(sp)
> coordinates(d) <- c("x", "y")
> gridded(d) <- TRUE
>
> That would give you a "SpatialPixelsDataFrame", which does two things
> (that should be separate IMO):
>
> - allows the grid to be sparse (note that algorithms to detect
> "regularity" in any arbitrary set of coordinates is quite hard to achieve,
> and impossible in some scenarios - if it's a grid that should be explicit,
> why would its extent be defined by populated cells, etc., rant . . .)
> - it allows some level of non-regularity, and it  justifies this by
> storing the original explicit coordinates so it can restore them if needed
>
> Also note the raster::rasterFromXYZ case needs extra work to apply it to
> multiple-attributed grids (no matter if you have one "z" column or any
> number of them the sp case works fine). You can also ingest any sp grid
> into raster() or raster::stack() or brick(). If rgdal is present you can
> writeRaster() to a .tif as well.
>
> If your data really are not regular (why would you store all those
> coordinates?), then you might
> - rasterize from irregular data (or explore other model solutions from
> packages like gstat)
> - use sp::points2grid to control the threshold of "regularity" (really
> this is for getting around numeric fuzz, but can be used)
>
> (note also that rasterFromXYZ has a digits argument, similar to
> points2grid's eps)
>
> HTH
>
>
>
>
>
> On Thu, 9 Apr 2015 at 22:44 Maurizio Marchi <mauriziomarchi85 at gmail.com>
> wrote:
>
>> Hi everybody, I need help with a big dataset that I need to transform in a
>> group of raster files. I have a big .csv (2 GB with 5 millions rows and 90
>> columns) which I want to transform in a group of raster images. The First
>> two culms represent the geographical coordinates while the others 88
>> columns represent the values I want to give to each cell of each raster
>> (temperatures, precipitations etc...). The database is compiled only with
>> the cells that will have a value (NA cells were not calculated).  I often
>> used the data.frame2ascii function of SDMTools package but in this case
>> the
>> function doesn't works (too many rows maybe?).
>> Any suggestion? I prefer the .asc format but even GeoTiff or other formats
>> would be ok.
>>
>> Manu thanks,
>> Maurizio
>>
>>
>>
>> --
>> Maurizio Marchi
>> Calenzano (FI) - Italy
>> ID Skype: maurizioxyz
>> Ubuntu 14.04 LTS
>> linux user 552742
>>
>>         [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at 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