Re: [R-sig-Geo] Calculating areas on Earth’s surface

2011-08-19 Thread Robert Hijmans
Dear Karl, For the area of a spherical polygon, you could do library(geosphere) areaPolygon(xy) I do not know how accurate this is relative to your alternative approaches. Robert Calculating areas on Earth’s surface I’m interested in the distortion in apparent area from various

Re: [R-sig-Geo] Transparency of Raster* objects

2011-07-29 Thread Robert Hijmans
Pierre, The trick is I'm using RColorBrewer, who does not provides this posibility. No, but the alpha argument to plot (with a Raster* object) does: r - raster(system.file(external/test.grd, package=raster)) library(RColorBrewer) col - brewer.pal(9, 'GnBu') plot(r, col=col, alpha=0.3)

Re: [R-sig-Geo] replace NA value error

2011-07-29 Thread Robert Hijmans
I'm trying to replace NA value with 0. But the function replace all the value with zero: dem[is.na(dem[])] - 0 Alfredo, that is indeed incorrect; fixed in version 1.9-5. Another way to do this also works in 1.9-2: dem[is.na(dem)] - 0 Thanks, Robert -- View this message in context:

Re: [R-sig-Geo] questions on RasterStack/Brick

2011-07-29 Thread Robert Hijmans
Apologies-- there was an error in the stack correlation function of my last post. Below is an updated version of the function. Thanks Logan, That is very useful, but I would not use stackApply, but the simpler calc. Below a reworked version of your function: stackcor - function(s1, s2,

Re: [R-sig-Geo] extracting time series data from a raster brick of AVHRR satellite data

2011-07-28 Thread Robert Hijmans
, 2011 at 9:23 PM, Robert Hijmans [via R-sig-geo] [hidden email] http://user/SendEmail.jtp?type=nodenode=6629146i=0 wrote: Jan, Any advice? Should I do this via Python or can this be done via R but more efficient? Interesting problem, that I had not noticed before. I think this is because

Re: [R-sig-Geo] Transparency of Raster* objects

2011-07-28 Thread Robert Hijmans
Pierre, There are two ways. You can use the alpha argument in plot, or in a function that generates a vector of colors, see below. But note that this works in the previous and in the next version of raster, but in the current version only with 'oldstyle=TRUE'. From ?slopeAspect

Re: [R-sig-Geo] extracting time series data from a raster brick of AVHRR satellite data

2011-07-27 Thread Robert Hijmans
Jan, Any advice? Should I do this via Python or can this be done via R but more efficient? Interesting problem, that I had not noticed before. I think this is because a loop that can perhaps be omitted or else perhaps needs to move to a C routine. I need to investigate that. For now, for

Re: [R-sig-Geo] crop by pixel

2011-07-27 Thread Robert Hijmans
I need to crop a raster by pixel value, from upper X,Y left. I'm using this: spot - raster(.) x_shift - 2 y_shift - 2 crop(spot,extent(xmin(spot)+res(spot)[1]*x_shift,xmax(spot),ymin(spot),ymax(spot)-res(spot)[2]*y_shift)) It works, but is there another way? A little bit

Re: [R-sig-Geo] crop by pixel

2011-07-27 Thread Robert Hijmans
I need to crop a raster by pixel value, from upper X,Y left. I'm using this: spot - raster(.) x_shift - 2 y_shift - 2 crop(spot,extent(xmin(spot)+res(spot)[1]*x_shift,xmax(spot),ymin(spot),ymax(spot)-res(spot)[2]*y_shift)) It works, but is there another way? A little bit

Re: [R-sig-Geo] empty brick?

2011-07-27 Thread Robert Hijmans
I have a process that creates a set of (large) raster layers. Does it make sense defining an empty brick object and then putting each layer as band of the brick? Or is it better saving each layer and then make the brick? Agus, The simplest is certainly to write single layer raster files

Re: [R-sig-Geo] plot border

2011-07-27 Thread Robert Hijmans
When running the following script, I can plot the image. Does anyone know how I can get the outline/border of the image? Sample data is attached. Muhammad, I have no idea what you mean with how can I get the outline/border of the image?, but perhaps the below helps: library(raster) r

Re: [R-sig-Geo] raster Median function very slow on stack compared to mean: expected behavior?

2011-07-22 Thread Robert Hijmans
I am trying to extract the per-pixel median from a raster stack, and am finding that the process takes a very long time relative to taking the per-pixel mean. It is long enough that I have never actually seen whether it successfully completes on my data, but this dummy example shows the

Re: [R-sig-Geo] subs and the name of column

2011-07-18 Thread Robert Hijmans
I'm trying to use subs function, but I've an error when I use by= with the name of the column. But if I use the column number it work: colnames(data_6SV_cluster) [1] cluster intercept coefficient subs(raster_cluster,data_6SV_cluster,by=cluster,which=2) Error in `[.data.frame`(y, ,

Re: [R-sig-Geo] classify a raster by unique value

2011-07-15 Thread Robert Hijmans
I've a raster stack with 3 layers. I need to classify it assigning one class to each unique combination of values. Perhaps the below works. It may be very slow if unq has many rows. That was not quite right, I think it works when you do: unq - unique(as.matrix(data_stack)) fun -

Re: [R-sig-Geo] plotting geographic coordinates on a map

2011-07-14 Thread Robert Hijmans
I simply would like to plot these on a map of the US. I've tried all sorts of approaches, including map('usa', project='albers', par=c(39,34)) points(x=data$LONGITUDE, y=data$LATITUTUDE, col='red') You are plotting longitude/latitude data on an map with Albers projection. Won't give you

Re: [R-sig-Geo] Long time listener, first time caller

2011-07-14 Thread Robert Hijmans
Lines appear to be a GUI issue, went back to 2.13.0 and plot of raster looks fine. When plotting a Raster* object, raster calls the 'image' function. spplot uses 'levelplot'. Both are affected by these white lines in R 2.13.1 on Windows, I think (anyone seeing this on Mac or Linux? or not

Re: [R-sig-Geo] Search in number sequence

2011-07-12 Thread Robert Hijmans
I have a vector with repeated values like ... I want to search the sequence in this vector. And search should give me the index of matching sequence. If there is not a more direct way to do this, you can perhaps use the movingFun function in raster for this. library(raster) values -

Re: [R-sig-Geo] Mapping contours from jpg map

2011-07-08 Thread Robert Hijmans
I have a jpg map of altitudinal contours in my study area which I would like to map and use in R to calculate the altitude and slope of GPS coordinates. Estimating elevation from contours is not as common as it used to be because of the availability of near-global high resolution raster

Re: [R-sig-Geo] creating a raster using import.asc() nd raster()

2011-07-08 Thread Robert Hijmans
I am converting an .asc object into a raster object in order to use functions from the raster package. I then use the converted file to populate an array called FishModel for the purpose of modeling. In the process the columns and rows seem to be confused Juliane, It is easier to answer

Re: [R-sig-Geo] dismo library: species distribution modelling and obtaining thresholds values

2011-06-27 Thread Robert Hijmans
I am using the dismo library for species distribution modelling using a number of models. I would like to select different threshold levels. The sdm.pdf vignette only gives an example to obtain the Maximum training (or testing) sensitivity plus specificity threshold: e@t[which.max(e@TPR +

Re: [R-sig-Geo] Problem with extent of output raster from crop() function in raster package

2011-06-27 Thread Robert Hijmans
I'm currently having some problems getting the crop() function in the raster package to work properly, and cannot for the life of me figure out what's going on. Essentially, I'm trying to crop a larger raster (raster1) to match one with a smaller extent (raster2), which is entirely

Re: [R-sig-Geo] insert NODATA_value -999.0 into asc file

2011-06-22 Thread Robert Hijmans
have a large number (several thousand) of asci files which were delivered to me without a NODATA_value -999.0 line in the header If all your files are for the same area you could do something like r - raster(ncol=601, nrow=351, xmn=10, xmx=701000, ymax=25, ymn=-101000) filename -

Re: [R-sig-Geo] Raster regression cooeficients plot?

2011-06-16 Thread Robert Hijmans
Hi Eddie, Consider this: set.seed(0) y = runif(365) time = 1:365 m = lm(y~time) m$coefficients (Intercept) time 0.5297172419 -0.0001886475 But you do: summary(m)$coefficients Estimate Std. Error t value Pr(|t|) (Intercept) 0.5297172419 0.0292052249

Re: [R-sig-Geo] Raster regression cooeficients plot?

2011-06-15 Thread Robert Hijmans
I am analysing monthly time series data using rasterbrick. Commands below give me one slope plot fun - function(x) { lm(x ~ time)$coefficients[2] } slope - calc(s, fun) plot(slope) But what other 7 plots means when I run these lines... fun - function(x) { lm(x ~ time)$coefficients }  

Re: [R-sig-Geo] How to calculate slope in rasterbrick

2011-06-15 Thread Robert Hijmans
I have a brick that contains 348 layers. Each layer is small in dimension ncol=69, nrow=43. My question is, how do I calculate slopes for each pixels from layer 1 to layer 348(Month one to months 348). I am trying to find the trend as I am working with time series data. for RasterBrick

Re: [R-sig-Geo] Supervised landscape classification according to NDVI time series

2011-06-15 Thread Robert Hijmans
From what I understood, most landscape classification methods available from GRASS (through R) do not account for the temporaI aspect of spectrum. So for example, if you have a raster where each band represents NDVI values at a given date, from March to September for example, the

Re: [R-sig-Geo] raster::plot() common color scale?

2011-06-10 Thread Robert Hijmans
Is there any way to get a common color scheme (i.e., setting common min and max values)? Here is yet another way: library(raster) foo - raster(nrows=20, ncols=20) values(foo) - runif(400) bar - raster(nrows=20, ncols=20) values(bar) - runif(400) s - stack(foo, bar, foo*2) # first

Re: [R-sig-Geo] converting bounding box to shapefile problem

2011-06-10 Thread Robert Hijmans
Interesting problem You have to decide if you want to create 7 different shapefiles, one for each of your grids and each containing one bounding box polygon, or one shapefile with 7 features. Here is a solution, I think, if you want a single shapefile with all bounding boxes

Re: [R-sig-Geo] writeRaster give error no slot of name file for this object...

2011-06-07 Thread Robert Hijmans
I'm using the raster-package in R. I have problem writing an RasterStack to a multi-band tif-file. Error in attr(x@file, transient) - temp[[1]] : no slot of name file for this object of class RasterStack I believe this is a bug that has been fixed. Can you try again after updating the

Re: [R-sig-Geo] spatial time series

2011-06-06 Thread Robert Hijmans
I have some rasters, respresentig a time series (let's say 5 years and 24 rasters for each year). The rasters are in a raster stack or a SpatialGridDataframe, whatever is better. Now I want to do some time series analysis which call for a ts class object. ... Now what I want to do is to do

Re: [R-sig-Geo] Methodology to compare crop maps

2011-06-03 Thread Robert Hijmans
 I am working with crops planted area maps from two distinct sources. One of the maps is based on a maximum NDVI composition, and the other map uses joint information from satellite and census to estimate the planted area.  Although the sources employ different methodologies to map the area

Re: [R-sig-Geo] multivariate output with predict() on rasterStack

2011-05-26 Thread Robert Hijmans
According to the help file, the predict() function in the raster package creates a RasterLayer. Since a RasterLayer cannot store more than one layer like a RasterStack, I wonder if it is possible to use the predict() functions when the output of the prediction is multivariate? For example

Re: [R-sig-Geo] Performance of raster package

2011-05-24 Thread Robert Hijmans
Thanks for pointing this out. Some functions in 'raster' are indeed slower/faster than others. Some seem to be reasonably quick. The focal* functions are slow, and indeed, as Rainer alludes to, good candidates for a C-implementation of at least the basic cases (e.g. fun=mean). Although I recently

Re: [R-sig-Geo] How to overlay two rasters limiting the spatial domain

2011-05-18 Thread Robert Hijmans
Thiago, You can use the 'crop' function. Best, Robert  Dear R colleagues,  Currently, I am working with the vegetation map published by SAGE (http://www.sage.wisc.edu/download/potveg/global_potveg.html). This map is published in netcdf and I can easily load it into R using the package

Re: [R-sig-Geo] projectRaster error with netcdf

2011-05-13 Thread Robert Hijmans
The second argument in projectRaster is another Raster* object, not a proj.4 string. I expect this problem goes away if you do: x - projectRaster(r, crs=+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs) Robert Having an error in getting library raster to read data from a netcdf file when

Re: [R-sig-Geo] hide legend in plot raster

2011-04-26 Thread Robert Hijmans
I would like to overlay two raster objects to produce a nice map. The underlying raster is a hillshade, the second is transparent. plot(hillshade, col=grey(1:20/20)) plot(soilraster, alpha = 0.7, add = TRUE) Does anybody know, how to hide the legend of the hillshade? In addition to

Re: [R-sig-Geo] get.var.ncdf and embedded scale factors

2011-04-18 Thread Robert Hijmans
I would like to confirm that the get.var.ncdf function within the ncdf package automatically scales output data values if there is an embedded scale factor within the ncdf file. It does and that is easy to infer from the code frament below that you get when typing get.var.ncdf. As you can

Re: [R-sig-Geo] subs (raster) on large dataset

2011-04-14 Thread Robert Hijmans
Lyndon, I have no idea what might be causing this. I would suggest to track down where exactly this happens, by going, line by line, through the code of 'subs' getMethod(subs, c(RasterLayer, data.frame)) Presumably, something is not moving here: for (i in 1:tr$n) { v - getValues(x, row =

Re: [R-sig-Geo] resample{raster}: Error invalid 'y' type in 'x || y'

2011-04-12 Thread Robert Hijmans
I am trying to resample a raster layer to another raster layer (dieffernt resolution, different extent) using the resample function as implemented in the raster package. (...) Interestingly, the same happens when using the example as provided in the package description: (...) s - resample(r,

Re: [R-sig-Geo] Calculating/applying transition matrices from classified imagery?

2011-04-12 Thread Robert Hijmans
Does anyone know of a package (or a suggestion on how to implement) to calculate, for two classified raster images of the same location but different times, the relative probability of transitioning from one class to the other? Additionally, once this is figured out, how to apply this

Re: [R-sig-Geo] Local Moran'I for raster focalFilter

2011-04-12 Thread Robert Hijmans
Dear All, I tried to write a function that can be used in focalFilter of raster package, but the output result is different from what was calculated using spdep for a sample dataset. It might be my mistake in the formula that is used in the function. Following you will find both

Re: [R-sig-Geo] focalFilter problem raster package

2011-04-11 Thread Robert Hijmans
Dear Robert I hope the following example is clear. you should be able to cut and paste... Nick Dear Nick, Thank you for the example. It reveals a serious error in focalFilter. Results with that function in raster versions lower than 1.8-11 are wrong in the first rows (half the number

Re: [R-sig-Geo] Shapefile to raster and crop a raster (error)

2011-04-11 Thread Robert Hijmans
Manuel, bio1ai - crop(bio1, ai) Error in intersectExtent(x, y) : Invalid extent This somewhat cryptic error message means that the extent of y does not overlap with the extent of x. Hence y cannot be used to crop x. extent(bio1) extent(ai) Perhaps this happens because bio1 is in lon/lat

Re: [R-sig-Geo] focalFilter problem raster package

2011-04-04 Thread Robert Hijmans
I am experiencing a strange problem when using the focalFilter function in the raster package. Nick, Could you provide a self-contained example that does not require downloading files? Given your description that should not be very hard. Robert -- View this message in context:

Re: [R-sig-Geo] summarize cells of different value intervals in a raster file by items in ESRI shapefile

2011-04-04 Thread Robert Hijmans
I have a raster file (cell value varies from 0 to 1) and a ESRI shapefile (there are countries, and provinces inside each countries), the two files overlapped in the same region. I want to summarized the cells (with different value intervals, say 0.0-0.25, 0.25-0.5, 0.5-0.75, 0.75-0.1) by

Re: [R-sig-Geo] package raster: issue with extent and stack

2011-03-28 Thread Robert Hijmans
Advait, I encounter two errors; A) when using extent to crop the rasters lims - extent(rcmraster,180,185,300,305) Error in .local(x, ...) : unused argument(s) (180, 185, 300, 305) I also tried using lat-long values in place of the index to no avail. I cannot reproduce the problem.

Re: [R-sig-Geo] extract cell numbers from raster along a line

2011-03-18 Thread Robert Hijmans
I'd like to extract celle numbers from a raster using a line, but it seems the cellnumbers=TRUE option isn't working with lines in raster::extract. Etienne, It is not working because cellnumbers is currently only an argument for extracting values from a Raster* for polygons. That's what the

Re: [R-sig-Geo] Open raster _ extract pixel value

2011-03-13 Thread Robert Hijmans
I tried your suggestion doing this: library(raster) myobject -raster(C:\\Users\\komine\\Desktop\\MODIS\\MYD09GQ.A2010280.h16v07.005.2010282160347.sur_refl_b01_1.tif) e - extent(-90, -32, -60, 15) r -

Re: [R-sig-Geo] package to query Google for latitude and longitude for a given ZIP code

2011-03-08 Thread Robert Hijmans
Hi, I was wondering if someone could direct me to a package that would allow you to query Google (or any other resource) for the latitude and longitude of a ZIP code. You can try the 'geocode' function in the dismo package. geocode('03861') ID lon lat lonminlonmax

Re: [R-sig-Geo] cleaning up a SpatialGridDataFrame

2011-03-07 Thread Robert Hijmans
I have an image which is a SpatialGridDatafFrame. This image has a number of cells that i need to erase or to delete but i don`t know how to do this in R. Mary, It is not clear what you mean with erase or delete. If you refer to setting some cell values to NA you can do, with

Re: [R-sig-Geo] Help on extracting min/max from raster object

2011-03-01 Thread Robert Hijmans
Rahul, I wanted to extract the min value and max value from the object. How can I do this? I have used the following function for this purpose cellStats(r,'min') [1] 0 But it is returning 0, not 0.001407638 The combination of minValue(r) [1] 0.001407638

Re: [R-sig-Geo] overlay raster by polygons: average values

2011-03-01 Thread Robert Hijmans
I've got a SpatialGridDataFrame SG with density values given by spatstat package I want to get the average values of this grid for each polygon of a dataset named iris Mathieu, I think you can do this: library(raster) #make a RasterLayer r - raster(SG) # extract mean values for polygons

Re: [R-sig-Geo] cropping in raster package loses color table?

2011-02-28 Thread Robert Hijmans
Don, The colortable is apparently not preserved when using crop() from the raster package. This is something I would find useful. I agree. Color table support is relatively recent and it is ignored by most functions (and hence lost when using crop). That needs improvement. (also, is there

Re: [R-sig-Geo] Help on slow processing of extract fuction

2011-02-22 Thread Robert Hijmans
I have a classified image of whole India (India measures 3,214 km (1,997 mi) from north to south and 2,993 km (1,860 mi) from east to west) at 56m resolution. I have generate a square grid of type polygon (area of each square polygon in grid is 1sq km) that covers whole India. Now I have

Re: [R-sig-Geo] Error in .GDALnodatavalue(dataformat)

2011-02-22 Thread Robert Hijmans
I am getting the following error when I run aggregate (from the raster package) on a raster image and output to a file. Error in .GDALnodatavalue(dataformat) : cannot find matching nodata value Ned, I think this is something that has been fixed but had not made it to CRAN yet. Could you

Re: [R-sig-Geo] kde output from ks reversed

2011-02-19 Thread Robert Hijmans
Im not sure what the problem is Robert, my previous post included both the code file and my albers coordinates. I will attach them again. Got them now Simulated data doesn't really prove anything to me if you can't apply the results back to the earth. ? really? This seems to work fine.

Re: [R-sig-Geo] kde output from ks reversed

2011-02-19 Thread Robert Hijmans
What are good raster formats and R libraries for dealing with non-square cells? You can use geotiff, as in my example (file.tif). Is this proper use of the hpi values from R? I do not know that How can I effectively get these rasters back to square cells I can see two ways to make the

Re: [R-sig-Geo] kde output from ks reversed

2011-02-18 Thread Robert Hijmans
Im having trouble with the results from the ks package being reversed. There must be a simple error that I am overlooking? Does anybody see my problem Perhaps I could have seen what you are overlooking if you had provided a simple self-contained example. That should be very easy to make in

Re: [R-sig-Geo] kde output from ks reversed

2011-02-18 Thread Robert Hijmans
Here is a self contained sample with a different set of points, same issues though. curset - read.delim(sample.csv, header = TRUE, sep = ,) Thanks for trying, but this is not self-contained, as it refers to a file that only you have. When I use your routines they fail, saying that the

Re: [R-sig-Geo] How to draw grid contours within a map

2011-02-15 Thread Robert Hijmans
In order to illustrate the spatial domain of the General Circulation Model (GCM) output data I am using, I need to display some grids within a map. They need to be 2.5°x2.5° lat-lon over specific coordinates. Following, I create the empty grids to draw: library(raster)

Re: [R-sig-Geo] bug writeRaster to ENVI

2011-02-14 Thread Robert Hijmans
I discovered a strange behaviour of the function writeRaster in ther raster package. Having a *.img or *.tiff file with a projected extend object like this, ... alway causes a wrong projection and associated coordinates when writing to a envi file with the function call: Carsten,

Re: [R-sig-Geo] Rasters average

2011-02-09 Thread Robert Hijmans
I'm trying to use MODIS 1day raster (.tif file) to obtain a, say, weekly raster which is the average of the seven 1 day raster. Using the following code (library raster) I can't obtain the results due to computational limits. Luca, You can do something like: s -

Re: [R-sig-Geo] how to calculate areas of shape files using R

2011-01-31 Thread Robert Hijmans
A small caveat - if the coordinates are planar, the explanation holds, if geographical (degrees), it doesn't. The naive area values have been used internally to plot larger Polygon objects before smaller Polygon objects, to avoid overplotting in earlier versions of R that did not identify

Re: [R-sig-Geo] ECMWF grib and raster

2011-01-26 Thread Robert Hijmans
I'm trying to read grib files using Raster, form the ECMWF interim dataset (example file linked below). I don't get errors but the coordinate system of the read raster does not seem to match. Bart, I think this is due to an instance of the grid vs. cell-center convention mistake in gdal,

Re: [R-sig-Geo] Learning raster

2011-01-25 Thread Robert Hijmans
Steve, But now I don' see an approach to subsetting this on the temporal domain. Does raster support this kind of analysis? x - subset(ss, 2:10) x - ss[[2:10]] But perhaps you do not need to subset, as you can probably use 'stackApply' for your purposes cellStats should be able to handle

Re: [R-sig-Geo] Vectorize and buffer

2011-01-25 Thread Robert Hijmans
I see functions to rasterize in the raster package but nothing to vectorize... and certainly nothing to do buffer around polygons. raster has rasterToPolygons -- but it only works well for smallish rasters (or when few cells have non NA values) because each cell with a value becomes a

Re: [R-sig-Geo] extract function - return the ID of the polygon

2011-01-22 Thread Robert Hijmans
Brian, I would like to know how to also reurn the ID of the polygon when using the 'extract' function to extract raster cell values. The values are returned in the order of the polygons. So the IDs would be 1:n, or in your example, poly$FID. Isn't that enough? I am just extracting and

Re: [R-sig-Geo] Function to smooth grids using n x n window moving average (low-pass filter)

2011-01-19 Thread Robert Hijmans
I was trying to do add the ability to ignore NAs (just like it's in the sum method with na.rm = TRUE). I can't find the way however. You can also compare with the focal functions in raster; that should support NA values library(raster) r = raster(meuse.grid, log.zinc) rf = focal(r, 3)

Re: [R-sig-Geo] RASTER or RGDAL package

2011-01-14 Thread Robert Hijmans
Dear mailing list.. Please give me some information. Which one is best fit for Remote Sensing Data RASTER or RGDAL package??? with Best Regards, I would add that raster builds on rgdal, and so, if you use raster, in most cases it would be raster rgdal, with rgdal providing the basic

Re: [R-sig-Geo] no slot of name data for this object of class RasterStack

2011-01-06 Thread Robert Hijmans
Hi Peter, I think you have made things way too complicated. I would suggest to do something along these lines: library(raster) # first get the filenames. vargroup - c(bio,prec,tmax,tmin,tmean) filenames - list() for (v in vargroup) { filenames - c(filenames,