I can not get this for loop to run in GME because i is being changed to 1 and , out is not recognized: wd <- "C:\Users\name\Desktop\KDE2011円\"; for (i in 1:15) { kde(in="C:\Users\name\Desktop\KDE\first15clip.shp"), out=paste(wd, "kde_p", 1, ".img"), bandwidth=1000, cellsize=10, where=paste("PName_ID=", 1)); }
Warning: An unexpected command argument was encountered: , out. The tool will attempt to run anyway, but may not produce the output you intended it to. Please check the results carefully. WHERE clause: PName_ID=1 Error: The command text could not be interpreted. Please check the syntax of the command. Error: An important error has occurred. Please include the information below if you submit a query about this error. Length cannot be less than zero. Parameter name: length
Any ideas on how to fix this so the loop runs?
1 Answer 1
You are using R syntax, why not just do this in R? Anyway, I have no idea how GME is parsing to R but from an syntax standpoint your backslashes either need to be double ("\") or single forward slashes ("/").
I believe that your actual issue is that you need a separator argument in the paste function. The way you have it now is creating a space between the two strings.
inpath <- "C:/Users/name/Desktop/KDE/"
paste(inpath, "first15clip.shp")
Which results in: "C:/Users/name/Desktop/KDE/ first15clip.shp"
As opposed to:
paste(inpath, "first15clip.shp", sep="")
Which results in: "C:/Users/name/Desktop/KDE/first15clip.shp"
Your "out" argument will cause you issues as well. If you run it as it is, with i=1, it would look like this: "C:/Users/name/Desktop/KDE/2011/ kde_p 1 .img"
This syntax:
outpath <- "C:/Users/name/Desktop/KDE/2011/"
paste(outpath, paste("kde_p", i, ".img", sep=""), sep="")
results in : "C:/Users/name/Desktop/KDE/2011/kde_p1.img"
-
This is GME's example for writing a for loop in GME:EJrandom– EJrandom2015年01月09日 19:53:57 +00:00Commented Jan 9, 2015 at 19:53
-
inpath <- "C:\data\" outpath <- "C:\output\" for (i in 1001:1010) { for (j in 1:12) { kde(in=paste(inpath, "telemetry.shp"), out=paste(outpath, "kde an", i, " m", j, ".img"), bandwidth=1000, cellsize=r.eval((250000-120000)/2000), where=paste("ANIMALID=", i, " AND MONTH=", j)); }; };EJrandom– EJrandom2015年01月09日 19:55:14 +00:00Commented Jan 9, 2015 at 19:55
-
when I try it with my Pname_ID replacing ANIMALID:EJrandom– EJrandom2015年01月09日 19:56:14 +00:00Commented Jan 9, 2015 at 19:56
-
inpath <- "C:\Users\ejraynor\Desktop\KDE\"outpath <- "C:\Users\ejraynor\Desktop\KDE2011円\"for (i in 1:15); kde(in=paste(inpath, "first15clip.shp", sep=""), out=paste(outpath, "kde_p_", i, ".img"), bandwidth=1000, cellsize=10, where=paste("PName_ID=", i)); Error: The default input/output working folders have not been specified, therefore not enough information has been supplied to open the specified data source Error: Could not open input point data source.EJrandom– EJrandom2015年01月09日 19:56:37 +00:00Commented Jan 9, 2015 at 19:56
-
1In looking at the ked and for help, your syntax is correct. Have you tried the kde syntax outside of the for loop? Perhaps contact the developer Hawth Beyer. You should be aware that GME is mostly just calling R. The for loop syntax you have is the exactly the same as what you would specify in R and, since R packages are moving at a much faster pace than GME, which is not leveraging improvements in R spatial classes, it seems prudent to just learn and use R. For a density analysis a good place to start would be the ppp.density function in spatstat.Jeffrey Evans– Jeffrey Evans2015年01月09日 21:48:32 +00:00Commented Jan 9, 2015 at 21:48