Hi,
I paste the code of the spatial_sync_raster function from climstats
package below. If you run this code then you will be able to use the
function even if you're not able to install the package.
Hope this helps
Paco
spatial_sync_raster <- function (unsynced, reference, method = "ngb",
verbose = FALSE)
{
new_projection = projection(reference)
old_projection = projection(unsynced)
new_res = res(reference)
old_res = res(unsynced)
if (new_projection != old_projection | new_res[1] != old_res[1] |
new_res[2] != old_res[2]) {
pr_extent = projectExtent(unsynced, new_projection)
pr_extent <- setExtent(pr_extent, extent(reference))
res(pr_extent) = res(reference)
if (new_projection != old_projection) {
pr <- projectRaster(unsynced, pr_extent, method = method)
}
else {
pr <- raster::resample(unsynced, pr_extent, method = method)
}
}
else {
pr = unsynced
}
expanded_raster = expand(pr, reference)
synced_raster = crop(expanded_raster, reference)
extent(synced_raster) = extent(reference)
return(synced_raster)
}
El 21/09/2012 15:38, Doni Schwalm escribió:
> Hi All:
>
> I, too, am trying to use the spatial_sync_raster function to align a
> series of rasters. When I completed the initial install (from the zip
> file), I subsequently received the error message indicating R couldn't
> find the spatial_sync_raster function. I then followed John's suggestion
> and deleted the NAMESPACE file. Using the command require(climstats), I
> receive the following error message: Failed with error: ‘package
> ‘climstats’ does not have a NAMESPACE and should be re-installed’.
>
> I then tried the install format suggested by John; my command line
> reads:
> install.packages('C:/Users/schwalmd/Documents/R/win-library/2.15/climstats',
> repos=NULL, type='source')
>
> This generated the following error messages:
>
> Installing package(s) into ‘C:/Users/schwalmd/Documents/R/win-library/2.15’
> (as ‘lib’ is unspecified)
> ERROR: cannot install to srcdir for package 'climstats'
> * removing 'C:/Users/schwalmd/Documents/R/win-library/2.15/climstats'
> Warning messages:
> 1: running command 'C:/PROGRA~1/R/R-215~1.1/bin/i386/R CMD INSTALL -l
> "C:/Users/schwalmd/Documents/R/win-library/2.15"
> "C:/Users/schwalmd/Documents/R/win-library/2.15/climstats"' had status 1
> 2: In
> install.packages("C:/Users/schwalmd/Documents/R/win-library/2.15/climstats",
> :
> installation of package
> ‘C:/Users/schwalmd/Documents/R/win-library/2.15/climstats’ had non-zero
> exit status
>
> I also tried a simpler path (c:/WorkSpace/climstats) but received the
> same error messages.
>
> Any suggestions? I am running R v 2.15.1, 32 bit version, on Windows 7.
>
> Thank you!
> Doni
>
>
>
> On Tuesday, July 3, 2012 3:09:56 AM UTC-7, Francisco Rodriguez-Sanchez
> wrote:
>
> Thanks John. It used to work for me, maybe the problem arose in the
> latest build.
>
> Mike, I haven't found extended documentation for this package, but
> you can have a look at the available functions by typing:
> help(package="climstats")
>
> Cheers
>
> Paco
>
>
> El 03/07/2012 09:12, Michael Treglia escribió:
>> Thanks John! I look forward to taking care of that when I'm back
>> in the office in the AM. Glad it wasn't just me with the problem.
>> On a side-note, is there any documentation for 'climstats'? (other
>> than the help files?) I would like to get a better idea of what
>> other commands are in it.
>> Cheers,
>> Mike
>>
>> On Tue, Jul 3, 2012 at 2:59 AM, John B
>> <
j.baum...@pgrad.unimelb.edu.au <javascript:>> wrote:
>>
>> Turns out that a NAMESPACE exists in the package but doesn't
>> export any of the functions.
>>
>> The simple fix is to:
>>
>> 1. download the package source
>> (
http://download.r-forge.r-project.org/src/contrib/climstats_1.0.tar.gz
>> <
http://download.r-forge.r-project.org/src/contrib/climstats_1.0.tar.gz>)
>> 2. keep extracting the nested archives (e.g. with 7zip
>> <
http://www.7-zip.org/>) until you have a 'climstats'
>> folder (typically 2 unzips required, except on OS X, which
>> I think extracts the tar.gz to a tar on download)
>> 3. within the climstats folder, there is a NAMESPACE file.
>> Delete it. (the problem with this file is that if present,
>> it should include exports of all functions etc. that
>> should be available, whereas the existing NAMESPACE is
>> blank. Deleting it will cause a default NAMESPACE - with
>> all functions exported - to be created on installation.)
>> 4. fire up R, and install the package with:
>> install.packages('c:/full/path/to/climstats/', repos=NULL,
>> type='source')
>>
>> Should work now.
>>
>>
>> On Tuesday, 3 July 2012 17:36:05 UTC+10, John B wrote:
>>
>> This is happening for me too. Not sure why. In fact the
>> problem exists for all functions in the climstats package.
>>
>> You can, however, access the function with:
>>
>> climstats:::spatial_sync_raster()
>>
>> (that's a triple colon)
>>
>>
>>
>> On Tuesday, 3 July 2012 16:33:43 UTC+10, Mike Treglia wrote:
>>
>> Hi Paco,
>>
>> I was trying out the "spatial_sync_raster" function
>> that you suggested, but received a message that R
>> could not find the function... yet there was a Help
>> topic for it. Any suggestions?
>>
>> Thanks!
>> Mike
>>
>> On Monday, April 2, 2012 2:59:30 AM UTC-7, Francisco
>> Rodriguez-Sanchez wrote:
>>
>> Hi,
>>
>> you can also try the all-in-one
>> "spatial_sync_raster" function in package
>> climstats:
>>
http://r-forge.r-project.org/projects/climstats/
>> <
http://r-forge.r-project.org/projects/climstats/>. It
>> will match the projection, extent and resolution
>> of any reference raster
>>
>> Cheers
>>
>> Paco
>>
>>
>> --
>> Dr Francisco Rodriguez-Sanchez
>> Forest Ecology and Conservation Group
>> Department of Plant Sciences
>> University of Cambridge
>> Downing Street
>> Cambridge CB2 3EA
>> United Kingdom
>>
http://sites.google.com/site/rodriguezsanchezf <
http://sites.google.com/site/rodriguezsanchezf>
>>
>>
>> El 31/03/2012 00:39, John Baumgartner escribió:
>>> Since you asked, Robert Hijman's excellent raster
>>> package makes this very straightforward in R, as
>>> well...
>>>
>>> library(raster)
>>>
>>> e <- extent(xmin, xmax, ymin, ymax) # desired
>>> final extent
>>>
>>> # read in rasters
>>> elev <- raster('path/to/elevation/raster')
>>> rain <- raster('path/to/rainfall/raster')
>>> lc <- raster('path/to/landcover/raster')
>>>
>>> elev <- crop(elev, e) # clip elev grid to study area
>>> # resample rain and lc grids to have same res and
>>> extent as elev grid
>>> # You can specify method='ngb' for
>>> nearest-neighbour (default is bilinear)
>>> # Provide a filename arg to. write the result
>>> directly to a file
>>> rain <- resample(rain, elev)
>>> lc <- resample(lc, elev)
>>>
>>> # Look at ?writeRaster
>>>
>>>
>>> On 31/03/2012, at 7:58 AM, Bert Harris
>>>> E-mails:
bert....@adelaide.edu.au <javascript:>,
>>>>
arami...@gmail.com <javascript:>
>>>> Homepage:
>>>>
https://www.adelaide.edu.au/directory/bert.harris <
https://www.adelaide.edu.au/directory/bert.harris>
>>>> Phone (USA):
1-256-533-0529, Mobile (USA):
>>>>
1-615-440-0666, Skype: ravenfork
>>>> --
>>>> You received this message because you are
>>>> subscribed to the Google Groups "Maxent" group.
>>>> To post to this group, send email to
>>>>
max...@googlegroups.com <javascript:>.
>>>> To unsubscribe from this group, send email to
>>>>
maxent+un...@googlegroups.com <javascript:>.
>>>> <
http://groups.google.com/group/maxent?hl=en>.
>>> --
>>> You received this message because you are
>>> subscribed to the Google Groups "Maxent" group.
>>> To post to this group, send email to
>>>
max...@googlegroups.com <javascript:>.
>>> To unsubscribe from this group, send email to
>>>
maxent+un...@googlegroups.com <javascript:>.
>>> <
http://groups.google.com/group/maxent?hl=en>.
>> <
https://groups.google.com/d/msg/maxent/-/sGcvMCQuwowJ>.
>> <javascript:>.
>> To unsubscribe from this group, send email to
>>
maxent+un...@googlegroups.com <javascript:>.
>> <
http://groups.google.com/group/maxent?hl=en>.
>>
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Maxent" group.
>> To post to this group, send email to
max...@googlegroups.com
>> <javascript:>.
>> To unsubscribe from this group, send email to
>>
maxent+un...@googlegroups.com <javascript:>.
>> <
http://groups.google.com/group/maxent?hl=en>.
>
> --
> Dr Francisco Rodriguez-Sanchez
> Forest Ecology and Conservation Group
> Department of Plant Sciences
> University of Cambridge
> Downing Street
> Cambridge CB2 3EA
> United Kingdom
>
http://sites.google.com/site/rodriguezsanchezf <
http://sites.google.com/site/rodriguezsanchezf>
>
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Maxent" group.
> To view this discussion on the web visit
>
https://groups.google.com/d/msg/maxent/-/TfMNekxnSMIJ.