Jon Aquino's Mental Garden

Engineering beautiful software jon aquino labs | personal blog

Friday, December 03, 2004

RE: BeanShell Script for Roadmatcher

Hi Chris:
 
BeanShell can be the same as Java. But it also allows shortcuts, most notably: omitting the type declaration. Example:
 
    String x = "Hello World";
 
is the same as:
 
    x = "Hello World";
 
Here's how to change all the TRIM segment comments to "ABC":
 
{   
  for (feature : wc.getLayerManager().getLayer("Network TRIM").getFeatureCollectionWrapper().getFeatures()) {
    feature.getRoadSegment().setComment("ABC");
  }
}
 
I've enclosed everything with { and } because I find that the BeanShell editor that JUMP uses sometimes freezes otherwise :-(
 
Here's how to change all the TRIM segment comments to "Long Road" if the length > 2000:
 
{   
  for (feature : wc.getLayerManager().getLayer("Network TRIM").getFeatureCollectionWrapper().getFeatures()) {
    if (feature.getRoadSegment().getApparentLineLength() <= 2000) { continue; }
    feature.getRoadSegment().setComment("Long Road");
  }
}
 
Note the use of the "enhanced for loop" - a Java 1.5 thing, but BeanShell lets you use it in any version of Java :-)
 
 
OK time for the issue log.
 
Here's how to change all the issue log descriptions to "Dell Axim X30":
 
{   
  for (feature : wc.getLayerManager().getLayer("Issue Log").getFeatureCollectionWrapper().getFeatures()) {
    feature.setAttribute("Desc", "Dell Axim X30");
  }
}
 
Hope that helps!
 
 
 


0 Comments:

Post a Comment

<< Home