0

I am using the isectpolypoly command in GME and would like to iterate over several polygons ("proj_0_ect0207", "proj_1_ect0207"). My code is as follows:

for (i in 0:30) 
{

isectpolypoly(in="F:\Users\p3\ResidentialShapefile\Britain_BNG.shp",poly=
("F:\Users\p3\new.gdb!"Pro_",[i],"_ject0207"), field="GRIDCODE", prefix=[i],    
thematic=FALSE, proportion=FALSE, awm=TRUE, min=FALSE, max=FALSE, aws=FALSE);

};

I keep getting the error:

Error: For loop commands must be contained within a pair of braces: { }.

I'm following guidance from http://www.spatialecology.com/gme/for.htm

Any help appreciated...

Cheers

  • 3
    If this is supposed to be R code, you have several syntax errors. Post notably, you should look up paste and also not enclose i in square brackets. – Ari B. Friedman Nov 27 '13 at 12:42
  • Thanks, I've refined the code: wd<-("F:\Users\p3\new.gdb!") for (i in 0:30) { isectpolypoly(in="F:\Users\p3\ResidentialShapefile\Britain_BNG. shp",poly= (paste(wd, "Pro_",i,"_ject0206"), field="GRIDCODE", prefix=i, thematic=FALSE, proportion=FALSE, awm=TRUE, min=FALSE, max=FALSE, aws=FALSE) }; but get this error now: Error: Incorrectly formulated expression; command cannot be interpreted ... think it's closer to working though ha – Marko Nov 27 '13 at 13:29
  • 1
    Please edit your question with the code--what you posted in the comment is unreadable.... – Ari B. Friedman Nov 27 '13 at 13:41
  • try: 1. removing the space between Britain_BNG. and shp; 2. remove ( in front of paste; 3. if it still fails after that, try adding sep="" in the paste argument paste(wd, "Pro_",i,"_ject0206", sep="") and maybe prefix=paste("x",i) so that the prefix does not start w/ a number. – mwil Nov 27 '13 at 15:17
  • 1
    You may want to check that GRIDCODE is numeric because the index you are calling is. You should just implement this directly in R. The code behind GME is not using the recent addition of the java GEOS topology library for things like intersect functions. This type of operator should be done in rgeos. This particular function could also be easily replicated using the over function in sp within a similar for loop. I do not understand the logic of using a commanndline interface for a commandline software. – Jeffrey Evans Nov 27 '13 at 18:47
1

Thanks for everyone's input. I've reached a solution with a mixture of your advice, using paste and removing the (. The following code works:

wd<-"F:\Users\p3\new.gdb!";
for (i in 0:30);
{ 
isectpolypoly(in="F:\Users\p3\ResidentialShapefile\Britain_BNG. shp",
poly=paste(wd,"Proj_",i,"_ect0206"), 
field=“GRIDCODE”, 
prefix=i, 
thematic=FALSE, proportion=FALSE, awm=TRUE, min=FALSE, max=FALSE, aws=FALSE) 
};
  • If GME is calling R's paste function you need a sep argument. Otherwise, you just have a name with spaces. If you use sep="_" you do not need the underscores in your syntax. – Jeffrey Evans Nov 27 '13 at 22:10
  • I don't believe you. That code can't work - the semicolon after for (i in 0:30) breaks it. R doesn't need semicolons at line ends, and in this case it breaks the for loop. Also you've got a space in your filename which I guess isn't really there. Don't say "this code works" unless this exact code works. – Spacedman Dec 5 '13 at 10:18
  • Just to clarify... I'm working within the GME GUI. The command above does work when copied and pasted into the 'Command Text' section. – Marko Dec 6 '13 at 13:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.