Search code examples
rgisrasterscientific-notation

R: get number output from density()


I am using R for GIS applications with spatstat and related packages. I would like to generate a kernel density raster, which I have already succeeded in doing using the following:

spatialgrid <- as(density(mypattern,5000,eps=50),'SpatialGridDataFrame')
rastergrid <- raster(spatialgrid)
writeRaster(rastergrid, filename=‘/file.tif’,format=‘GTiff’)

However, when I load the resulting raster into QGIS I have issues due to the fact that the cell values are written in scientific notation, rather than as simple numbers.

Based on this question, I tried format(density(),scientific=FALSE) but that caused a heavy spike in CPU and took a very long time to run, such that I eventually killed the process.

I'd like to find a way to get the density() function to output integer values. Alternatively, perhaps there is a way to convert the dataframe to integer data type?


Solution

  • I see two options here.

    1. You could use the options(scipen=99) to remove scientific notation, as suggested by @dash2.
    2. Multiply your values by a factor, for example 1000. Try something until your values aren't in scientific notation anymore. The advantage is that your raster won't have as many leading zeroes as option 1 and will take less hard drive space, but the disadvantage is that you have to multiply your values by that factor in QGIS.