import uk.ac.leeds.ccg.grids.*; import uk.ac.leeds.ccg.raster.*; import uk.ac.leeds.ccg.geotools.*; import uk.ac.leeds.ccg.geotools.classification.*; import uk.ac.leeds.ccg.widgets.*; import java.awt.*; import java.io.*; public class GenerateTestData { public GenerateTestData() { } /** * @param args the command line arguments */ public static void main(String[] args) { System.out.println( "GenerateTestData" ); long time = System.currentTimeMillis(); String dataDirectory1 = new String( "d:/andyt/data/TestData/Gridascii/" ); //String dataDirectory1 = new String( "d:/andyt/Projects/medaction/data/arc/corine/" ); File asciiFile1 = null; File asciiFile2 = null; File asciiFile3 = null; File tempGridFile = null; Grid2DSquareCellDoubleFactory f = new Grid2DSquareCellDoubleFactory(); Grid2DSquareCellDoubleFileFactory ff = new Grid2DSquareCellDoubleFileFactory(); AbstractGrid2DSquareCellDouble grid1 = null; AbstractGrid2DSquareCellDouble grid2 = null; AbstractGrid2DSquareCellDouble grid3 = null; int ncols = 0; int nrows = 0; double xllcorner = Double.MIN_VALUE; double yllcorner = Double.MIN_VALUE; double cellsize = Double.MIN_VALUE; double noDataValue = Double.MIN_VALUE; // Test Squares ncols = 100; nrows = 100; xllcorner = 0.0d; yllcorner = 0.0d; cellsize = 1.0d; noDataValue = -9999.0d; grid1 = f.createGrid2DSquareCellDouble( nrows, ncols, xllcorner, yllcorner, cellsize, noDataValue ); grid2 = f.createGrid2DSquareCellDouble( nrows, ncols, xllcorner, yllcorner, cellsize, noDataValue ); grid3 = f.createGrid2DSquareCellDouble( nrows, ncols, xllcorner, yllcorner, cellsize, noDataValue ); asciiFile1 = new File( new String( dataDirectory1 + "pit1.asc" ) ); asciiFile2 = new File( new String( dataDirectory1 + "pit2.asc" ) ); asciiFile3 = new File( new String( dataDirectory1 + "pit3.asc" ) ); for ( int i = 0; i < nrows; i ++ ) { for ( int j = 0; j < ncols; j ++ ) { grid1.addToCell( i, j, 1.0d ); grid2.addToCell( i, j, 1.0d ); grid3.addToCell( i, j, 1.0d ); } } for ( int i = 5; i < nrows - 5; i ++ ) { for ( int j = 5; j < ncols - 5; j ++ ) { grid1.addToCell( i, j, 1.0d ); grid2.addToCell( i, j, 1.0d ); grid3.addToCell( i, j, 1.0d ); } } for ( int i = 10; i < nrows - 10; i ++ ) { for ( int j = 10; j < ncols - 10; j ++ ) { grid1.addToCell( i, j, 1.0d ); grid2.addToCell( i, j, 1.0d ); grid3.addToCell( i, j, 1.0d ); } } for ( int i = 20; i < nrows - 20; i ++ ) { for ( int j = 20; j < ncols - 20; j ++ ) { grid3.addToCell( i, j, -0.1d ); grid2.addToCell( i, j, 1.0d ); } } for ( int i = 30; i < nrows - 30; i ++ ) { for ( int j = 30; j < ncols - 30; j ++ ) { //grid1.addToCell( i, j, 1.0d ); grid2.addToCell( i, j, 1.0d ); grid3.addToCell( i, j, 1.0d ); } } for ( int i = 40; i < nrows - 30; i ++ ) { for ( int j = 40; j < ncols - 30; j ++ ) { //grid1.addToCell( i, j, 1.0d ); grid2.addToCell( i, j, 1.0d ); grid3.addToCell( i, j, 1.0d ); } } grid1.toAsciiFile( asciiFile1 ); grid2.toAsciiFile( asciiFile2 ); grid3.toAsciiFile( asciiFile3 ); /* Test drainage catchment ncols = 100; nrows = 100; xllcorner = 0.0d; yllcorner = 0.0d; cellsize = 1.0d; noDataValue = -9999.0d; grid1 = f.createGrid2DSquareCellDouble( nrows, ncols, xllcorner, yllcorner, cellsize, noDataValue ); grid2 = f.createGrid2DSquareCellDouble( nrows, ncols, xllcorner, yllcorner, cellsize, noDataValue ); grid3 = f.createGrid2DSquareCellDouble( nrows, ncols, xllcorner, yllcorner, cellsize, noDataValue ); asciiFile1 = new File( new String( dataDirectory1 + "s1.asc" ) ); asciiFile2 = new File( new String( dataDirectory1 + "s2.asc" ) ); asciiFile3 = new File( new String( dataDirectory1 + "s3.asc" ) ); for ( int i = 0; i < nrows; i ++ ) { for ( int j = 0; j < ncols; j ++ ) { grid1.addToCell( i, j, 1.0d ); grid2.addToCell( i, j, 0.0d ); grid3.addToCell( i, j, 0.0d ); } } for ( int i = 40; i < nrows - 40; i ++ ) { for ( int j = 40; j < ncols - 40; j ++ ) { grid3.addToCell( i, j, 1.0d ); } } for ( int i = 20; i < nrows - 20; i ++ ) { for ( int j = 20; j < ncols - 20; j ++ ) { grid1.addToCell( i, j, -1.0d ); grid2.addToCell( i, j, 1.0d ); grid3.addToCell( i, j, 0.0d ); } } grid1.toAsciiFile( asciiFile1 ); grid2.toAsciiFile( asciiFile2 ); grid3.toAsciiFile( asciiFile3 ); */ time = System.currentTimeMillis() - time; int hours = ( int ) Math.floor( time / 3600000.0d ); int mins = ( int ) Math.floor( ( time - ( 3600000.0d * hours ) ) / 60000.0d ) ; int secs = ( int ) Math.floor( ( time - ( 3600000.0d * hours ) - ( 60000.0d * mins ) ) / 1000.0d ) ; int milisecs = ( int ) Math.floor( ( time - ( 3600000.0d * hours ) - ( 60000.0d * mins ) ) - ( 1000.0d * secs ) ); System.out.println( "Processing complete in " + hours + " hours, " + mins + " mins, " + secs + " secs, " + milisecs + " milisecs" ); //System.out.println( "Processing complete in " + time + " ms" ); //File displayFile = null; File displayFile = asciiFile1; // Display results boolean displayResult = true; //boolean displayResult = false; if ( displayResult ) { // Display GeometricDensity output as a raster on screen // Get output try { Raster r2 = new Raster( displayFile.toString() ); r2.setMissingValueCode(-9999.0d); System.out.println("(min,max)=("+r2.getMin()+","+r2.getMax()+")"); // Set Frame Frame frame2 = new Frame(); frame2.setLayout(new BorderLayout()); // Set RasterLayer RasterLayer rl1 = new RasterLayer(r2); // Set a Shader and Key //HSVShader hsvs1 = new HSVShader(Color.black,Color.red,true); //hsvs1.setMissingValueColor(Color.white); //hsvs1.setMissingValueCode((double)r1.getMissingValueCode()); //hsvs1.setRange(r1.getMin()+r1.getTol()+(r1.getMax()-r1.getMin())/100.0d,r1.getMax()); //t1.setShader(hsvs1); //Key k1=hsvs1.getKey(); //ClassificationShader cs1=new ClassificationShader(r2,6,ClassificationShader.QUANTILE); ClassificationShader cs1 = new ClassificationShader( r2, 4, ClassificationShader.EQUAL_INTERVAL ); cs1.setRange( r2.getMin(), r2.getMax() ); cs1.setMissingValueColor( Color.white ); Key k1 = cs1.getKey(); // Add key to frame frame2.add(k1,"East"); // Set theme Theme t1=new Theme(rl1,cs1); // Set viewer Viewer v1=new Viewer(); v1.setBackground(Color.white); v1.addTheme(t1); // Add viewer to theme frame2.add(v1,"Center"); // Set Toolbar ToolBar tb1=new ToolBar(v1); // Add Toolbar to frame frame2.add(tb1,"South"); // Display frame frame2.pack(); frame2.setVisible(true); // Annonymous inner class set up for closing frame. frame2.addWindowListener(new java.awt.event.WindowAdapter(){ public void windowClosing(java.awt.event.WindowEvent e){ System.exit(0); } }); } catch ( java.io.IOException e ) { System.out.println( e + " in GenerateTestData display" ); } } } }