Gregory Duveiller | 26 Jan 16:19 2015
Picon

Unexpected behaviour of "area" slot in sp Polygons

Dear All,

I noticed something unusual when trying to get the areas of some polygons I
extracted from a raster.

In the script below, I generate a random raster with 4 classes, which I
then turn to a "SpatialPolygonsDataFrame". I then try to calculate areas
per class in two different ways.

########

require(sp)
require(raster)
require(rgeos)

nrows=100; ncols=100

rdum<-raster(nrows=nrows,ncols=ncols,xmn=0,ymn=0,ymx=100,xmx=100)
rdum[]<-round(runif(nrows*ncols,1,4))

vdum <- rasterToPolygons(rdum,dissolve=T)

# calculate areas
df <- data.frame(cls=1:4)
for(i in 1:4){
  ddd <- sapply(vdum <at> polygons[[i]] <at> Polygons, function(x) x <at> area)
  df$area1[i] <- sum(ddd)
  df$area2[i] <- sum(as.vector(rdum==i))
}
#########
(Continue reading)

Vanessa Machault | 26 Jan 12:17 2015
Picon

Raster package - Focal sum in circles

Hi,
I have a question regarding the package "raster" and the function "focal".
I have a raster with 0.5m pixels and I would like to calculate the sum of all pixels in 50m radius circles, with
a moving window.I have some NA values and I need to ignore them in the calculation.
Then, I would create a new raster where all the pixels that are not NA would be filled with the sum value.
I tried with "focal" and "focal weight" but nothing comes close to the result.Example :fw <-
focalWeight(x, 50, type='circle')
p_focal<-focal(x, w=fw,fun=sum , na.rm=TRUE)
I saw that several way of writing those focal stats may lead to different computation times. Here, as I need
to repeat the process for a large number of rasters, computation time may be an issue.
I thank you very much in advance for your help.Regards,Vanessa Machault

	[[alternative HTML version deleted]]
Bede-Fazekas Ákos | 25 Jan 13:49 2015
Picon

regression kriging with singular variogram

Dear All,
I have a simple question about regression kriging (gstat:::krige()) and
variogram fitting (gstat:::fit.variogram()), which I have not found exact
answer for (neither in the description of package gstat, nor on the
internet). Does it cause any problem if I do regression kriging with a
fitted variogram (eg. a spherical or exponential type) that is singular (ie.
I got a message 'warning: singular model in variogram fit') but shows a
curve in plot(experimental_variogram, fitted_variogram) that is expected
(ie. it fits nicely to the points and has a shape as drawn in the books)?

A bonus question: is the message 'warning: singular model in variogram fit'
a warning or a simple message? I tried to use
fitted_variogram <- suppressWarnings(fit.variogram(...))
and
fitted_variogram <- suppressMessages(fit.variogram(...))
but none of them hides the message. Please let me know how to hide it.

Thanks in advance,
Ákos Bede-Fazekas
Corvinus University of Budapest
Hungary
Anna-Marie Corman | 25 Jan 09:17 2015
Picon
Picon

fpt function in adehbaitatLT

Dear list,

does anybody have experiences with the fpt function in the 
adehabitatLT-package? I want to calculate first-passage time for several 
seabird individuals just to divide my foraging trips into commuting and 
real foraging localizations.
Is it possible to run this function for each individual or do I have to 
do it for each trip separately?

Thanks a lot for any comment on that.

Best wishes,
Anna
Bronwyn Hradsky | 25 Jan 01:43 2015
Picon
Picon

Rediscretising trajectories in adehabitatLT

Dear list members,

Do you know how to prevent redisltraj (type = "time") in adehabitatLT
(version 0.3.16) from removing the last location from each burst when
rediscretising?  I noticed this with my data and also in the example
provided in the help file.

I would like to rediscretise within specific bursts and then bind the bursts
back together, so I don't want to lose the final location from each burst. 

Is there some way of preventing this?

e.g. I have GPS fixes at 30 min intervals with some fixes missing.  For one
burst, the final fix was successful and occurred at  2014-05-17 17:00:00.  I
rediscretise using

> vulpes.added <- redisltraj(vulpes.chop, 1800, type = "time")

which works well in terms of interpolating the missing fixes.  However, the
final fix for the burst is now 2014-05-17 16:30:00

Many thanks,

Bronwyn 

	[[alternative HTML version deleted]]
Milan Cisty | 24 Jan 20:22 2015
Picon

gIntersection - Input geom 0 is invalid

Dear list members.
I tried intersection of two SpatialPolygonsDataFrames and I get following
error:
 > podnyDruh=gIntersection(textura, zavlahaJTSK)
Error in RGEOSBinTopoFunc(spgeom1, spgeom2, byid, id, drop_not_poly,
"rgeos_intersection") : 
  TopologyException: Input geom 0 is invalid: Self-intersection at or near
point -536834.52051807998 -1210383.10809479 at -536834.52051807998
-1210383.10809479
I believe, that there is refered error in data (in geom 0), but I would like to
ask if there is not possible some workaround this (I want to do more
intersections). When I made shp files it was possible to accomplish
intersection in ArcGIS, so maybe there is some trick how to accomplish it also
in R. Referred error in geom 0 is not in area of my interest.
I am not sending data because I do not think its necessary, but I can if it
could help.
Thanks,
Milan
Ferra Xu via R-sig-Geo | 23 Jan 19:00 2015

How to show the color bar legend in R?

Based on the dataset, I computed a 3D kernel (longitude, latitude, depth) and displayed the magnitude with
the sphere radius and time with color as follows. I am wondering how I can show the color bar legend. 

Also I have problem with the scale of the graph. I need to see if the balls touch or overlap each other from the
graph but since the scales are not real I cannot recognize it. How can I correct it? 

library(ks) 
x <- read.csv("HK1.csv") 
y <- x[,1:3] 
fhat1 <- kde(x=y) 
n <- nrow(x) 
col <- grey((n:1)/n) 
plot(fhat1, xlim=c(0,500), ylim=c(0,250), zlim=c(0, 4.4)) 
spheres3d(y, radius=15*(x$magnitude), alpha=1, col= col) 

I tried this code (which didn't work): 

legend_image <- as.raster(matrix(grey((n:1)/n), ncol=1)) 
plot(c(0,2),c(0,200),type = 'n', axes = F, xlab = '', ylab = '', main =  'time scale') 
text(x=1.5, y = seq(0,200,l=5), labels = seq(0,200,l=5)) 
rasterImage(legend_image, 0, 0, 1, 1) 

And this one in "plotrix" package: 

testcol<- col 
col.labels<- seq(0,200, l=5) 
color.legend(600, 0, 601,200,col.labels,testcol,gradient="y") 

But it gives me this error: 

(Continue reading)

A. John Woodill | 22 Jan 19:01 2015
Picon

Spacial plotting of appt

Greetings r-sig-geo!

I have a large dataset that contains multiple observations for various fips
codes located in the central portion of the United States.  Within this
data set, I have merged lat/long coordinates to zip codes and have plotted
the results of average precipitation (appt) on a map using ggplot2.  I have
been playing with various ways of plotting to provide the most visually
appealing method for displaying the data in the most telling way.  However,
I'm not sure if I'm using the correct methods and am looking for assistance
in other ways to plot the data.  In particular, I'm looking for a gradient
effect to show where the highest levels of precipitation were.  I
appreciate any help and direction you can provide.

Here is what I'm trying to achieve (although I know it's a raster object) :
http://nrelscience.org/2013/05/30/this-is-how-i-did-it-mapping-in-r-with-ggplot2/

This is a small subset of my dataset and I'm posting a link because the
dput is too large.

Data set : https://www.dropbox.com/s/0evuvrlm49ab9up/PRISM_1895_db.csv?dl=0

Code :

PRISM_1895_db <- read.csv("/.../PRISM_1895_db.csv")

regions<- c("north dakota","south
dakota","nebraska","kansas","oklahoma","texas","minnesota","iowa","missouri","arkansas",
"illinois", "indiana", "wisconsin")

# Using geom_plot
(Continue reading)

Maurizio Marchi | 22 Jan 14:40 2015
Picon

Raster format and compression

Hello everybody.
I need help with writeRaster function of raster package. I downloaded
WorldClim rasters with 30 second of spatial resolution and I need to change
the projection from WGS84 to ETR89-LAEA. I used projectRaster function and
everything goes fine but when I write the raster map in .tif format, the
same of the input file, the result is much heavier than the first one
(approximately 200 MB versus 45 MB). Is there a particular option of
writeRaster function that I'm missing? Maybe the possibility to compress
the final raster? And which compression should be used?

Many thanks

--

-- 
Maurizio Marchi
Calenzano (FI) - Italy
ID Skype: maurizioxyz
Ubuntu 14.04 LTS
linux user 552742

	[[alternative HTML version deleted]]
Picon

error in splm()

Dear list:

I'm new in spatial panel data. I try to do a simple model but I have the following error in splm library.
Please, could you help me?

Best,

Gema

*****************************************************************************
## Read the data
library(splm)
library("spdep")
madrid     #my data: 10 years, 179 municipalities, 38 variables

> str(madrid)
'data.frame':   1790 obs. of  38 variables:
 $ id                      : Factor w/ 179 levels "Acebeda (La)",..: 1 1 1 1 1 1 1 1 1 1 ...
 $ year                    : num  2000 2001 2002 2003 2004 ...
 $ pop                     : num  57 56 53 55 55 60 59 58 57 61 ...
 $ Extensin..km2.         : num  22.1 22.1 22.1 22.1 22.1 22.1 22.1 22.1 22.1 22.1 ...
 $ Altit                   : num  1269 1269 1269 1269 1269 ...
 $ DistaMadrid             : num  88 88 88 88 88 88 88 88 88 88 ...
 $ longit                  : num  446704 446704 446704 446704 446704 ...
 $ latit                   : num  4549417 4549417 4549417 4549417 4549417 ...
...
...

?fm <- log(nox) ~  log(EEC_pc) +  log(car_1000_ab)

(Continue reading)

Jean-Luc Dupouey | 21 Jan 22:45 2015
Picon
Picon

matching does not work in SpatialPointsDataFrame

I get an incorrect match between row names of coordinates and data in 
SpatialPointsDataFrame:

 > Mycoord <- data.frame(row.names=letters[1:5], x=rnorm(5), y=rnorm(5))
 >
 > Mycoord
             x          y
a -0.80138451  1.9291882
b -1.58229979 -0.7713053
c -1.28416923  1.3324122
d -0.22558639  0.7320874
e -0.08702876  1.7635046
 >
 > Myattr <- data.frame(row.names=sample(letters[1:5]),var1=rnorm(5))
 >
 > Myattr
         var1
d  1.2935138
c  0.1143173
a -0.2157230
b -1.9424786
e -0.7234636
 >
 > MyptsdataT <- SpatialPointsDataFrame(Mycoord, Myattr, match.ID=TRUE)
 >
 > MyptsdataT
               coordinates       var1
d  (-0.8013845, 1.929188)  1.2935138
c   (-1.5823, -0.7713053)  0.1143173
a   (-1.284169, 1.332412) -0.2157230
(Continue reading)


Gmane