Frede Aakmann Tøgersen | 21 Oct 13:30 2014

Re: Order raster images in a levelplot

Please remember to post to the list as well since this was there this thread startet.

Dows it have something to do with you not setting the name argument of setZ()?

You are doing:

NDVImodis<-setZ(NDVImodis,d)
names(NDVImodis)<-d

Perhaps you should do:

NDVImodis<-setZ(NDVImodis,d, name = "Months")

And then e.g.

zApply(NDVImodis, by=months, fun=mean, name="Months")

?????

Yours sincerely / Med venlig hilsen

Frede Aakmann Tgersen
Specialist, M.Sc., Ph.D.
Plant Performance & Modeling

Technology & Service Solutions
T +45 9730 5135
M +45 2547 6050
frtog <at> vestas.com<mailto:frtog <at> vestas.com>
http://www.vestas.com<http://www.vestas.com/>
(Continue reading)

Navinder Singh | 21 Oct 12:45 2014
Picon
Picon

Order raster images in a levelplot


Dear Both,
Thank you for your responses.
Oscar- I am still trying to get the indexing going. Hope it will be sorted out soon.
Just to provide some more background on my code- here is an example.

library(raster)
library(rasterVis)
library(raster)
library(rgdal)
library(zoo)

setwd("/Users/nasi/Google Drive/5KMNDVI_Monthly")

modis = stack(list.files(pattern='NDVI.tif'))
modis
names(modis)
d<-seq(as.Date("2010-01-01"),as.Date("2014-08-01"),by="month")
names(modis)<-d
NDVImod<-setZ(modis,d)
e<-extent(-17.96, 43.135, -30.055, 67.08)
NDVImodis<-crop(NDVImod,e)
NDVImodis[NDVImodis<0]<-0
NDVImodis<-setZ(NDVImodis,d)
names(NDVImodis)<-d

# The first problem occurs below. I am trying to get monthly means and other quantities. Although the
function does give me an output, but the results are completely wrong. As it seems to be averaging the wrong
months together. Can’t really paste the image here i suppose.

(Continue reading)

Jue Lin-Ye | 21 Oct 12:17 2014
Picon

pieSP: non-finite coordinates

Greetings!

I am working with the following code. I am having an error called
"non-finite coordinates". May you tell me what does it exactly mean and how
to fix it?

On the other hand, I see that my original percentages in "pie.chart" is
changed when converting to "pies" (I have written them both in boldface).
Why does this happen and how can I fix it?

Thank you in advance!

>* pie.chart*
        wana long   lat prob1 prob2 prob3 prob4

*[1,] 2125149 3.42 42.42   106  5292  5198     0[2,] 2125147 3.42 42.25
15  4241  5205     0*
> pie.chart<-data.frame(pie.chart)
> coordinates(pie.chart)<-~long+lat
> proj4string(pie.chart) <-llCRS
> pie.chart
class       : SpatialPointsDataFrame
features    : 2
extent      : 3.42, 3.42, 42.25, 42.42  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +ellps=WGS84
variables   : 5
names       :    wana, prob1, prob2, prob3, prob4
min values  : 2125147,    15,  4241,  5198,     0
max values  : 2125149,   106,  5292,  5205,     0
>
(Continue reading)

Jianhua Huang | 21 Oct 08:40 2014
Picon

weird ncdf4 output 9.969210e+36

Hi All:

I am trying to create a 3 dimensional (200*200*8760) netCdf file using the
ncdf4 package. Everything goes fine, except some unexpected outputs. Here is
tail of the result in one grid cell. I cbind the original values and the
output read from the nc file. 

        Original   ncdf4

[8755,] 70.47247 7.047247e+01

[8756,] 47.10336 4.710336e+01

[8757,] 38.70509 3.870509e+01

[8758,] 32.86281 3.286281e+01

[8759,] 21.90854 9.969210e+36

[8760,] 10.95427 9.969210e+36

Most ncdf4 data matches with the original data, except the last two values.
There are extremely large values: 9.969210e+36

I have no idea where these huge values come from, and can't figure out where
is wrong at all.

Any one met the same problem before? Thanks for any suggestion, and I really
appreciate any help.

(Continue reading)

alannie | 20 Oct 20:21 2014
Picon

Error In proj4string

Hi list!

I have been trying to run some code that I have run tons of times before,
only to get a warning message:

##add in ASCII raster maps bio1-11
> bio1 <- readGDAL("bio1.asc") 
bio1.asc has GDAL driver AAIGrid 
and has 1486 rows and 1347 columns
> bio2 <- readGDAL("bio2.asc") 
bio2.asc has GDAL driver AAIGrid 
and has 1486 rows and 1347 columns
> bio3 <- readGDAL("bio3.asc") 
bio3.asc has GDAL driver AAIGrid 
and has 1486 rows and 1347 columns
> bio4 <- readGDAL("bio4.asc") 
bio4.asc has GDAL driver AAIGrid 
and has 1486 rows and 1347 columns
> bio5 <- readGDAL("bio5.asc") 
bio5.asc has GDAL driver AAIGrid 
and has 1486 rows and 1347 columns
> bio6 <- readGDAL("bio6.asc")
bio6.asc has GDAL driver AAIGrid 
and has 1486 rows and 1347 columns
> bio7 <- readGDAL("bio7.asc")  
bio7.asc has GDAL driver AAIGrid 
and has 1486 rows and 1347 columns
> bio8 <- readGDAL("bio8.asc")
bio8.asc has GDAL driver AAIGrid 
and has 1486 rows and 1347 columns
(Continue reading)

Navinder Singh | 18 Oct 01:49 2014
Picon
Picon

Order raster images in a levelplot

Hi,
Two questions.

1. Does someone have any suggestions on how i can order the sequence of images in a levelplot" made using rasterVis.
Specifically, i have months i need to arrange in the normal sequence, as the plot currently aligns them in an
alphabetical order. Does levelplot works the same way as xyplots in lattice?

2. Have there been more developments on the zApply function in the raster package? I am trying to make basic
statistical summaries for mean monthly (eg. NDVI values) form a multi annual time series.
How does one go about using the by" Indexing in this case.

Thanks,

Navinder J Singh
Associate Professor
Department of Wildlife, Fish, and Environmental Studies
Faculty of Forest Sciences
Swedish University of Agricultural Sciences
SE-901 83 Umea, Sweden
O: +46 (0)90 786 8538;
M: +46 (0)70 676 0103
email: navinder.singh <at> slu.se<mailto:navinder.singh <at> slu.se>
Web: navinderjsingh.weebly.com<http://navinderjsingh.weebly.com/>

	[[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
(Continue reading)

Nicolas Meurisse | 20 Oct 06:03 2014

sample with varying intensity according to local density

Hi all,

I want to sample locations within a defined area, but also optimize the spatial arrangement of my sample
locations in order to:

1.       sample some parts of the area more intensively (e.g. as a function of previous findings intensity, as it
could be illustrated by a density map)

2.       sample at regular intervals within each area, as opposed to pure random sampling (e.g. "regular" or
"stratified random" as defined in sp package)

Here an example dataset:
n <- 10000
x1  <- matrix(rnorm(n), ncol = 2)
x2  <- matrix(rnorm(n, mean = 3, sd = 1.5), ncol = 2)
x   <- rbind(x1, x2)
# scatterplot with smoothed densities color representation
smoothScatter(x)
# random sampling (not appropriate, as we want an arrangement that optimizes conditions 1 and 2)
points(sample(x[,1],20), sample(x[,2],20), col="red", pch=16)

I would greatly appreciate any insight someone might have as it seems there are lot of potential
applications using  such "stratified" sampling.

Many thanks !

Nicolas

________________________________

(Continue reading)

kirsty fulton | 17 Oct 15:01 2014
Picon

Multiple legends with levelplot and spplot

I am trying to overlay two shapefiles on a raster grid. The raster is a digital elevation model. The first
shapefile is a polygon, which shows the outline of a country, and the second shapefile is a polyline, which
represents rivers. I am currently using levelplot to plot the raster and spplot to overlay the polyline
and polygon. The polyline is coloured according to the attribute table using the STATUS column - this
plots "perennial" status as blue and "ephemeral" status as orange. My code is shown below. This produces a
plot with a colorkey for the raster, but I can't work out how to add a key for the polyline. Apologies if this
is very obvious but I can't seem to find an answer on any existing threads.
Any help would be much appreciated. 

The code is as follows:
# Read rasterdata_location_DEM1 <- "E:/AGA_ProcessDatasets/DEM_Data/gt30e020n40.tif"iDEM <- raster(data_location_DEM1)
# Read shapefilesioutlineCountry <- readOGR(dsn = "E:/AGA_ProcessDatasets", layer =
"UNAfricanCountries_Final_Buffer100m")proj4string(ioutlineCountry) <- CRS("+proj=longlat
+datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0")
irivers <- readOGR(dsn = "E:/AGA_ProcessDatasets/Hydrology_Data", layer =
"Rivers_Africa_37333_ForPlotting_Split")proj4string(irivers) <- CRS("+proj=longlat
+datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0")
# define colours for riversrivercolours <- c("orange","blue")
# define colours for DEMcols <- gray.colors(128,start=1,end=0)
# define extents for plottingplotmin <- cellStats(iDEM,stat='min')plotmax <-
cellStats(iDEM,stat='max')breaks <- (plotmax - plotmin)/128legendbreaks <- round((plotmax -
plotmin)/5,0)scale <- seq(plotmin, plotmax, by=breaks)xmin <- iDEM <at> extent <at> xminxmax <-
iDEM <at> extent <at> xmaxymin <- iDEM <at> extent <at> yminymax <- iDEM <at> extent <at> ymax
# define output png filefilenamePre = paste(iCountryName,"_Hydrology2.png",sep="")png(filename="Hydrology.png",width=1000,height=486,units="px")
# plot dataa<-levelplot(iDEM,margin=FALSE,xlab="",ylab="",at=scale,col.regions=cols,            
colorkey=list(space="right",width=0.75,height=0.75)) +  
spplot(irivers,zcol="STATUS",col.regions=rivercolours) +  
spplot(ioutlineCountry,zcol="NAME_0",fill="transparent",col="black") # add title to legend
a$legend$right <-   list(fun = mergedTrellisLegendGrob(a$legend$right,list(fun = textGrob,args =
list("maSL",rot = 0)),vertical = FALSE))
(Continue reading)

marcel Austenfeld | 17 Oct 10:54 2014
Picon

RasterStack on file disk

Hello,

i would like to develop an action to store a RasterStack on file disk instead of memory.
The images are transferred from a stack or virtual stack from ImageJ in different types.

For a stack of RGB images the images are split into three integer matrices and added to a RasterStack:

rasterStackFromIJ<-stack()

..........
imageMatrix<-.....from ImageJ.....

r<-matrix(imageMatrix[,1],nrow=xxx, ncol=yyy)
rasterStackFromIJ <- stack(rasterStackFromIJ,raster(r))

g<-matrix(imageMatrix[,2],nrow=xxx, ncol=yyy)
rasterStackFromIJ <- stack(rasterStackFromIJ,raster(g))

b<-matrix(imageMatrix[,3],nrow=xxx, ncol=yyy)
rasterStackFromIJ <- stack(rasterStackFromIJ,raster(b))
......

This works quite well for a bunch of images if enough RAM is available (Created e.g. stack size:
4096:3072:21 from 7 RGB images)

However it would be nice to have an option to store and access the RasterLayer to and from the file disk for
huge stacks.

Is this possible for a RasterLayer?

(Continue reading)

Marcel | 17 Oct 10:43 2014
Picon

RasterStack on file disk

Hello,

i would like to develop an action to store a RasterStack on file disk
instead of memory.

The images are transferred from a stack or virtual stack from ImageJ in
different types.

For a stack of RGB images the images are split into three integer matrices
and added to a RasterStack:

rasterStackFromIJ<-stack()
..........

imageMatrix<-.....from ImageJ.....

r<-matrix(imageMatrix[,1],nrow=xxx, ncol=yyy)
rasterStackFromIJ <- stack(rasterStackFromIJ,raster(r))
g<-matrix(imageMatrix[,2],nrow=xxx, ncol=yyy)
rasterStackFromIJ <- stack(rasterStackFromIJ,raster(g))
b<-matrix(imageMatrix[,3],nrow=xxx, ncol=yyy)
rasterStackFromIJ <- stack(rasterStackFromIJ,raster(b))
......

This works quite well for a bunch of images if enough RAM is available
(Created e.g. stack size: 4096:3072:21 from 7 RGB images)

However it would be nice to have an option to store and access the
RasterLayer to and from the file disk for huge stacks.

(Continue reading)

Leigh Kroeger | 15 Oct 10:33 2014
Picon

Shifting x coordinates by 180

Hello,

I have the following shapefile imported into R:

> summary(grid)
Object of class SpatialPolygonsDataFrame
Coordinates:
         min        max
x -165.73220 -123.23912
y   29.55567   46.44211
Is projected: FALSE
proj4string : [+proj=longlat +ellps=WGS84]

I need to shift 'x' by adding 180 to the data column. I think the 'elide'
function in maptools can accomplish this but the following error comes up
when I start the code:

>coordinates(grid) <- c("x", "y")
Error in `coordinates<-`(`*tmp*`, value = c("x", "y")) :   setting
coordinates cannot be done on Spatial objects, where they have already been
set

My intended outcome is to be able to plot occurrence data from GBIF onto
the polygon shapefile.

Regards,

--

-- 
*Leigh A. Kroeger*
<*)))><
(Continue reading)


Gmane