[R-sig-Geo] extracting non-NA values from RasterLayer

2012-04-25 Thread Carson Farmer
Dear list, I am currently dealing with extremely large raster datasets
(100s of millions of cells), and am masking out large regions which
are of no particular interest for our current project. This produces
RasterLayers with a large number of NAs (but still millions of non-NA
cells as well). What I'd like to do is extract all non-NA values into
a vector for use in various statistical analyses, but I am having
trouble finding the most efficient means of doing so. Any pointers? I
have tried sampleRandom, which is supposed to only take non-NA
cells, but there must be a better/faster way to extract *all* non-NA
values that I've just missed.

Cheers,

Carson

-- 
Dr. Carson J. Q. Farmer
Centre for GeoInformatics (CGI)
School of Geography and Geosciences
Irvine Building, University of St Andrews
St Andrews, Fife, KY16 9AL
Scotland, UK

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] extracting non-NA values from RasterLayer

2012-04-25 Thread Rafael Wüest
Hi Carson,

check ?rasterToPoints from raster package. That should do it!

Rafi

On 25.04.2012, at 12:26, Carson Farmer wrote:

 Dear list, I am currently dealing with extremely large raster datasets
 (100s of millions of cells), and am masking out large regions which
 are of no particular interest for our current project. This produces
 RasterLayers with a large number of NAs (but still millions of non-NA
 cells as well). What I'd like to do is extract all non-NA values into
 a vector for use in various statistical analyses, but I am having
 trouble finding the most efficient means of doing so. Any pointers? I
 have tried sampleRandom, which is supposed to only take non-NA
 cells, but there must be a better/faster way to extract *all* non-NA
 values that I've just missed.
 
 Cheers,
 
 Carson
 
 -- 
 Dr. Carson J. Q. Farmer
 Centre for GeoInformatics (CGI)
 School of Geography and Geosciences
 Irvine Building, University of St Andrews
 St Andrews, Fife, KY16 9AL
 Scotland, UK
 
 ___
 R-sig-Geo mailing list
 R-sig-Geo@r-project.org
 https://stat.ethz.ch/mailman/listinfo/r-sig-geo



--
Rafael Wüest
Swiss Federal Research Institute WSL
Zürcherstrasse 111
8903 Birmensdorf
Switzerland

+41 44 7392126
rafael.wue...@wsl.ch
http://www.wsl.ch/info/mitarbeitende/wueest

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


[R-sig-Geo] averaging home range contours

2012-04-25 Thread Melanie Shapiera
Hello all

I am trying to run some Monte Carlo simulations on single individuals in R.

So far, I have sampled 100 X and Y coordinates from known positions of an
individual, 100 times. This results in a list of 200. I then convert this
list into a dataframe that is more condusive to eventual functions I want
to run for each sample (kernel.area,kernelUD).
So I had a data frame with 200 columns, and I wanted to perform the
kernel.area function (adehabitatHR), using each successive pair of columns
(which represent a resampling). I ended up writing a loop that allows me to
calculate the kernel.area for each of the simulations, as well as the 95%
volume contour, which is saved as a Spatial Polygon.

I now want to take the average of these 95% volume contours, to get an
average 95% volume contour that I can view in Arc. However, I am unsure how
to do this. Any advice would be greatly appreciated!
I can't replicate my data very well here, so I'll give an example of what
the structure is:

# generate dataframe representing X and Y positions
df - data.frame(x=seq(1:200),y=seq(1:200))
# 100 replications of sampling 100 positions
resamp - replicate(100,df[sample(nrow(df),100),])
# convert to data frame (kernel.area needs an xy dataframe)
dfnew - do.call(rbind, resamp[1:2,])
# xy positions need to be in columns for kernel.area
df2 - t(dfnew)

Ok, here is the for loop I've been using for my actual positions:

#calculate the 50,95% kernel area for each simulation, as well as the 95%
volume contour

for (j in seq(1,ncol(df2)-1,2)) {
kud -kernelUD(SpatialPoints(df2[,j:(j+1)]),kern=bivnorm)
kernAr-kernel.area(kud,percent=c(50,95),unin=c(m),unout=c(km2))
print(kernAr)
name[[j]]-getverticeshr(kud, lev = 95)
}
Again, the next step I wish to take is to average the hundred 95% contours
I have created (ie name[[1]],name[[3]]...). Any suggestions?
Melanie
-- 
Melanie Shapiera
MSc candidate
Memorial University of Newfoundland

[[alternative HTML version deleted]]

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


[R-sig-Geo] Overlaying maps

2012-04-25 Thread mas.cyrille2

Dear all,



I am a botanist and I need some assistance for overlaying maps under R. I have 
an altimetric file for Madagascar in .gri. This file come from 
http://www.diva-gis.org/gdata (and the original data seem to have been edited 
by CGIAR STRM). I realize a plot of this file and I’m overlaying an Arview 
file (bioclimate 5) in .shp (polygon) but I don’t know his specific features. 
Finally I’m overlaying my sheet herbarium geographical localities points. My 
final map don’t have any problems in a global points of view (figure 1). 
Problems come when 1) I would a more detailed part of this final map or 2) I 
wish to modify the size of the final plot (figure 2). For the detailed plot : 
the files are not correctly superposed and numerous pixels of the .gri file are 
outside of the limits of the polygons of the .shp file. For the modified size 
of the final plot : the .gri file not change his conformation but the .shp file 
and the distance between my sheet herbarium geographical localities points are 
proportionally modified with the draw of the plot. Is it a problem with the 
geographical projections ? Who know how to do have a good overlaying between 
.gri file and .shp file for the removal of my problems ?



As an advance, thank you for your responses,



Cyrille MAS 







My code is :



# display the bioclimate 5 file

library(maptools)

SHP=E:/Bioclimate 5/bc5.shp

bc5

plot(bc5,xlim=c(44,50),ylim=c(-26,-12),cex.axis=0.6,cex.names=0.6,axis.lty=0,xlab=Longitude,

ylab=Latitude,axes=TRUE,border=black,col=white)



# display the altimetric file 

require(raster) 

alt 

str(alt) 

plot(alt,cex.axis=0.6,cex.names=0.6,axis.lty=0,xlab=Longitude (en 
°E),ylab=Latitude (en °S),axes=TRUE) 



# overlaying the bioclimate 5 file upon the altimetric file

plot(bc5,add=TRUE)



# apply of my sheet herbarium geographical localities data

library(dismo)

data
[[alternative HTML version deleted]]

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] Overlaying maps

2012-04-25 Thread Raphael Saldanha
Hi Cyrille,

This can be something linked to the projection of your files. All
geographical data have a projection, and, for a correct overlaying,
the projection should be informed to the software (ArcView, ArcGIS, R,
etc), and will be better if all the data have the same projection. Can
you inform us the projection of your files?

On Wed, Apr 25, 2012 at 11:05 AM, mas.cyrille2 mas.cyril...@wanadoo.fr wrote:


 Dear all,



 I am a botanist and I need some assistance for overlaying maps under R. I 
 have an altimetric file for Madagascar in .gri. This file come from 
 http://www.diva-gis.org/gdata (and the original data seem to have been edited 
 by CGIAR STRM). I realize a plot of this file and I’m overlaying an Arview 
 file (bioclimate 5) in .shp (polygon) but I don’t know his specific features. 
 Finally I’m overlaying my sheet herbarium geographical localities points. My 
 final map don’t have any problems in a global points of view (figure 1). 
 Problems come when 1) I would a more detailed part of this final map or 2) I 
 wish to modify the size of the final plot (figure 2). For the detailed plot : 
 the files are not correctly superposed and numerous pixels of the .gri file 
 are outside of the limits of the polygons of the .shp file. For the modified 
 size of the final plot : the .gri file not change his conformation but the 
 .shp file and the distance between my sheet herbarium geographical localities 
 points are proportionally modified with the draw of the plot. Is it a problem 
 with the geographical projections ? Who know how to do have a good overlaying 
 between .gri file and .shp file for the removal of my problems ?



 As an advance, thank you for your responses,



 Cyrille MAS







 My code is :



 # display the bioclimate 5 file

 library(maptools)

 SHP=E:/Bioclimate 5/bc5.shp

 bc5

 plot(bc5,xlim=c(44,50),ylim=c(-26,-12),cex.axis=0.6,cex.names=0.6,axis.lty=0,xlab=Longitude,

 ylab=Latitude,axes=TRUE,border=black,col=white)



 # display the altimetric file

 require(raster)

 alt

 str(alt)

 plot(alt,cex.axis=0.6,cex.names=0.6,axis.lty=0,xlab=Longitude (en 
 °E),ylab=Latitude (en °S),axes=TRUE)



 # overlaying the bioclimate 5 file upon the altimetric file

 plot(bc5,add=TRUE)



 # apply of my sheet herbarium geographical localities data

 library(dismo)

 data
        [[alternative HTML version deleted]]


 ___
 R-sig-Geo mailing list
 R-sig-Geo@r-project.org
 https://stat.ethz.ch/mailman/listinfo/r-sig-geo




--
Atenciosamente,

Raphael Saldanha
saldanha.plan...@gmail.com

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] earth Package question for running a loop

2012-04-25 Thread Brooke, J.

--

De informatie opgenomen in dit bericht kan vertrouwelijk zijn en is
uitsluitend bestemd voor de geadresseerde. Indien u dit bericht onterecht
ontvangt, wordt u verzocht de inhoud niet te gebruiken en de afzender direct
te informeren door het bericht te retourneren. Het Universitair Medisch
Centrum Utrecht is een publiekrechtelijke rechtspersoon in de zin van de W.H.W.
(Wet Hoger Onderwijs en Wetenschappelijk Onderzoek) en staat geregistreerd bij
de Kamer van Koophandel voor Midden-Nederland onder nr. 30244197.

Denk s.v.p aan het milieu voor u deze e-mail afdrukt.

--

This message may contain confidential information and is...{{dropped:12}}

___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] semi-transparent mapping - overlapping areas

2012-04-25 Thread Juta Kawalerowicz
Dear Roger and Roman, 

Thanks for answering, with your kind help  I compiled the maps I wanted.

Best wishes, 
Juta

From: Roger Bivand [roger.biv...@nhh.no]
Sent: 25 April 2012 11:34
To: Roman Luštrik
Cc: Juta Kawalerowicz; r-sig-geo [r-sig-geo@r-project.org]
Subject: Re: [R-sig-Geo] semi-transparent mapping - overlapping areas

On Wed, 25 Apr 2012, Roman Luštrik wrote:

 You could use the alpha argument to set transparency to each color. The
 overlaying colors should have a mixture of both. For example, see the
 bottom two images (http://had.co.nz/ggplot2/geom_histogram.html) of how
 alpha mixing works. Lattice graphics also have an alpha argument.


Right. In base graphics:

library(maptools)
set.seed(1)
xx - readShapeSpatial(system.file(shapes/sids.shp,
  package=maptools)[1], proj4string=CRS(+proj=longlat))
xx$reds - 1
is.na(xx$reds) - sample(1:100, 50)
xx$blues - 1
is.na(xx$blues) - sample(1:100, 50)
plot(xx, col=grey80, border=transparent)
plot(xx, col=ifelse(is.na(xx$reds), transparent, red),
  border=transparent, add=TRUE)
plot(xx, col=ifelse(is.na(xx$blues), transparent,
  rgb(red=0, green=0, blue=1, alpha=0.5)), border=transparent,
  add=TRUE)

with rather too brutal red/blue colours.

Roger


 Cheers,
 Roman


 On Wed, Apr 25, 2012 at 12:13 PM, Juta Kawalerowicz 
 juta.kawalerow...@stx.ox.ac.uk wrote:

 Hi,



 Does anyone know how to create mapping of attribute A and attribute B so
 that the overlapping areas are not colour A or B but the mixture of the two
 (the semi-transparent effect). In case that does not sound clear, I am
 looking for this kind of effect



 http://tinyurl.com/cko7c4b created by Divid McCandless (probably not
 using R?)



 If anyone knows a function/package which could allows to do something like
 this, I would be very gretful for suggestions.



 Cheers,

 Juta

[[alternative HTML version deleted]]

 ___
 R-sig-Geo mailing list
 R-sig-Geo@r-project.org
 https://stat.ethz.ch/mailman/listinfo/r-sig-geo






--
Roger Bivand
Department of Economics, NHH Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: roger.biv...@nhh.no
___
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo