Jon Aquino's Mental Garden

Engineering beautiful software jon aquino labs | personal blog

Wednesday, November 10, 2004

BeanShell to turn a session back into a source package


{
zip = "c:/junk3/a.zip";
import com.vividsolutions.jcs.plugin.conflate.roads.*;
import com.vividsolutions.jump.workbench.ui.plugin.*;
import com.vividsolutions.jump.util.*;
import com.vividsolutions.jcs.jump.*;
FeatureCollection nodeConstraints(network) {
nodeConstraints = AddNewLayerPlugIn.createBlankFeatureCollection();
for (segment : network.graph.edges) {
if (segment.startNodeConstrained) {
nodeConstraints.add(FeatureUtil.toFeature(new GeometryFactory().createPoint(segment.startNode.coordinate), nodeConstraints.featureSchema));
}
if (segment.endNodeConstrained) {
nodeConstraints.add(FeatureUtil.toFeature(new GeometryFactory().createPoint(segment.endNode.coordinate), nodeConstraints.featureSchema));
}
}
return nodeConstraints;
}
temporaryDirectory = FUTURE_FileUtil.createTemporaryDirectory();
session = ToolboxModel.instance(wc).session;
n0 = session.getSourceNetwork(0).name;
n1 = session.getSourceNetwork(1).name;
new ResultPackageExporter().saveShapefile(session.getSourceNetwork(0).featureCollection, new File(temporaryDirectory+"/"+n0+".shp"), null);
new ResultPackageExporter().saveShapefile(session.getSourceNetwork(1).featureCollection, new File(temporaryDirectory+"/"+n1+".shp"), null);
new ResultPackageExporter().saveShapefile(session.getContextFeatureCollection(0), new File(temporaryDirectory+"/"+n0+"Context.shp"), null);
new ResultPackageExporter().saveShapefile(session.getContextFeatureCollection(1), new File(temporaryDirectory+"/"+n1+"Context.shp"), null);
new ResultPackageExporter().saveShapefile(nodeConstraints(session.getSourceNetwork(0)), new File(temporaryDirectory+"/"+n0+"NodeConstraints.shp"), null);
new ResultPackageExporter().saveShapefile(nodeConstraints(session.getSourceNetwork(1)), new File(temporaryDirectory+"/"+n1+"NodeConstraints.shp"), null);
new SaveProfileAsPlugIn().saveAs(new File(temporaryDirectory+"/x.rmprofile"), null, wc.createPlugInContext());
FileUtil.setContents(temporaryDirectory+"/manifest.xml",
"\n"+
"\n"+
" \n"+
" "+n0+"\n"+
" \n"+
" "+n0+".shp\n"+
" shape\n"+
" \n"+
" \n"+
" "+n0+"NodeConstraints.shp\n"+
" shape\n"+
"
\n"+
" \n"+
" "+n0+"Context.shp\n"+
" shape\n"+
"
\n"+
"
\n"+
" \n"+
" "+n1+"\n"+
" \n"+
" "+n1+".shp\n"+
" shape\n"+
" \n"+
" \n"+
" "+n1+"NodeConstraints.shp\n"+
" shape\n"+
"
\n"+
" \n"+
" "+n1+"Context.shp\n"+
" shape\n"+
"
\n"+
"
\n"+
"
");
FUTURE_FileUtil.zip(temporaryDirectory.listFiles(), new File(zip), -1, null);
}

0 Comments:

Post a Comment

<< Home