Re: [R-sig-Geo] calculate "regional" slope

2016-02-19 Thread chris english
Dominik,

r <- raster(nrows=22, ncols=20, xmn=-58, xmx=-48, ymn=-33, ymx=-22)
 vals <- sample.int(1e3,440)
r[ ] <- vals
#raster::terrain
terr_r <- terrain(r, opt='slope', unit='degrees', neighbors=8)
Ah, but it appears you want up sampling to 1.5 degrees rather than 0.5 deg.
so maybe spatial.tools::projectRaster_rigorous then raster:terrain.

I'm inclined to end that last so maybe with a question mark. Sorry for an
essentially inconclusive response but I was happy to find terrain in any
case.
Chris

On Fri, Feb 19, 2016 at 2:59 AM, Dominik Schneider <
dominik.schnei...@colorado.edu> wrote:

> I need to calculate slope at different scales. In the case below, r is a
> 0.5deg resolution raster and I want the slope for 1.5 deg centered on each
> of those 0.5 deg pixels. I'm trying to estimate which side of mountain
> range each pixel is on. So the resulting raster would have the same number
> of pixels as r. The edges can be NA.
> any suggestions would be appreciated. Thanks
>
>
> r <- raster(nrows=22, ncols=20, xmn=-58, xmx=-48, ymn=-33, ymx=-22)
> setValues(r,rnorm(440))
>
> [[alternative HTML version deleted]]
>
> ___
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

[[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] How to speed up the projection of a raster

2016-02-19 Thread Manuel Spínola
Dear list members,

I am trying to reproject a raster (see the code below), however the process
is too slow.  What I need to do to speed up the process? It took me seconds
to do the task in QGIS, but I prefer to do other raster projections in r.

Thank you very much in advance.

> ras = raster("lc.grd")
> ras

class   : RasterLayer
dimensions  : 16118, 21959, 353935162  (nrow, ncol, ncell)
resolution  : 98.4252, 98.4252  (x, y)
extent  : 183871.7, 2345191, 88600.88, 1675018  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=lcc +lat_1=43 +lat_2=45.5 +lat_0=41.75 +lon_0=-120.5
+x_0=39.99 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=ft
+no_defs
data source :
C:\Users\Manuel\Documents\Documentos_personales\Clases_y_Cursos\Clases\ICOMVIS\03_Evaluacion_del_Habitat\Practicos\Practica_03_Seleccion_de_habitat_Paisaje\oregon\lc.grd
names   : w001001
values  : 0, 95  (min, max)
attributes  :
   ID   COUNT   RED GREEN  BLUE
 from:  0   60051 0.000 0.000 0.000
 to  : 95 2481857 0.4392157 0.6392157 0.7294118
LAND_COVER OPACITY
  Unclassified   1
 Emergent Herbaceuous Wetlands   1



> rasp = projectRaster(ras, crs = "+proj=longlat +datum=WGS84", method =
"ngb")

-- 
*Manuel Spínola, Ph.D.*
Instituto Internacional en Conservación y Manejo de Vida Silvestre
Universidad Nacional
Apartado 1350-3000
Heredia
COSTA RICA
mspin...@una.ac.cr
mspinol...@gmail.com
Teléfono: (506) 2277-3598
Fax: (506) 2237-7036
Personal website: Lobito de río 
Institutional website: ICOMVIS 

[[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] calculate "regional" slope

2016-02-19 Thread Dominik Schneider
Thanks for the suggestion Chris.  I'm familiar with gdaldem, which
raster::terrain is based on, to compute slope from a dem. I now realize
that my example isnt a good one because neighbors=8 would achieve what I
described. However I actually want some flexibility such that I can
specifiy neighbors=16 so that it uses the next "ring" of cells.

I played around with focal() with weight argument =
matrix(rep(c(1,0,0,0,1),5),byrow=T) but couldn't figure out how to solve
for a directional slope.

On Fri, Feb 19, 2016 at 4:09 AM, chris english <
englishchristoph...@gmail.com> wrote:

> Dominik,
>
> r <- raster(nrows=22, ncols=20, xmn=-58, xmx=-48, ymn=-33, ymx=-22)
>  vals <- sample.int(1e3,440)
> r[ ] <- vals
> #raster::terrain
> terr_r <- terrain(r, opt='slope', unit='degrees', neighbors=8)
> Ah, but it appears you want up sampling to 1.5 degrees rather than 0.5 deg.
> so maybe spatial.tools::projectRaster_rigorous then raster:terrain.
>
> I'm inclined to end that last so maybe with a question mark. Sorry for an
> essentially inconclusive response but I was happy to find terrain in any
> case.
> Chris
>
> On Fri, Feb 19, 2016 at 2:59 AM, Dominik Schneider <
> dominik.schnei...@colorado.edu> wrote:
>
>> I need to calculate slope at different scales. In the case below, r is a
>> 0.5deg resolution raster and I want the slope for 1.5 deg centered on each
>> of those 0.5 deg pixels. I'm trying to estimate which side of mountain
>> range each pixel is on. So the resulting raster would have the same number
>> of pixels as r. The edges can be NA.
>> any suggestions would be appreciated. Thanks
>>
>>
>> r <- raster(nrows=22, ncols=20, xmn=-58, xmx=-48, ymn=-33, ymx=-22)
>> setValues(r,rnorm(440))
>>
>> [[alternative HTML version deleted]]
>>
>> ___
>> R-sig-Geo mailing list
>> R-sig-Geo@r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>
>

[[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] How to speed up the projection of a raster

2016-02-19 Thread Dominik Schneider
Manual,
I generally find gdal directly (which is what's used by qgis) to be faster
than the raster package.  I would use either:
1. gdalUtils package which essentially just provides r-style syntax to the
gdal commandline utilities
2. use system() with the gdal commandline utility command given as a string
to this function.
I use os x so not sure if things are the same on windows, if that's your OS.
gl
ds


On Fri, Feb 19, 2016 at 8:08 AM, Manuel Spínola 
wrote:

> Dear list members,
>
> I am trying to reproject a raster (see the code below), however the process
> is too slow.  What I need to do to speed up the process? It took me seconds
> to do the task in QGIS, but I prefer to do other raster projections in r.
>
> Thank you very much in advance.
>
> > ras = raster("lc.grd")
> > ras
>
> class   : RasterLayer
> dimensions  : 16118, 21959, 353935162  (nrow, ncol, ncell)
> resolution  : 98.4252, 98.4252  (x, y)
> extent  : 183871.7, 2345191, 88600.88, 1675018  (xmin, xmax, ymin,
> ymax)
> coord. ref. : +proj=lcc +lat_1=43 +lat_2=45.5 +lat_0=41.75 +lon_0=-120.5
> +x_0=39.99 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=ft
> +no_defs
> data source :
>
> C:\Users\Manuel\Documents\Documentos_personales\Clases_y_Cursos\Clases\ICOMVIS\03_Evaluacion_del_Habitat\Practicos\Practica_03_Seleccion_de_habitat_Paisaje\oregon\lc.grd
> names   : w001001
> values  : 0, 95  (min, max)
> attributes  :
>ID   COUNT   RED GREEN  BLUE
>  from:  0   60051 0.000 0.000 0.000
>  to  : 95 2481857 0.4392157 0.6392157 0.7294118
> LAND_COVER OPACITY
>   Unclassified   1
>  Emergent Herbaceuous Wetlands   1
>
>
>
> > rasp = projectRaster(ras, crs = "+proj=longlat +datum=WGS84", method =
> "ngb")
>
> --
> *Manuel Spínola, Ph.D.*
> Instituto Internacional en Conservación y Manejo de Vida Silvestre
> Universidad Nacional
> Apartado 1350-3000
> Heredia
> COSTA RICA
> mspin...@una.ac.cr
> mspinol...@gmail.com
> Teléfono: (506) 2277-3598
> Fax: (506) 2237-7036
> Personal website: Lobito de río <
> https://sites.google.com/site/lobitoderio/>
> Institutional website: ICOMVIS 
>
> [[alternative HTML version deleted]]
>
> ___
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo

[[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] AIC/R^2 in splm

2016-02-19 Thread Tobias Rüttenauer

> -Ursprüngliche Nachricht-
> Von: R-sig-Geo [mailto:r-sig-geo-boun...@r-project.org] Im Auftrag von
> Maryia Bakhtsiyarava
> Gesendet: Montag, 15. Februar 2016 03:59
> An: R-sig-geo Mailing List 
> Betreff: [R-sig-Geo] AIC/R^2 in splm
> 
> Dear list members,
> 
> I am estimating a spatial lag model with time-period fixed effects using
> package splm. I would like to obtain some goodness-of-fit measures for my
> models but I cannot figure out how to do it. The traditional AIC
extraction
> function doesn't work for a an object of class "splm".

Most extract functions do not support "splm" class. You can try to access
the functions for objects of a similar class and rearrange it for splm.

> 
> The only thing I can extract is the log likelihood, using which in theory
I can
> calculate AIC, but even in that case I am not sure about the degrees of
> freedom to use in the calculation (do I count time dummies, lag and
intercept
> as parameters?). I tried df.residual(model) but I got NULL.

If you use the same data for different models (having the same number of
time dummies), it does not matter if you include or exclude these dummies. 

> 
> Is there another way to obtain AIC and/or R^2? I am sure people
> encountered this problem before, so if you have any advice on how to
obtain
> model statistics, I would greatly appreciate it.

If you receive the log Likelihood in your spml model output (
summary(fesar.mod)$logLik ), you can use the following function to calculate
the AIC (it includes the spatial lag as one parameter and the spatial error
as one parameter):

 AIC function for spml 

godf.spml<-function(object, k=2, criterion=c("AIC", "BIC"),  ...){
  s<-summary(object)
  l<-s$logLik[1,1]
  np<- length(coef(s))
  N<- nrow(s$model)
  if(criterion=="AIC"){
aic<- -2*l+k*np
names(aic)<-"AIC"
return(aic)
  }
  if(criterion=="BIC"){
bic<- -2*l+log(N)*np
names(bic)<-"BIC"
if(k!=2){
  warning("parameter  not used for BIC")
}
return(bic)
  }
}

Example:

require(splm)
fesar.mod<-spml(formula= y~x1+x2, data=data.pd, ...)
godf.spml(fesar.mod, criterion="AIC")


If your spml model output does not contain a value for logLik, see here how
to fix this:
http://r-sig-geo.2731867.n2.nabble.com/spml-and-logLik-help-td7581581.html

There is an R squared reported in the model output:

summary(fesar.mod)$rsqr

Unfortunately it is not documented what kind of (Pseudo)-R squared this is
(to my knowledge).

Best
Tobi

> 
> Thank you,
> Maryia
> --
> Maryia Bakhtsiyarava
> Graduate student
> Department of Geography, Environment and Society University of
> Minnesota, Twin Cities
> 
> Research Assistant
> TerraPop Project
> Minnesota Population Center
> 
> 414 Social Sciences, 267 19th Ave S, Minneapolis, MN 55455
> 
>   [[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 mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Re: [R-sig-Geo] calculate "regional" slope

2016-02-19 Thread Chris Reudenbach
Dominik,

If you want to deal with bigger data sets in a fast and more flexible way I 
strongly suggest to use GRASS7. Rgrass7 provides a very good "r-ish" wrapper to 
use it from R. If You are interested i 'll post a typical setup and example for 
your question. Please note you need obligatory a GRASS 7 installation on your 
system.

Cheers Chris 


Am 19. Februar 2016 16:55:32 MEZ, schrieb Dominik Schneider 
:
>Thanks for the suggestion Chris.  I'm familiar with gdaldem, which
>raster::terrain is based on, to compute slope from a dem. I now realize
>that my example isnt a good one because neighbors=8 would achieve what
>I
>described. However I actually want some flexibility such that I can
>specifiy neighbors=16 so that it uses the next "ring" of cells.
>
>I played around with focal() with weight argument =
>matrix(rep(c(1,0,0,0,1),5),byrow=T) but couldn't figure out how to
>solve
>for a directional slope.
>
>On Fri, Feb 19, 2016 at 4:09 AM, chris english <
>englishchristoph...@gmail.com> wrote:
>
>> Dominik,
>>
>> r <- raster(nrows=22, ncols=20, xmn=-58, xmx=-48, ymn=-33, ymx=-22)
>>  vals <- sample.int(1e3,440)
>> r[ ] <- vals
>> #raster::terrain
>> terr_r <- terrain(r, opt='slope', unit='degrees', neighbors=8)
>> Ah, but it appears you want up sampling to 1.5 degrees rather than
>0.5 deg.
>> so maybe spatial.tools::projectRaster_rigorous then raster:terrain.
>>
>> I'm inclined to end that last so maybe with a question mark. Sorry
>for an
>> essentially inconclusive response but I was happy to find terrain in
>any
>> case.
>> Chris
>>
>> On Fri, Feb 19, 2016 at 2:59 AM, Dominik Schneider <
>> dominik.schnei...@colorado.edu> wrote:
>>
>>> I need to calculate slope at different scales. In the case below, r
>is a
>>> 0.5deg resolution raster and I want the slope for 1.5 deg centered
>on each
>>> of those 0.5 deg pixels. I'm trying to estimate which side of
>mountain
>>> range each pixel is on. So the resulting raster would have the same
>number
>>> of pixels as r. The edges can be NA.
>>> any suggestions would be appreciated. Thanks
>>>
>>>
>>> r <- raster(nrows=22, ncols=20, xmn=-58, xmx=-48, ymn=-33, ymx=-22)
>>> setValues(r,rnorm(440))
>>>
>>> [[alternative HTML version deleted]]
>>>
>>> ___
>>> R-sig-Geo mailing list
>>> R-sig-Geo@r-project.org
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>
>>
>>
>
>   [[alternative HTML version deleted]]
>
>___
>R-sig-Geo mailing list
>R-sig-Geo@r-project.org
>https://stat.ethz.ch/mailman/listinfo/r-sig-geo

-- 
Diese Nachricht wurde von meinem Android-Mobiltelefon mit K-9 Mail gesendet.
[[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] calculate "regional" slope

2016-02-19 Thread chris english
Dominik,
Sorry, I'm still trying to understand your 0.05 to 1.5 degree part of your
problem.

Otherwise, I think you are limited to 8 neighbors as this reflects the
documentation as I read it.

Even Roualt perhaps would be up in arms; but, there's nothing saying you
can't do a 16 vs 8 neighbor. You'd have to examine the impacts thereafter,
but basically you'd be amending some gdal (probably a line or two of code)
for your purposes.

There are a bunch of things to consider, theoretical and practical; but,
why 16 better than 8. And more importantly as you relax, as a matter of
rings (in this case), would your analytical result be better? Or
potentially have any remainder meaning at all, I.e. I don't know my
neighbor's neighbor's neighbor (does that get us out to 16?).
And so generalizing beyond some given point might yield not much on a knn
influence/likeness basis.

I think we're first better off dialing back in on what you mean by regional
or the 0.5 to 1.5 resolution and then neighborhood size (4, 8,16?).

Of course another approach to this "what side of the mountain am I on" is
to transect along the z. I.e. roll your dem on it's side.

Anyway, clarify the 0.5/1.5 so I don't go too far astray.
Chris
Thanks for the suggestion Chris.  I'm familiar with gdaldem, which
raster::terrain is based on, to compute slope from a dem. I now realize
that my example isnt a good one because neighbors=8 would achieve what I
described. However I actually want some flexibility such that I can
specifiy neighbors=16 so that it uses the next "ring" of cells.

I played around with focal() with weight argument =
matrix(rep(c(1,0,0,0,1),5),byrow=T) but couldn't figure out how to solve
for a directional slope.

On Fri, Feb 19, 2016 at 4:09 AM, chris english <
englishchristoph...@gmail.com> wrote:

> Dominik,
>
> r <- raster(nrows=22, ncols=20, xmn=-58, xmx=-48, ymn=-33, ymx=-22)
>  vals <- sample.int(1e3,440)
> r[ ] <- vals
> #raster::terrain
> terr_r <- terrain(r, opt='slope', unit='degrees', neighbors=8)
> Ah, but it appears you want up sampling to 1.5 degrees rather than 0.5 deg.
> so maybe spatial.tools::projectRaster_rigorous then raster:terrain.
>
> I'm inclined to end that last so maybe with a question mark. Sorry for an
> essentially inconclusive response but I was happy to find terrain in any
> case.
> Chris
>
> On Fri, Feb 19, 2016 at 2:59 AM, Dominik Schneider <
> dominik.schnei...@colorado.edu> wrote:
>
>> I need to calculate slope at different scales. In the case below, r is a
>> 0.5deg resolution raster and I want the slope for 1.5 deg centered on each
>> of those 0.5 deg pixels. I'm trying to estimate which side of mountain
>> range each pixel is on. So the resulting raster would have the same number
>> of pixels as r. The edges can be NA.
>> any suggestions would be appreciated. Thanks
>>
>>
>> r <- raster(nrows=22, ncols=20, xmn=-58, xmx=-48, ymn=-33, ymx=-22)
>> setValues(r,rnorm(440))
>>
>> [[alternative HTML version deleted]]
>>
>> ___
>> R-sig-Geo mailing list
>> R-sig-Geo@r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>
>

[[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] calculate "regional" slope

2016-02-19 Thread Dominik Schneider
Chris R,
I'd be happy to use grass7 but I can't get it to run on my mac. osx
10.11.3. I have a working qgis from kyngchaos, installed pandoc and cairo
on top of that, and disabled sip but the grass7.app just hangs when I try
to open it.
Chris E,
I will try to clarify. Rather than thinking about "side of a mountain",
think about "side of a mountain **range**".  The point of calculating a
regional slope is that if I am on the west side of a continental divide but
on the east side of mountain, the function still returns a value indicating
west-facing.  so maybe it's easier to think in meters.   lets assume my DEM
is a 500m grid. the slope calculation would give a local value at 500m.
This local slope might be east facing, but I am interested in the overall
slope across 10km to indicate which way e.g. the watershed is draining.
What do you mean with "transect along the z. I.e. roll your dem on it's
side."?


On Fri, Feb 19, 2016 at 2:50 PM, chris english <
englishchristoph...@gmail.com> wrote:

> Dominik,
> Sorry, I'm still trying to understand your 0.05 to 1.5 degree part of your
> problem.
>
> Otherwise, I think you are limited to 8 neighbors as this reflects the
> documentation as I read it.
>
> Even Roualt perhaps would be up in arms; but, there's nothing saying you
> can't do a 16 vs 8 neighbor. You'd have to examine the impacts thereafter,
> but basically you'd be amending some gdal (probably a line or two of code)
> for your purposes.
>
> There are a bunch of things to consider, theoretical and practical; but,
> why 16 better than 8. And more importantly as you relax, as a matter of
> rings (in this case), would your analytical result be better? Or
> potentially have any remainder meaning at all, I.e. I don't know my
> neighbor's neighbor's neighbor (does that get us out to 16?).
> And so generalizing beyond some given point might yield not much on a knn
> influence/likeness basis.
>
> I think we're first better off dialing back in on what you mean by
> regional or the 0.5 to 1.5 resolution and then neighborhood size (4, 8,16?).
>
> Of course another approach to this "what side of the mountain am I on" is
> to transect along the z. I.e. roll your dem on it's side.
>
> Anyway, clarify the 0.5/1.5 so I don't go too far astray.
> Chris
> Thanks for the suggestion Chris.  I'm familiar with gdaldem, which
> raster::terrain is based on, to compute slope from a dem. I now realize
> that my example isnt a good one because neighbors=8 would achieve what I
> described. However I actually want some flexibility such that I can
> specifiy neighbors=16 so that it uses the next "ring" of cells.
>
> I played around with focal() with weight argument =
> matrix(rep(c(1,0,0,0,1),5),byrow=T) but couldn't figure out how to solve
> for a directional slope.
>
> On Fri, Feb 19, 2016 at 4:09 AM, chris english <
> englishchristoph...@gmail.com> wrote:
>
>> Dominik,
>>
>> r <- raster(nrows=22, ncols=20, xmn=-58, xmx=-48, ymn=-33, ymx=-22)
>>  vals <- sample.int(1e3,440)
>> r[ ] <- vals
>> #raster::terrain
>> terr_r <- terrain(r, opt='slope', unit='degrees', neighbors=8)
>> Ah, but it appears you want up sampling to 1.5 degrees rather than 0.5
>> deg.
>> so maybe spatial.tools::projectRaster_rigorous then raster:terrain.
>>
>> I'm inclined to end that last so maybe with a question mark. Sorry for an
>> essentially inconclusive response but I was happy to find terrain in any
>> case.
>> Chris
>>
>> On Fri, Feb 19, 2016 at 2:59 AM, Dominik Schneider <
>> dominik.schnei...@colorado.edu> wrote:
>>
>>> I need to calculate slope at different scales. In the case below, r is a
>>> 0.5deg resolution raster and I want the slope for 1.5 deg centered on
>>> each
>>> of those 0.5 deg pixels. I'm trying to estimate which side of mountain
>>> range each pixel is on. So the resulting raster would have the same
>>> number
>>> of pixels as r. The edges can be NA.
>>> any suggestions would be appreciated. Thanks
>>>
>>>
>>> r <- raster(nrows=22, ncols=20, xmn=-58, xmx=-48, ymn=-33, ymx=-22)
>>> setValues(r,rnorm(440))
>>>
>>> [[alternative HTML version deleted]]
>>>
>>> ___
>>> R-sig-Geo mailing list
>>> R-sig-Geo@r-project.org
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>>
>>
>>
>

[[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] calculate "regional" slope

2016-02-19 Thread chris english
Dominik,
There's mention of grass not working on osx 10.11 and a work around
grassmac.wikidot.com

I was generally using PCRaster when I was doing watershed/flood
re-creations to handle the watershed delineations and the like and don't
have an opinion on Grass.

Yeah, that transect was maybe a silly idea but it generalizes surface to
line, sort of like Mauana volcano is a cake you've cut in half. And the
line is outline.

Chris
On Feb 20, 2016 2:09 AM, "Dominik Schneider" 
wrote:

> Chris R,
> I'd be happy to use grass7 but I can't get it to run on my mac. osx
> 10.11.3. I have a working qgis from kyngchaos, installed pandoc and cairo
> on top of that, and disabled sip but the grass7.app just hangs when I try
> to open it.
> Chris E,
> I will try to clarify. Rather than thinking about "side of a mountain",
> think about "side of a mountain **range**".  The point of calculating a
> regional slope is that if I am on the west side of a continental divide but
> on the east side of mountain, the function still returns a value indicating
> west-facing.  so maybe it's easier to think in meters.   lets assume my DEM
> is a 500m grid. the slope calculation would give a local value at 500m.
> This local slope might be east facing, but I am interested in the overall
> slope across 10km to indicate which way e.g. the watershed is draining.
> What do you mean with "transect along the z. I.e. roll your dem on it's
> side."?
>
>
> On Fri, Feb 19, 2016 at 2:50 PM, chris english <
> englishchristoph...@gmail.com> wrote:
>
>> Dominik,
>> Sorry, I'm still trying to understand your 0.05 to 1.5 degree part of
>> your problem.
>>
>> Otherwise, I think you are limited to 8 neighbors as this reflects the
>> documentation as I read it.
>>
>> Even Roualt perhaps would be up in arms; but, there's nothing saying you
>> can't do a 16 vs 8 neighbor. You'd have to examine the impacts thereafter,
>> but basically you'd be amending some gdal (probably a line or two of code)
>> for your purposes.
>>
>> There are a bunch of things to consider, theoretical and practical; but,
>> why 16 better than 8. And more importantly as you relax, as a matter of
>> rings (in this case), would your analytical result be better? Or
>> potentially have any remainder meaning at all, I.e. I don't know my
>> neighbor's neighbor's neighbor (does that get us out to 16?).
>> And so generalizing beyond some given point might yield not much on a knn
>> influence/likeness basis.
>>
>> I think we're first better off dialing back in on what you mean by
>> regional or the 0.5 to 1.5 resolution and then neighborhood size (4, 8,16?).
>>
>> Of course another approach to this "what side of the mountain am I on" is
>> to transect along the z. I.e. roll your dem on it's side.
>>
>> Anyway, clarify the 0.5/1.5 so I don't go too far astray.
>> Chris
>> Thanks for the suggestion Chris.  I'm familiar with gdaldem, which
>> raster::terrain is based on, to compute slope from a dem. I now realize
>> that my example isnt a good one because neighbors=8 would achieve what I
>> described. However I actually want some flexibility such that I can
>> specifiy neighbors=16 so that it uses the next "ring" of cells.
>>
>> I played around with focal() with weight argument =
>> matrix(rep(c(1,0,0,0,1),5),byrow=T) but couldn't figure out how to solve
>> for a directional slope.
>>
>> On Fri, Feb 19, 2016 at 4:09 AM, chris english <
>> englishchristoph...@gmail.com> wrote:
>>
>>> Dominik,
>>>
>>> r <- raster(nrows=22, ncols=20, xmn=-58, xmx=-48, ymn=-33, ymx=-22)
>>>  vals <- sample.int(1e3,440)
>>> r[ ] <- vals
>>> #raster::terrain
>>> terr_r <- terrain(r, opt='slope', unit='degrees', neighbors=8)
>>> Ah, but it appears you want up sampling to 1.5 degrees rather than 0.5
>>> deg.
>>> so maybe spatial.tools::projectRaster_rigorous then raster:terrain.
>>>
>>> I'm inclined to end that last so maybe with a question mark. Sorry for an
>>> essentially inconclusive response but I was happy to find terrain in any
>>> case.
>>> Chris
>>>
>>> On Fri, Feb 19, 2016 at 2:59 AM, Dominik Schneider <
>>> dominik.schnei...@colorado.edu> wrote:
>>>
 I need to calculate slope at different scales. In the case below, r is a
 0.5deg resolution raster and I want the slope for 1.5 deg centered on
 each
 of those 0.5 deg pixels. I'm trying to estimate which side of mountain
 range each pixel is on. So the resulting raster would have the same
 number
 of pixels as r. The edges can be NA.
 any suggestions would be appreciated. Thanks


 r <- raster(nrows=22, ncols=20, xmn=-58, xmx=-48, ymn=-33, ymx=-22)
 setValues(r,rnorm(440))

 [[alternative HTML version deleted]]

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

>>>
>>>
>>
>

[[alternative HTML version deleted]]

___
R-sig-Geo mailin