Re: [GRASS-user] Boxplots based on raster data in GRASS GIS

2024-04-24 Thread Roger Bivand via grass-user
If you ran execGRASS("g.extension", extension="r.boxplot", operation="add"), 
the add-on will not be found until you restart the R session in RStudio 
(parseGRASS caches all *.bat found the first time it is used on Windows). GRASS 
extensions are installed in GRASS, not R, but can be installed through 
execGRASS(). In that case, on Windows, the R session needs to restarted. In any 
case, I guess that making the boxplot in R is easier, see for example: 
https://rsbivand.github.io/rgrass/reference/readRAST.html.

--
Roger Bivand
Emeritus Professor
Norwegian School of Economics
Postboks 3490 Ytre Sandviken, 5045 Bergen, Norway
roger.biv...@nhh.no


From: sibylle.stoec...@gmx.ch 
Sent: 24 April 2024 11:45
To: Roger Bivand; grass-user@lists.osgeo.org
Subject: RE: [GRASS-user] Boxplots based on raster data in GRASS GIS

Yes I have installed successfully all addons (visualised in the figure below). 
Additionally I was able to run the code using GUI or GRASS GIS command.

  *   Managed installed GRASS addons extensions: then r.boxplot is visible as 
installed.



As g.region, r.mask, v.to.rast is working and the error was just related to 
r.boxplot, I was wondering if I need to install addons a second time in rstudio?





[cid:image001.png@01DA963C.F15DEE40]



-----Original Message-
From: Roger Bivand 
Sent: Wednesday, April 24, 2024 10:25 AM
To: grass-user@lists.osgeo.org
Cc: sibylle.stoec...@gmx.ch
Subject: Re: [GRASS-user] Boxplots based on raster data in GRASS GIS



It is a GRASS addon, install as per:



https://grass.osgeo.org/download/addons/<https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgrass.osgeo.org%2Fdownload%2Faddons%2F=05%7C02%7CRoger.Bivand%40nhh.no%7C53695f68bf734e3c848208dc64435092%7C33a15b2f849941998d56f20b5aa91af2%7C0%7C0%7C638495487507664917%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C=AjIgJKpSmV8LCwwqvw1Co7pDm819QpI5uXJiPCEOufg%3D=0>



https://grass.osgeo.org/grass83/manuals/g.extension.html<https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgrass.osgeo.org%2Fgrass83%2Fmanuals%2Fg.extension.html=05%7C02%7CRoger.Bivand%40nhh.no%7C53695f68bf734e3c848208dc64435092%7C33a15b2f849941998d56f20b5aa91af2%7C0%7C0%7C638495487507677612%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C=l2K7Z617o9mAPK1yqlGOraOJWz76%2Fmjyd%2Bq9j2L03LA%3D=0>



https://grass.osgeo.org/grass83/manuals/addons/r.boxplot.html<https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgrass.osgeo.org%2Fgrass83%2Fmanuals%2Faddons%2Fr.boxplot.html=05%7C02%7CRoger.Bivand%40nhh.no%7C53695f68bf734e3c848208dc64435092%7C33a15b2f849941998d56f20b5aa91af2%7C0%7C0%7C638495487507686606%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C=WXu7btmERlnCeIsqL2ubiFKtqDmnZVNZnf6RnNpdKac%3D=0>



--

Roger Bivand

Emeritus Professor

Norwegian School of Economics

Postboks 3490 Ytre Sandviken, 5045 Bergen, Norway 
roger.biv...@nhh.no<mailto:roger.biv...@nhh.no>
___
grass-user mailing list
grass-user@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user


Re: [GRASS-user] Boxplots based on raster data in GRASS GIS

2024-04-24 Thread Roger Bivand via grass-user
It is a GRASS addon, install as per:

https://grass.osgeo.org/download/addons/

https://grass.osgeo.org/grass83/manuals/g.extension.html

https://grass.osgeo.org/grass83/manuals/addons/r.boxplot.html

--
Roger Bivand
Emeritus Professor
Norwegian School of Economics
Postboks 3490 Ytre Sandviken, 5045 Bergen, Norway
roger.biv...@nhh.no
___
grass-user mailing list
grass-user@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user


Re: [GRASS-user] Using RStudio in a GRASS GIS session

2024-04-20 Thread Roger Bivand via grass-user
First tell us exactly what you do. Do you start GRASS first (how was GRASS 
installed, which version?), then what? The first message suggests a failed 
GRASS installation. Can you use GRASS at all? Try to run any regular example on 
the data in your location in GRASS to check that GRASS works before anything 
else.

---
Roger Bivand
Emeritus Professor
Department of Economics
Norwegian School of Economics, Bergen, Norway


Fra: sibylle.stoec...@gmx.ch 
Sendt: fredag, april 19, 2024 5:56:04 p.m.
Til: Roger Bivand 
Kopi: grass-user@lists.osgeo.org 
Emne: RE: [GRASS-user] Using RStudio in a GRASS GIS session

Dear community
Dear Roger

I suppose it is my name
Here the output from the console:

C:\Users\Sibylle Stöckli>
C:\Users\Sibylle Stöckli>
ERROR: Unable to read WIND file: not enough values to unpack (expected 2,
got 1)
library(rgrass)
Der Befehl "library" ist entweder falsch geschrieben oder
konnte nicht gefunden werden.

Kind regards
Sibylle

-Original Message-----
From: Roger Bivand 
Sent: Friday, April 19, 2024 4:31 PM
To: sibylle.stoec...@gmx.ch
Cc: grass-user@lists.osgeo.org
Subject: Re: [GRASS-user] Using RStudio in a GRASS GIS session

Please see: 
https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Frsbivand.github.io%2Frgrass%2Farticles%2Fuse.html=05%7C02%7CRoger.Bivand%40nhh.no%7C04d6d2c547b14550ec5f08dc608936de%7C33a15b2f849941998d56f20b5aa91af2%7C0%7C0%7C638491389645818206%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C=3fLYSzCE3uRNBetqb69RxZz%2FzLiv%2F1LuBFkdb%2B19nsA%3D=0<https://rsbivand.github.io/rgrass/articles/use.html>.
https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Frsbivand.github.io%2Frgrass%2Farticles%2Fuse.html=05%7C02%7CRoger.Bivand%40nhh.no%7C04d6d2c547b14550ec5f08dc608936de%7C33a15b2f849941998d56f20b5aa91af2%7C0%7C0%7C638491389645826443%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C=zM%2Fia4%2BGNTgKd%2Bjxo3HVJnDgt02JrI9CSyx%2F1AtwK%2FU%3D=0<https://rsbivand.github.io/rgrass/articles/use.html>

Do you have a GRASS location and wish to use R on the data in that location?
Then start GRASS first and start rstudio from inside GRASS.

The error messages suggest that something is missing in your installation.

Is your query related to
https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fpipermail%2Fr-help%2F2024-April%2F479232.html=05%7C02%7CRoger.Bivand%40nhh.no%7C04d6d2c547b14550ec5f08dc608936de%7C33a15b2f849941998d56f20b5aa91af2%7C0%7C0%7C638491389645832105%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C=i1bTT5y7lmJcG1MtEniurDJsEYbK63t0UB%2BSagiLmMM%3D=0<https://stat.ethz.ch/pipermail/r-help/2024-April/479232.html>
 ?

--
Roger Bivand
Emeritus Professor
Norwegian School of Economics
Postboks 3490 Ytre Sandviken, 5045 Bergen, Norway roger.biv...@nhh.no


___
grass-user mailing list
grass-user@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user


Re: [GRASS-user] Using RStudio in a GRASS GIS session

2024-04-19 Thread Roger Bivand via grass-user
Please see: https://rsbivand.github.io/rgrass/articles/use.html. 
https://rsbivand.github.io/rgrass/articles/use.html

Do you have a GRASS location and wish to use R on the data in that location? 
Then start GRASS first and start rstudio from inside GRASS.

The error messages suggest that something is missing in your installation.

Is your query related to 
https://stat.ethz.ch/pipermail/r-help/2024-April/479232.html ?

--
Roger Bivand
Emeritus Professor
Norwegian School of Economics
Postboks 3490 Ytre Sandviken, 5045 Bergen, Norway
roger.biv...@nhh.no
___
grass-user mailing list
grass-user@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user


Re: [GRASS-user] grass-7.8.5 on Fedora 33

2020-12-23 Thread Roger Bivand
I install from source, so cannot check. PROJ 7 needs Tiff and curl (to access
the CDN) over and above the sqlite3 requirement introduced by PROJ 6. Is the
install process pulling in PROJ > 6? I see 6.3.2 as the F33 current version,
but >= 7 would explain complaints about missing Tiff:

$ pkg-config proj --libs --static
-L/usr/local/lib -lproj -lsqlite3 -ltiff -lcurl -lstdc++ 





-
Roger Bivand
NHH Norwegian School of Economics, Bergen, Norway
--
Sent from: http://osgeo-org.1560.x6.nabble.com/Grass-Users-f3884509.html
___
grass-user mailing list
grass-user@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user


Re: [GRASS-user] [R-sig-Geo] [R] Need help using GRASS within R - error when running the script for a second time

2020-07-09 Thread Roger Bivand

Dear Loïc,

On Wed, 8 Jul 2020, Loïc Valéry wrote:


Dear Roger,

Following the message you left on github this morning (here is the github link 
to make it easier for the subscribers to follow our exchanges: 
https://github.com/rsbivand/rgrass7/issues/13#issuecomment-655384113), I 
continued my investigations and I finally found the origin of the problem.

First of all, I would like to answer your questions this morning:
- OS: Windows 8.1
- R version 3.6.3
- all the packages are up to date 
- the GRASS version: stand-alone Windows GRASS 7.8.3

- I confirm that when I load the library rgrass7, R returns a message 
indicating that GRASS is not open.

Coming back to the subject itself, when you told me that you were unable 
to reproduce the problem under Windows, I also did the test and, indeed, 
when I only ran these few lines of code, everything worked fine and I 
could execute initGRASS() as many times as I wanted without any 
problems.


But these few lines of code are included in a larger script that first 
calls link2GI to interface R with the OTB software. And this is where 
the problem occurs. Here are the results of the tests in a very 
synthetic way:


So perhaps raise the issue with link2GI? 
https://github.com/r-spatial/link2GI/


Or separate the components to run in different R sessions as a stop-gap? 
It is quite likely that attaching link2GI will overwrite GRASS environment 
variables (and the reverse is probably the case too).


Roger



Test 1: 
1-Running initGRASS() n times: everything works fine n times
2-Running link2GI::linkOTB() 
3-Running initGRASS() : this crashes on the first attempt.


Test 2:
1-Running link2GI::linkOTB() 
2-Running initGRASS() n times: everything works fine n times
3-Running link2GI::linkOTB() 
4-Running initGRASS() : this crashes on the first attempt.


There is clearly a conflict between these two packages: running the command link2GI::linkOTB() seems to "break" the link made by rgrass7 between R and GRASS. 


So, I modified the code to prevent the problem from occurring during a second run of the 
script. But even though I had no problems since then, it's still a "band-aid on a 
wooden leg". It would be nice if Chris could find a solution to prevent linkOTB() 
from breaking the link between R and GRASS.

I hope this feedback is clear and remain at your disposal to complete this 
message if you would like more information.

Best regards,
Loïc



De : R-sig-Geo  de la part de Loïc Valéry 

Envoyé : mardi 7 juillet 2020 21:03
À : roger.biv...@nhh.no 
Cc : grass-user ; r-sig-...@r-project.org 

Objet : Re: [R-sig-Geo] [R] Need help using GRASS within R - error when running the script for a second time 
 

Dear Roger,

Sorry for cross-posting.
As you invite me, I'm going to post my case on 
https://github.com/rsbivand/rgrass7/issues.

Just a short comment to yours: if the reason you give is the right one, I don't 
understand why the script works the first time but not the second time. In your 
hypothesis, I guess it shouldn't work at all.

Best regards,
Loïc

De : Roger Bivand 
Envoyé : mardi 7 juillet 2020 20:20
À : Loïc Valéry 
Cc : Micha Silver ; r-sig-...@r-project.org 
; grass-user 
Objet : Re: [R-sig-Geo] [R] Need help using GRASS within R - error when running the script for a second time 
 
Please do not cross-post between lists, because few are likely to 
subscribe to both. Choose rather to post only to the list likely to 
include people using R and GRASS:


http://lists.osgeo.org/mailman/listinfo/grass-stats

Further, please post plain text only - I missed your earlier post to 
grass-user because it was scrubbed as HTML (or maybe Micha's reply).


Once resolved, you might report back on grass-user and R-sig-geo on the 
findings.


Briefly, it looks as though you are caught in the transition in sp/rgdal 
and sf from Proj4 to WKT2-2019 CRS, and similar changes in Grass. Grass 
7.8 and R packages may be installed with old PROJ/GDAL or new PROJ/GDAL. 
So far, nobody knows how to use g.proj and siblings sensibly in the R 
context. Most likely, using the wkt= parameter when the object in R has a 
WKT2 representation is going to be much more secure than passing a proj4= 
string, but wkt= takes a file name or standard input.


I would invite discussion in an issue on:

https://github.com/rsbivand/rgrass7/issues

with use cases (platform-independent).

Roger

On Tue, 7 Jul 2020, Loïc Valéry wrote:


Dear all,

As advised by Micha (FYI his reply is at the end of this email) , I 
contact you to submit an inextricable problem when using rgrass7 : the 
script (cf. just below) works the first time but, when I rerun it a 
second time, R and windows return error messages. For this to work, I 
must close and open R or use the rs.restartR() command from RStudio, 
which is not very convenient because it stops the script.


Many thanks in advance for your help.
Loïc


@Micha :  thank you very much for your reply. But I performed the tests

Re: [GRASS-user] [R-sig-Geo] [R] Need help using GRASS within R - error when running the script for a second time

2020-07-07 Thread Roger Bivand
atialPolygonsDataFrame
features    : 31
extent  : 477371.3, 477397.6, 5631995, 5632020  (xmin, xmax, ymin, ymax)
crs : +proj=utm +zone=32 +datum=WGS84 +units=m +no_defs
variables   : 1
names   : Seg_ID
min values  :  1
max values  : 31
Warning message:
In proj4string(x) : CRS object has comment, which is lost in output

# initialization of GRASS 7.8 from R
initGRASS(gisBase ="C:/Program Files/GRASS GIS 7.8", 
home="temp/GRASS",gisDbase="temp/GRASS", use_g.dirseps.exe=F,remove_GISRC=T, override=T)

gisdbase    temp/GRASS
location    file19685026c56
mapset  file196829fa7141
rows    1
columns 1
north   1
south   0
west    0
east    1
nsres   1
ewres   1
projection  NA

I suspect that the problem comes from 'projection NA' when initializing GRASS 
(cf. just above)

What you need to do here is setup the CRS of your new location.
Typically, you would run initGRASS and point to a *previously created* 
LOCATION, with CRS already defined. In this case, since you are creating
a new location, you must define it's coordinate system. (GRASS is very
"picky" about that).

Here's a GIS Stackexchange post that explains:

https://gis.stackexchange.com/questions/183032/create-a-new-grass-database-in-r-with-crs-projection


You can derive the full proj4 string from your sp object with:


p4str = sp::proj4string(seg_poly)


Then use that to set the project parameters for the new LOCATION, with

execGRASS("g.proj", flags = "c", proj4 = p4str) Now you should be able
to continue with...



execGRASS("v.generalize",flag=c("overwrite"),parameters=list(input="vec1",

+  
output="GRASS_smooth_seg_poly",
+  
error="GRASS_smooth_seg_poly_error",
+  
method="distance_weighting",
+  threshold=1))



As a novice in the field, I would be very grateful for your help.
I remain at your entire disposal for any further information you may need to 
help me in finding a solution to this problem.

Yours sincerely,
Loïc
__
r-h...@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.





--
Roger Bivand
Department of Economics, Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; e-mail: roger.biv...@nhh.no
https://orcid.org/-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0J=en___
grass-user mailing list
grass-user@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/grass-user

Re: [GRASS-user] rgrass7 syntax for passing a command

2016-04-29 Thread Roger Bivand
Simply, don't.

execGRASS() is for executing single GRASS commands, not a drop-in
replacement for bash.

Try something like creating the point in R with the correct projection, and
write that vector object to your mapset:

library(sp)
library(rgrass7)
pt <- SpatialPointsDataFrame(matrix(c(636645, 218835), ncol=2), 
  proj4string=CRS(paste(execGRASS("g.proj", flags="j", intern=TRUE),
collapse=" ")),
  data=data.frame(x=1))
writeVECT(pt, "outlet")

You could create a temporary text file to read in:

tf <- tempfile()
writeLines("636645, 218835", tf)
execGRASS("v.in.ascii", input=tf, output="outlet1", separator=",",
flags="n")

which is closer to your script but less natural.

Yes, grass-stats is a more appropriate list.
 
Roger




-
Roger Bivand
NHH Norwegian School of Economics, Bergen, Norway
--
View this message in context: 
http://osgeo-org.1560.x6.nabble.com/rgrass7-syntax-for-passing-a-command-tp5263330p5263427.html
Sent from the Grass - Users mailing list archive at Nabble.com.
___
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user

[GRASS-user] Re: Natural breaks classification

2012-05-18 Thread Roger Bivand
Since all Spatial*DataFrame objects behave link data.frame objects, you can
say:

DTM- readRAST6(DTM@mapset, ignore.stderr=TRUE)
DTM_class - classIntervals(DTM.df$varOfInterest, n=5, style=fisher)

However, if nrow(DTM) is large, you may find that the natural breaks
classifications take a lot of time, because the number of possible
alternative classifications to compare is very large. If you can reasonably
represent the distribution of your variable of interest by a sample, do
that, but add back the maximum and minimum values. Of course, in this case
you may get different class intervals for each sample.

In spearfish, I see:

 library(spgrass6)
 spear - readRAST6(c(geology, elevation.dem), cat=c(TRUE, FALSE),
+  useGDAL=TRUE)
 library(classInt)
 system.time(CI0 - classIntervals(spear$elevation.dem, n=5,
 style=fisher))
user   system  elapsed 
1151.1360.053 1153.775 
 nrow(spear)
[1] 294978
 CI0
style: fisher
  [1066,1221.5) [1221.5,1338.5) [1338.5,1472.5) [1472.5,1608.5)  
[1608.5,1840] 
  93972   60419   59562   45228  
33136 
 set.seed(1)

 system.time(CI1 - classIntervals(c(sample(na.omit(spear$elevation.dem),
 500), 
+ range(na.omit(spear$elevation.dem))), n=5, style=fisher))
   user  system elapsed 
  0.017   0.002   0.019 
 CI1
style: fisher
  [1066,1215.5) [1215.5,1322.5)   [1322.5,1450) [1450,1591)
[1591,1840] 
159 109  86  78 
70 
 table(findInterval(na.omit(spear$elevation.dem), CI0$brks,
 all.inside=TRUE))

1 2 3 4 5 
88747 59755 57077 47726 39012 

Or for more precision:

 set.seed(1)
 var_na - na.omit(spear$elevation.dem)
 mm_var - range(var_na)
 out - vector(mode=list, length=100)
 system.time(for (i in seq(along=out)) out[[i]] -
 classIntervals(c(sample(var_na, 500), mm_var), n=5, style=fisher))
   user  system elapsed 
  0.312   0.000   0.316 
 mbrks - sapply(out, [[, brks)
 str(mbrks)
 num [1:6, 1:100] 1066 1216 1322 1450 1591 ...
 apply(mbrks, 1, mean)
[1] 1066.000 1218.920 1337.745 1473.920 1612.390 1840.000

which gives a result very like the one using the complete data set but
taking over three orders of magnitude longer, using 100 samples of 500
raster cells each.

Hope this helps,

Roger



Salvatore Mellino wrote
 
 Hi,
 
 thanks a lot. Now the process started, but the operation DTM_class -
 classIntervals(DTM.df$varOfInterest, n=5, style=fisher takes too long;
 it was started by hours but does not end. Is it normal?
 
 Salvatore
 
 
 Il giorno 16/mag/2012, alle ore 22:04, Luigi Ponti ha scritto:
 
 On 16/05/2012 21:10, Luigi Ponti wrote:
 On 16/05/2012 20:55, Salvatore Mellino wrote:
 I'm trying but I receive an error.
 
 1. In R I started the libraries spgarass6 and classInt
 2. I imported the DTM in R using   DTM-
 readRAST6(DTM@mapset, ignore.stderr=TRUE)
 3. I used the commandDTM_class- classIntervals(DTM,
 n=5, style=fisher) and I received the error
 
 Error in classIntervals(DTM, n = 5, style = fisher) :
   var is not numeric
 
 I do not recall exactly, but it may be that classIntervals does not have
 a method for spatial data frames (i.e. the output of readRAST6). One
 thing I would try to get the breaks anyway, is a regular R data.frame,
 for example:
 
 DTM.df - as.data.frame(DTM)
 DTM_class - classIntervals(DTM.df, n=5, style=fisher)
 
 
 I am replying to myself as I may have omitted part of the answer -- my
 apologies. Start the same way:
 
DTM.df - as.data.frame(DTM)
 
 then get variable names:
 
names(deltaYieldVector.df)
 
 then use the variable of interest (altitude, I guess):
 
DTM_class - classIntervals(DTM.df$varOfInterest, n=5, style=fisher)
 
 This should work; we were feeding a data.frame as input to
 classIntervals, whereas a variable is needed (e.g. one of the variables
 in the data.frame).
 
 Let me know how it goes.
 
 Kind regards,
 
 Luigi
 
 
 ___
 grass-user mailing list
 grass-user@.osgeo
 http://lists.osgeo.org/mailman/listinfo/grass-user
 


--
View this message in context: 
http://osgeo-org.1560.n6.nabble.com/Natural-breaks-classification-tp4975148p4975552.html
Sent from the Grass - Users mailing list archive at Nabble.com.
___
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user


[GRASS-user] Re: spgrass6

2012-02-22 Thread Roger Bivand
Just 2k may mean 4 million rectangles. R display is vector, hard-copy, with
some recent support for raster grids when the rectangles are in fact square.
As has been said, the graphics engine is not designed for fast screen
output, but for scientific statistical graphics. 

spplot uses lattice graphics, which are slower anyway, but analytically more
powerful. For me running levelplot() - the internals of spplot - on a 2k by
2k matrix takes 2 seconds, but output to a png file using cairo takes 70
seconds. 

Using the improved raster graphics handling for square cells with image()
rather than spplot() and useRaster=TRUE - equivalent to
image.SpatialGridDataFrame() and useRasterImage=TRUE with the same matrix
takes 1.2 seconds on x11/cairo. You didn't say which version of R you are
using - the raster graphics facilities have been improved recently.

Did you try using image() instead of spplot() if your cells are square, and
if rasterImage() is available in your version of R?

Roger


Paolo Cavallini wrote
 
 Il 22/02/2012 12:21, Benjamin Ducke ha scritto:
 As opposed to GRASS, R has not been designed
 with computational and/or memory efficiency as a priority.
 Oh! I was not fully aware of this.
 Maybe your analysis would allow you to run your
 computations on a representative sample instead
 of the whole dataset?
 In our case, the analysis is vert simple: just ssplot() of a small (2k 
 by 2k cells) raster.
 Thanks.
 
 -- 
 Paolo Cavallini
 See: http://www.faunalia.it/pc
 
 ___
 grass-user mailing list
 grass-user@.osgeo
 http://lists.osgeo.org/mailman/listinfo/grass-user
 


--
View this message in context: 
http://osgeo-org.1560.n6.nabble.com/spgrass6-tp4494142p4495201.html
Sent from the Grass - Users mailing list archive at Nabble.com.
___
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user


[GRASS-user] Re: readVECT6 in R under GRASS

2011-10-24 Thread Roger Bivand
You need to provide a lot more information, including the messages displayed
when spgrass6 (and possibly rdgal) are loaded, and the output of
sessionInfo(). These will tell us which versions you are using. Then also
run:

execGRASS(g.list, parameters=list(type=vect))

to check that the vector object you think that you have is actually visible.
It may be in a mapset that is not on your search path.

Roger


Salvatore Mellino wrote:
 
 Hi,
 
 I'm trying to open a vector file (points) in GRASS with R. I used the
 following command:
 
 rain - readVECT6(rain_2010, ignore.stderr=TRUE)
 
 but I received the following message:
 
 
 Error in ogrInfo(dsn = dsn, layer = layer, input_field_name_encoding =
 input_field_name_encoding) : 
  Cannot open layer
 
 How can I fix the problem?
 
 Thanks.
 
 Salvatore
 
 
 ___
 grass-user mailing list
 grass-user@.osgeo
 http://lists.osgeo.org/mailman/listinfo/grass-user
 


-
Roger Bivand
Economic Geography Section
Department of Economics
Norwegian School of Economics and Business Administration
Helleveien 30
N-5045 Bergen, Norway

--
View this message in context: 
http://osgeo-org.1803224.n2.nabble.com/readVECT6-in-R-under-GRASS-tp6924585p6924616.html
Sent from the Grass - Users mailing list archive at Nabble.com.
___
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user


[GRASS-user] Re: Error running GRASS from R

2011-07-19 Thread Roger Bivand
There is a specific list for R/GRASS questions:
http://lists.osgeo.org/mailman/listinfo/grass-stats.

I don't know how you you started the R session. I hope you started R within
a running GRASS session, as you seem to be using an existing location. You
mention using initGRASS() which you should never do with an existing
location, unless you really know what you are doing. You do not say whether
you have also used the execGRASS() wrapper from R to run the other commands,
or whether these were run from the command line. More information is needed
- such as does the same script work locally, or when run without the remote
desktop access on the faster computer.

Roger



Tim Besser wrote:
 
 Dear GRASS-community,
 
 I have a very strange problem. I created a script in R (2.10.1) for the 
 preparation of my datasets which work fine on my laptop (winxp). I use 
 the spgrass6 package and GRASS 6.4.1. As the script would run for days 
 on my old laptop I now got a remote desktop connection to a much faster 
 computer at the university (win7). However, while cmds like r.reclass or 
 r.in.gdal work on that computer the r.patch cmd produces following error:
 
 execGRASS(r.patch, flags=c(z), 
 parameters=list(input=mangroves_1989_138_044_LR_recl,mangroves_1989_138_045_UL_recl,mangroves_1989_138_045_UR_recl,
  
 output=testomat), intern=T)
 
 Error in system(cmd0, intern = TRUE) :
Createprocess konnte 'C:\GRASS6~1.1\bin\RPATCH~1.EXE 
 --interface-description' nicht ausführen
 Fehler in parseGRASS(cmd) : r.patch not found
 
 I checked the GRASS directory and it is set right in the initGRASS
 command.
 
 I hope you can help me with one. I have no clue what to do!
 
 Thanks in advance,
 
 Tim
 
 
 
 ___
 grass-user mailing list
 grass-user@lists.osgeo.org
 http://lists.osgeo.org/mailman/listinfo/grass-user
 


-
Roger Bivand
Economic Geography Section
Department of Economics
Norwegian School of Economics and Business Administration
Helleveien 30
N-5045 Bergen, Norway

--
View this message in context: 
http://osgeo-org.1803224.n2.nabble.com/Error-running-GRASS-from-R-tp6598521p6599623.html
Sent from the Grass - Users mailing list archive at Nabble.com.
___
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user


[GRASS-user] Re: Installing spgrass6 package - Errors and warnings

2010-09-12 Thread Roger Bivand
... /usr/bin/pkg-config
 checking for xml2-config... no
 Cannot find xml2-config
 ERROR: configuration failed for package ‘XML’
 * removing ‘/usr/local/lib/R/site-library/XML’
 ERROR: dependencies ‘rgdal’, ‘XML’ are not available for package
 ‘spgrass6’
 * removing ‘/usr/local/lib/R/site-library/spgrass6’
 
 The downloaded packages are in
 ‘/tmp/RtmpP2fUan/downloaded_packages’
 Warning messages:
 1: In install.packages(spgrass6, dependencies = TRUE) :
   installation of package 'rgdal' had non-zero exit status
 2: In install.packages(spgrass6, dependencies = TRUE) :
   installation of package 'XML' had non-zero exit status
 3: In install.packages(spgrass6, dependencies = TRUE) :
   installation of package 'spgrass6' had non-zero exit status
 
 The result is I am not able to use spgrass.
 library(spgrass6)
 Error in library(spgrass6) : there is no package called 'spgrass6'
 
 As an intermediate level user in terms of commands and also regarding R
 and
 GRASS packages I am not able to decide what went wrong. Can you please
 help
 me out.
 
 Regards,
 
 Chethan S.
 
 ___
 grass-user mailing list
 grass-user@lists.osgeo.org
 http://lists.osgeo.org/mailman/listinfo/grass-user
 
 


-
Roger Bivand
Economic Geography Section
Department of Economics
Norwegian School of Economics and Business Administration
Helleveien 30
N-5045 Bergen, Norway

-- 
View this message in context: 
http://osgeo-org.1803224.n2.nabble.com/Installing-spgrass6-package-Errors-and-warnings-tp5522860p5523163.html
Sent from the Grass - Users mailing list archive at Nabble.com.
___
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user


[GRASS-user] Re: Download the new release 6.4.0

2010-09-12 Thread Roger Bivand

Hamish:

Are you (or more likely the OSGeo4W developers) aware of:

http://cran.r-project.org/doc/manuals/R-admin.html#Building-R-for-64_002dbit-Windows

which is now up and running nicely?

Roger


hamish-2 wrote:
 
 kapo coulibaly wrote:
 Is there a 64 bit version for windows?
 
 unfortunately not- until our build toolchain (minGW, Msys,
 osgeo4w) supports it, or we release grass 7 which is free
 from some of those shackles, we're pretty much stuck at 32
 bit on Windows. If you have to work with massive datasets,
 perhaps installing e.g. Ubuntu 64bit in a VirtualBox virtual
 machine inside Vista/Windows7 64 bit could get you going?(?)
 Either that or find a Mac or Linux to work on. :-/
 
 my guess is that mingw and co. will get 64 bit before
 too long though. obviously there's demand for it.
 
 
 Hamish
 
 
 
   
 ___
 grass-user mailing list
 grass-user@lists.osgeo.org
 http://lists.osgeo.org/mailman/listinfo/grass-user
 
 


-
Roger Bivand
Economic Geography Section
Department of Economics
Norwegian School of Economics and Business Administration
Helleveien 30
N-5045 Bergen, Norway

-- 
View this message in context: 
http://osgeo-org.1803224.n2.nabble.com/Download-the-new-release-6-4-0-tp5517558p5523173.html
Sent from the Grass - Users mailing list archive at Nabble.com.
___
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user


Re: [GRASS-user] Retaining holes in buffers

2010-01-26 Thread Roger Bivand

On Mon, 25 Jan 2010, Hamish wrote:


Roger wrote:

PS. Where is v.to.rast on the wx menu system?



in the wx GUI try:

Help - Show menu tree
 then
Search: [command]
 then type in v.to.rast



Regretably, on my 6.4.0RC5, there are only GRASS GIS Help, GRASS GIS GUI 
Help, and About GRASS GIS to choose from.




or have a look in the module synopsis PDF
 http://grass.osgeo.org/gdp/grassmanuals/grass64_module_list.pdf



Yes, that is: File  Map type conversions  Vector to raster

I'd been looking under Vector  for obvious reasons.

Thanks,

Roger



there is an open wish to add the menu location between the
option summary and the description.html part of the module help
pages. It's doable, it just takes some Makefile magic.



Hamish







--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: roger.biv...@nhh.no

___
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user


Re: [GRASS-user] R and GRASS-windows (readRAST6 problem, installation)

2009-11-02 Thread Roger Bivand

For questions of this kind, please use the statgrass list.

When you repeat your question on that list, please include sessionInfo()
with all information including your locale, and full GRASS details, that is
what GRASS version, how installed (there are many different variants, which
version of the standalone installer), how used (Rterm.exe, Rgui.exe, ...),
from which terminal R was started, and verbatim output of gmeta6().

Using spaces in path variables is never a good idea anyway, but it might be
possible to add an extra layer of protection. Without knowing your exact
system specifications will however make your report difficult to reproduce.

Roger



Martin Maier-2 wrote:
 
 Hello at all
 
 I use R to do statistics of some GRASS data. On the windows machines (XP
 and W2K) there occurred a problem when using the readRAST6 command form
 the spgrass6 library. I think the problem is linked to the standard
 installation of the GRASS standalone installer.
 
 The standalone installer creates a folder named GIS DataBase under My
 Documents. To test where the problem is, I moved the folder GIS
 DataBase to D:\
 
 Now I started R from within the new GRASS wxpython GUI. Within R I
 loaded spgrass6 (library(spgrass6)). Then the command readRAST6 fails.
 After renaming GIS DateBase to GISDataBase (and of course new start
 of GRASS and R) everything with the readRAST6 command works fine.
 
 So my guess is, that the readRAST6 command can not handle the blanks in
 the paths and on the other hand the installation of GRASS under windows
 with the standalone installer creates a default GIS database with a
 blank in the folder name. So probably it would be a good idea to change
 GIS DataBase to GISDataBase. But then there is still the blank in
 My Documents!
 
 Can anyone confirm this, and should I file a bug report?
 
 Martin
 ___
 grass-user mailing list
 grass-user@lists.osgeo.org
 http://lists.osgeo.org/mailman/listinfo/grass-user
 
 


-
Roger Bivand
Economic Geography Section
Department of Economics
Norwegian School of Economics and Business Administration
Helleveien 30
N-5045 Bergen, Norway

-- 
View this message in context: 
http://n2.nabble.com/R-and-GRASS-windows-readRAST6-problem-installation-tp3932646p3935041.html
Sent from the Grass - Users mailing list archive at Nabble.com.
___
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user


Re: [GRASS-user] R and GRASS (readVECT6 problem)

2009-10-29 Thread Roger Bivand

The last time this was seen, it was a locale problem. I heard today something
from that questioner, who asked on the more relevant statsgrass list. Try
setting your locale to an English one. I'll try to release the package with
a patch, although the original questioner did not report success (but that
could be because he was unable to install a source package).

Roger


Martin Maier-2 wrote:
 
 Hi,
 
 I am using the latest GRASS windows binary 
 (WinGRASS-6.4.0SVN-r39626-1-Setup.exe) on W2K. My R version is 2.9.2.
 After starting R from within GRASS, loading the library(spgrass6) it is 
 not possible to use the readVECT6 command (with the South-Dakota 
 dataset) in R:
 
   map - readVECT6(bugsites)
 Error in vInfo(vname) : Vector information not found
 
 readRAST6() and gmeta6() both works fine.
 Does anybody have the same error and can give a hint, why this error 
 occures?
 
 Martin
 ___
 grass-user mailing list
 grass-user@lists.osgeo.org
 http://lists.osgeo.org/mailman/listinfo/grass-user
 
 


-
Roger Bivand
Economic Geography Section
Department of Economics
Norwegian School of Economics and Business Administration
Helleveien 30
N-5045 Bergen, Norway

-- 
View this message in context: 
http://n2.nabble.com/R-and-GRASS-readVECT6-problem-tp3913174p3915521.html
Sent from the Grass - Users mailing list archive at Nabble.com.
___
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user


Re: [GRASS-user] problem on vectorizing a float point raster

2009-06-10 Thread Roger Bivand

I think that r.to.vect wants to build a line structure, like river channels,
but sees all the raster cells occupied, so no linear structure, and the
advice to thin first is then appropriate. If this is connected to your
question about calculating a measure of spatial autocorrelation for the
raster data, then I suspect that you do not need polygons but rather points,
where r.out.xyz may be helpful, followed by v.in.ascii if you will be using
GRASS downstream, or if you want to emit a shapefile for GeoDa (another
posting).

If you really want to calculate a measure of spatial autocorrelation for
your raster, I suggest copying the raster to R with readRAST6, creating the
neighbour list with dnearneigh() with max. distance the greater of ewres and
nsres, and proceeding from there in the usual way. But please consider the
inevitable fact that unless the resolution of your raster matches the
natural support of the phenomenon of interest, the observed
autocorrelation will certainly be driven by your having multiple
neighbouring observations of each entity, in addition to not having
demeaned (detrended) the data. This means that any results will almost
certainly be spurious.

Hope this helps,

Roger


Milton Cezar Ribeiro wrote:
 
 Dear Grass-Gurus,
 
 I have a 2400x2200 raster image with values ranging
 from 0.1 to 42, in float format. Now I need
 vetororize the image, on the way that each pixel
 come to be a polygon and the pixel value be stored as
 attribute.
 
 I am trying to do this using:
 r.to.vect input=temp71.img output=temp71_img_integer_vect_200m --o -b
 
 but grass return the following error messages:
 
 GRASS 6.4.0svn (newLocation):C:/GRASS-6-SVN/msys/home/mjfortin  r.to.vect
 inpu
 t=temp71.img output=temp71_img_integer_vect_200m --o -b
 WARNING: Vector map temp71_img_integer_vect_200m already exists and will
  be overwritten
 WARNING: Table temp71_img_integer_vect_200m linked to vector map
  temp71_img_integer_vect_200m does not exist
 Extracting lines...
 ERROR: Raster map is not thinned properly.
Please run r.thin.
 By the way, I am running grass under a WinXp 64bit.
 Any help are welcome.
 
 Cheers
 
 milton
 brazil=toronto
 
 ___
 grass-user mailing list
 grass-user@lists.osgeo.org
 http://lists.osgeo.org/mailman/listinfo/grass-user
 
 


-
Roger Bivand
Economic Geography Section
Department of Economics
Norwegian School of Economics and Business Administration
Helleveien 30
N-5045 Bergen, Norway

-- 
View this message in context: 
http://n2.nabble.com/problem-on-vectorizing-a-float-point-raster-tp3052124p3054013.html
Sent from the Grass - Users mailing list archive at Nabble.com.

___
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user


Re: [GRASS-user] problem on vectorizing a float point raster

2009-06-10 Thread Roger Bivand

The other thread was on the openspace list and was concerned with calculating
local Moran's Ii. My comments there copied here for completeness:

In your case, temperature will be being driven by altitude at least, and
possibly other important omitted variables. I also think that you will find
exploratory variography on the (detrended) data, or perhaps rather a sample
of the data (about 4M observations), might give some information. But I
don't think that squeezing your data into an inappropriate methods
setting is going to help much, and I'm pretty certain that just comparing
the output of a function of your input data and GRASS r.neighbors average
values for increasing values of the size parameter would be sufficient to
display the local dependence, most of which will still be driven by the
trend.

For example in spearfish:

g.region rast=elevation.dem
r.univar -g map=elevation.dem
# to get the mean and variance values
r.mapcalc 'demean_elev=elevation.dem-1353.66931789804'
r.neighbors -c input=demean_elev output=demean_elev3 method=average size=3
r.mapcalc 'Ii=(demean_elev*demean_elev3)/31343.402316476'

Then compare histograms and displays of Ii for increasing values of size.

Roger


Roger Bivand wrote:
 
 I think that r.to.vect wants to build a line structure, like river
 channels, but sees all the raster cells occupied, so no linear structure,
 and the advice to thin first is then appropriate. If this is connected to
 your question about calculating a measure of spatial autocorrelation for
 the raster data, then I suspect that you do not need polygons but rather
 points, where r.out.xyz may be helpful, followed by v.in.ascii if you will
 be using GRASS downstream, or if you want to emit a shapefile for GeoDa
 (another posting).
 
 If you really want to calculate a measure of spatial autocorrelation for
 your raster, I suggest copying the raster to R with readRAST6, creating
 the neighbour list with dnearneigh() with max. distance the greater of
 ewres and nsres, and proceeding from there in the usual way. But please
 consider the inevitable fact that unless the resolution of your raster
 matches the natural support of the phenomenon of interest, the observed
 autocorrelation will certainly be driven by your having multiple
 neighbouring observations of each entity, in addition to not having
 demeaned (detrended) the data. This means that any results will almost
 certainly be spurious.
 
 Hope this helps,
 
 Roger
 
 
 Milton Cezar Ribeiro wrote:
 
 Dear Grass-Gurus,
 
 I have a 2400x2200 raster image with values ranging
 from 0.1 to 42, in float format. Now I need
 vetororize the image, on the way that each pixel
 come to be a polygon and the pixel value be stored as
 attribute.
 
 I am trying to do this using:
 r.to.vect input=temp71.img output=temp71_img_integer_vect_200m --o -b
 
 but grass return the following error messages:
 
 GRASS 6.4.0svn (newLocation):C:/GRASS-6-SVN/msys/home/mjfortin 
 r.to.vect
 inpu
 t=temp71.img output=temp71_img_integer_vect_200m --o -b
 WARNING: Vector map temp71_img_integer_vect_200m already exists and
 will
  be overwritten
 WARNING: Table temp71_img_integer_vect_200m linked to vector map
  temp71_img_integer_vect_200m does not exist
 Extracting lines...
 ERROR: Raster map is not thinned properly.
Please run r.thin.
 By the way, I am running grass under a WinXp 64bit.
 Any help are welcome.
 
 Cheers
 
 milton
 brazil=toronto
 
 ___
 grass-user mailing list
 grass-user@lists.osgeo.org
 http://lists.osgeo.org/mailman/listinfo/grass-user
 
 
 
 


-
Roger Bivand
Economic Geography Section
Department of Economics
Norwegian School of Economics and Business Administration
Helleveien 30
N-5045 Bergen, Norway

-- 
View this message in context: 
http://n2.nabble.com/problem-on-vectorizing-a-float-point-raster-tp3052124p3054112.html
Sent from the Grass - Users mailing list archive at Nabble.com.

___
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user


[GRASS-user] Re: GRASS R : g.region command not found

2009-04-06 Thread Roger Bivand
Milton Cezar Ribeiro miltinho.astronauta at gmail.com writes:

 
 
 Dear all,
  
 I am running grass65 under MSYS under Vista.
 After launch MSYS  / GRASS / R, I get the information about
 mapset without problem. But as my raster image are very large,
 R can support the file. 
  
 But when I try run system(g.region ...) I get error on R.
 May be R can't get the PATH where the g.region command are.
  

You must add .exe to compiled commands, and .bat to scripts.

Wait for a forthcoming 0.6-* series spgrass6, which will automate some of 
this.

For questions like this, do use the statgrass list.

Roger

PS.

Don't use Windows if you need to do real work - there are so many binary GRASS 
versions that interfacing them all is a nightmare (see the pain on OSGEO4W)!


___
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user


Re: [GRASS-stats] Re: [GRASS-user] Testing i.pca ~ prcomp(), m.eigensystem ~ princomp()

2009-03-10 Thread Roger Bivand

On Tue, 10 Mar 2009, Nikos Alexandris wrote:


On Tue, 2009-03-03 at 14:26 +0100, Nikos Alexandris wrote:

On Tue, 2009-03-03 at 13:18 +0100, Markus Neteler wrote:

On Tue, Mar 3, 2009 at 12:26 PM, Hamish hamis...@yahoo.com wrote:
...


it will be really good to finally have all this documented.


I find it hard to follow these long mails. Why not enjoying the
GRASS Wiki to stabilize the documentation and comparisons?

Markus


Yes, why not? Hmmm, you mean to put these stuff already in the Wiki
before we are sure about the one last and very important variable
(=eigenvalues reported by  i.pca)?

Kind regards, Nikos


I've started the PCA grass-wiki page. I am trying to build it... step by
step. Expert advice is always welcome and highly appreciated.

http://grass.osgeo.org/wiki/Principal_Component_Analysis


Good, thanks. There you say that you are using some MODIS surface 
reflectance products. I guess it will be easier to check things if the 
data (GRASS location) are available, so that others can try the same 
calculations. Would it be possible to make one or more test sets 
available, and link them from thw Wiki?


Roger



Kind regards, Nikos

___
grass-stats mailing list
grass-st...@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-stats



--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: roger.biv...@nhh.no

___
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user


[GRASS-user] Re: Using R to check points in polygons does not work

2008-03-04 Thread Roger Bivand
Corrado ct529 at york.ac.uk writes:

 
 Dear friends,
 
 Platform: Ubuntu 7.10, Grass 6.2.3,PostgresSQL 8.2,R 2.6.2
 
 Yes, I am in a hurry. If I do not solve it by tomorrow, then it is back to 
 ARCGIS I am afraid. It is not my will, of course, but the project's leader is 
 already not keen on switching to GRASS, so she is pressing for me to solve it 
 using ARCGIS. :(

However it goes, good luck! In any case, please keep notes, because at speed
it's easy to mix up either species, or conservation areas (or both).

I'm pretty certain overlay() on the points and polygons will give you what you
need, first for the straight polygons, then for their buffers.

Roger




___
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user


Re: [GRASS-stats] Re: [GRASS-user] grass/stats mapping/prediction question

2007-12-19 Thread Roger Bivand

On Wed, 19 Dec 2007, Dylan Beaudette wrote:


On Wednesday 19 December 2007, Roger Bivand wrote:

On Wed, 19 Dec 2007, Daniel McInerney wrote:

The original questioner should have written to the grass-stats list in the

first place - thanks for CC-ing. See below for inline comments:

Hi Andy,


 I am unsure how to then move the 'outmap' back across to grass.
 How can i convert the df to a spatial grid object.


AFAIK, 'predict' won't create a dataframe object.
R should return FALSE for is.data.frame(outmap) and
TRUE for is.numeric(outmap)

You can slot the model output to the AttributeList of


It hasn't been an AttributeList for a long time - the data slot *is* a
data frame. We *always* need the output of sessionInfo() to help -
update.packages() is most often very helpful too.


one of the SpatialGridDataFrames that you created when
you read in a GRASS raster and then use writeRAST6 to
write it back to GRASS.

e.g. using 'anmax' from your example

anmax$anmax - outmap
#if that doesn't work, you might try
anmax$anmax - as.numeric(outmap)
writeRAST6(anmax, NameOfNewGRASSRaster, anmax)

Regards,
Daniel.

cc: [EMAIL PROTECTED]

andrew haywood wrote:

 Dear List,

 I am having some problems analysing some ecoligical models in grass
using the spgrass package through R.

 I have 130 plot locations where i have observed presence/absence of a
 species. I have followed a similar framework to the BUGSITE modelling
 example from Markus's 2003 grass gis handouts (Grass 5) I have no
 problems constructing the model based on the 130 plots and the
 environmental layers from grass.


See the OSGeo tutorial September 2006:

http://www.foss4g2006.org/contributionDisplay.py?contribId=46sessionId=59;
confId=1

and the OSGeo Journal note:

http://www.osgeo.org/files/journal/final_pdfs/OSGeo_vol1_GRASS-R.pdf

for more up-to-date information.


 However, I am having problems bringing all the maps through into R so I
 can make a prediction map.
 The region isnt too large 1600 by 800 cells at 10m resolution
 I can bring all the environmental layers through to R using readRAST6()
 which doesnt take too much time at all.

 However i assume I must convert the spatial grid objects into
dataframes to apply the predicted model function.


No, usually not at all, since the objects have a data.frame in the data
slot, and have the standard access methods.


 So I then coerce them into dataframes using as.dataframe (this takes
ages) I then merge all the dataframes into a single dataframe. (this
takes ages)

 I then apply the model predict to the new data frame.

 I am unsure how to then move the 'outmap' back across to grass.
 How can i convert the df to a spatial grid object.

 Im thinking i must be doing something wrong. As it quite quick to pull
 through the layers . But seems to take quite a lot of processing to get
 the layers into a datframe appropppriate for applying the predictions.

 Any help would be greatly appreciated.

 Andy


# pull through environmental layers
# FAST
 anmax - readRAST6(anmax, ignore.stderr=TRUE)
 anmin - readRAST6(anmin, ignore.stderr=TRUE)
 aspect - readRAST6(aspect, ignore.stderr=TRUE)
 dem10_lidar - readRAST6(dem10_lidar, ignore.stderr=TRUE)


Wrong, do:

mydata - readRAST6(c(anmax, anmin, aspect, dem10_lidar),
   ignore.stderr=TRUE)

then the data slot of the object is a data frame. Look at

summary(mydata)

for a sanity check.


# coerce to dataframe
# SLOW
 mypred_anmaxDF-as.data.frame(anmax)
 mypred_anminDF-as.data.frame(anmin)
 mypred_aspectDF-as.data.frame(aspect)
 mypred_dem10_lidarDF-as.data.frame(dem10_lidar)

# merge into single dataframe
# VERY SLOW
 merge_tmp-merge(mypred_anmaxDF,mypred_anminDF)
 rm(mypred_anmaxDF,mypred_anminDF)
 merge_tmp1-merge(merge_tmp,mypred_aspectDF)
 rm(merge_tmp,mypred_aspectDF)
 mypredDF-merge(merge_tmp1,mypred_dem10_lidarDF)

 #apply model


What is tree? You may need to do extra steps depending on what class(tree)
says - if you have used rpart() or some such, you may find that

outmap   - predict(tree,newdata=mydata, type=class)

works,

or

outmap   - predict(tree,newdata=as(mydata, data.frame), type=class)

Maybe just assign into mydata straight away:

mydata$outmap   - predict(tree,newdata=as(mydata, data.frame),
   type=class)

given ?predict.rpart saying:

If 'type=class': (for a classification tree) a factor of
classifications based on the responses.

which looks like a vector for a vector response in the formula to rpart().
But do check what happens if there are NA in the newdata, because the
default predict() behaviour may be to drop those observations. Look at
summary(mydata).

Some formula-using model fitting functions just work, like lm() and
the predict() method for lm objects.


From there, as Daniel wrote:


writeRAST6(mydata, rpartpred, outmap)

Hope this helps,

Roger


 outmap   - predict(tree,newdata=mypredDF, type=class)





An article on this in the OSGeo newsletter might be a nice way to document
simple modeling examples with GRASS and R

[GRASS-user] Re: Start R w/in Cygwin and Native WinGrass?

2007-12-05 Thread Roger Bivand
 paallen at attglobal.net writes:

 
 Hi all,
 
 I use window for my work computers so I have been using Grass under Cygwin and
the latest native WinGrass and R
 for windows.  By the way the WinGrass RC3 look GREAT
 
 I want to use the R package spgrass6.  Can/How do I start windows R within
cygwin and WinGrass?

Use a console interface - under cygwin I usually start an xterm within the GRASS
session, then start R within that (either Rgui or Rterm). You may need to set
.libPaths() within R, and may also need to check the working directory in Rgui,
depending on environment variable settings.

Roger


 
 Thanks
 
 Phil
 Sent via BlackBerry by ATT
 ___
 grass-user mailing list
 grass-user at lists.osgeo.org
 http://lists.osgeo.org/mailman/listinfo/grass-user
 
 




___
grass-user mailing list
grass-user@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/grass-user