Skip to content

ecw for rgdal package

9 messages · Alexandre VILLERS, Roger Bivand, Paul Hiemstra +5 more

#
Good afternoon,

I was wondering if the reading and creating of ecw files was planned for 
the rgdal library. I suppose it is a bit tricky to include this function 
because of the need for the ECW SDK library from ER mapper...

Best regards

Alex
#
On Mon, 21 Dec 2009, Alexandre VILLERS wrote:

            
Correct, we cannot distribute this library from CRAN. If you need this 
driver, you have to provide it yourself, on Windows using the instructions 
for the alternative build approach in:

file.show(system.file("README.windows", package="rgdal"))

You will have to improvise a little, as - for example - building R 
packages from source is easier now than it was in 2007.

Hope this helps,

Roger

  
    
#
Dear all,

I have two "nested" grids (SpatialGridDataFrame) looking like this:

prj <- "+proj=utm +zone=28 +ellps=WGS84 +datum=WGS84 +units=m +no_defs"
gt1 <- GridTopology(c(5, 5), c(10, 10), c(100, 100))
gt2 <- GridTopology(c(50, 50), c(100, 100), c(10, 10))
band1 <- sample(c(0, 1), replace = TRUE, size = 10000)
sgdf1 <- SpatialGridDataFrame(gt1, data.frame(band1), CRS(prj))
sgdf2 <- SpatialGridDataFrame(gt2, data.frame(band1=rep(0, 100)), CRS(prj))
## Graphic display
spplot(sgdf1, scales = list(draw = TRUE),
        panel = function(...){
            panel.gridplot(...)
            sp.grid(sgdf2, col = 0)
            })

I want to compute the mean (and other statistics) of sgdf1 at data$band1 
according to the cells defined in sgdf2. How can I do that ? I tried to 
use overlay, without success:

 > sgdf3 <- overlay(sgdf1, sgdf2, fn = mean)
 > sgdf3 at data$band1
   [1] 1 0 0 0 0 0 1 1 1 0 0 1 0 0 0 0 0 1 1 0 1 0 1 1 0 1 0 0 0 0
  [31] 0 0 1 0 1 1 1 0 0 0 0 0 0 1 0 1 1 0 0 0 1 0 1 0 1 0 1 1 0 0
  [61] 1 1 0 1 1 1 1 0 0 0 1 1 0 0 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0
  [91] 1 0 1 1 1 0 1 0 1 0

All the best,

Renaud
#
Hi Renaud,

Take a look at the pointsToRaster() function in the raster package.

cheers,
Paul
Renaud Lancelot wrote:

  
    
#
Hi

I guess you could also try something like:

# First of all
showMethods(overlay)

# Than, one possibility:
ovrl <- overlay(as(sgdf2, "SpatialPixelsDataFrame"), 
		as(sgdf1, "SpatialPointsDataFrame"))

# aggregate by the ovrl index
aggMean <- aggregate(slot(sgdf1, "data"), 
		     by = list(ovrl), 
		     FUN = mean)$band1
# make a new SpatialGridDataFrame:
sgdf3 <- SpatialGridDataFrame(gt2, 
			      data.frame(band1=aggMean), 
			      CRS(prj))

Best wishes
Torleif
On Tuesday 22 December 2009 10:52:50 Paul Hiemstra wrote:
#
Renaud,
Here another way:

library(raster)
r <- raster(sgdf1, 1)
ra <- aggregate(r, 10, mean)
sgdf3 <- as(ra, 'SpatialGridDataFrame')
[1] 0.43 0.45 0.57 0.50 0.49 0.47 0.58 0.50 0.61 0.49 0.49 0.53 0.54
0.51 0.53 0.42 0.48 0.51 0.54 0.53 0.50
 [22] 0.52 0.39 0.52 0.52 0.62 0.53 0.48 0.52 0.48 0.52 0.45 0.50 0.48
0.43 0.47 0.52 0.49 0.43 0.59 0.54 0.52
 [43] 0.53 0.53 0.48 0.57 0.46 0.54 0.49 0.48 0.47 0.48 0.47 0.50 0.48
0.49 0.47 0.45 0.50 0.52 0.54 0.46 0.49
 [64] 0.52 0.54 0.50 0.46 0.43 0.49 0.46 0.55 0.52 0.52 0.47 0.41 0.51
0.56 0.40 0.56 0.50 0.47 0.48 0.55 0.44
 [85] 0.57 0.44 0.51 0.49 0.50 0.49 0.56 0.54 0.46 0.50 0.52 0.49 0.52
0.42 0.57 0.54
Robert

On Tue, Dec 22, 2009 at 1:36 AM, Renaud Lancelot
<renaud.lancelot at cirad.fr> wrote:
#
Thank you for the different solutions which all work fine.

Kind regards,

Renaud

2009/12/22, Robert J. Hijmans <r.hijmans at gmail.com>:

  
    
#
Roger Bivand wrote:
I believe the ECW dll for GDAL is available in the OSGEO4W package, and
my understanding of it is that as long as the dll is present on your
gdal path for the gdal install that rgdal is using it should work.
http://trac.osgeo.org/osgeo4w/

I can't speak for ECW but I do know for MrSID there's been clarification
on several occasions that it is ok to distribute the built binary.

Alex