/** * Example use of uk.ac.leeds.ccg.andyt.gws.core * Copyright (C) 2005 Andy Turner, CCG, University of Leeds, UK. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ package uk.ac.leeds.ccg.andyt.gws.examples; // java dependencies import java.awt.geom.Point2D; import java.io.File; import java.math.BigDecimal; // uk.ac.leeds.ccg.andyt.grids dependencies import uk.ac.leeds.ccg.andyt.grids.core.Grid2DSquareCellDouble; import uk.ac.leeds.ccg.andyt.grids.core.Grid2DSquareCellDoubleFactory; import uk.ac.leeds.ccg.andyt.grids.exchange.ESRIAsciiGridExporter; //import uk.ac.leeds.ccg.andyt.grids.util.Utilities; // uk.ac.leeds.ccg.andyt.gws dependencies import uk.ac.leeds.ccg.andyt.gws.core.FixedGWS; import uk.ac.leeds.ccg.andyt.gws.utilities.Utilities; /** * TODO: * docs */ public class FixedGWSRuns { long time; /** Creates a new instance of GWSRunner */ public FixedGWSRuns() { } /** * @param args the command line arguments */ public static void main(String[] args) { FixedGWSRuns fgws = new FixedGWSRuns(); fgws.run(); } public void run() { System.out.println( "Initialising ..." ); time = System.currentTimeMillis(); //run0(); run1(); System.out.println( "Processing complete in " + uk.ac.leeds.ccg.andyt.grids.utilities.Utilities.time( System.currentTimeMillis() - time ) ); } public void run0() { // Initialisation FixedGWS fgws = new FixedGWS(); String dataDirectory = "C:/Work/Projects/PhD/Data/XY/GB"; String outDataDirectory = "C:/Work/Projects/PhD/Data/GWS/FixedKernel0"; Grid2DSquareCellDoubleFactory grid2DSquareCellDoubleFactory = new Grid2DSquareCellDoubleFactory(); BigDecimal[] dimensions = new BigDecimal[ 5 ]; // Cellsize dimensions[ 0 ] = new BigDecimal( "20" ); double cellsize = dimensions[ 0 ].doubleValue(); double noDataValue = -9999.0d; // // Define Study Area // // Leeds - Bradford Region // String region = "lb"; // long nrows = 2375L; // long ncols = 2685L; // dimensions[ 1 ] = new BigDecimal( "403200" ); // dimensions[ 2 ] = new BigDecimal( "412600" ); // // Leeds City Centre // String region = "lcc"; // long nrows = 200L; // long ncols = 250L; // dimensions[ 1 ] = new BigDecimal( "428000" ); // dimensions[ 2 ] = new BigDecimal( "432000" ); // Test String region = "test"; long nrows = 60L; long ncols = 50L; dimensions[ 1 ] = new BigDecimal( "428000" ); dimensions[ 2 ] = new BigDecimal( "432000" ); BigDecimal nrowsBigDecimal = new BigDecimal( nrows ); BigDecimal ncolsBigDecimal = new BigDecimal( ncols ); dimensions[ 3 ] = dimensions[ 1 ].add( dimensions[ 0 ].multiply( ncolsBigDecimal ) ); dimensions[ 4 ] = dimensions[ 2 ].add( dimensions[ 0 ].multiply( nrowsBigDecimal ) ); // Generate input Grid2DSquareCellDouble grid2DSquareCellDouble = grid2DSquareCellDoubleFactory.createGrid2DSquareCellDouble( nrows, ncols, dimensions, noDataValue ); int distanceFactor = 2; double weightIntersect = 1.0d; double weightFactor = 1.0d; double distance; File output = null; for ( int distances = 2; distances <= 4; distances *= 2 ) { distance = cellsize * distances; for ( int i = 0; i < 2; i ++ ) { Point2D.Double[] t0Points = null; if ( i == 0 ) { //t0Points = Utilities.loadData( new File( dataDirectory, "92Fatalxy.csv" ) ); //t0Points = Utilities.loadData( t0Points, new File( dataDirectory, "93Fatalxy.csv" ) ); //t0Points = Utilities.loadData( t0Points, new File( dataDirectory, "94Fatalxy.csv" ) ); //t0Points = Utilities.loadData( t0Points, new File( dataDirectory, "95Fatalxy.csv" ) ); //t0Points = Utilities.loadData( t0Points, new File( dataDirectory, "96Fatalxy.csv" ) ); //output = new File( outDataDirectory, "Fatal_9296_" + distances + ".asc" ); t0Points = Utilities.loadData( new File( dataDirectory, "acc92xy.csv" ) ); t0Points = Utilities.loadData( t0Points, new File( dataDirectory, "acc93xy.csv" ) ); t0Points = Utilities.loadData( t0Points, new File( dataDirectory, "acc94xy.csv" ) ); t0Points = Utilities.loadData( t0Points, new File( dataDirectory, "acc95xy.csv" ) ); t0Points = Utilities.loadData( t0Points, new File( dataDirectory, "acc96xy.csv" ) ); output = new File( outDataDirectory, "All_9296_" + distances + ".asc" ); } if ( i == 1 ) { t0Points = Utilities.loadData( new File( dataDirectory, "acc97xy.csv" ) ); t0Points = Utilities.loadData( t0Points, new File( dataDirectory, "acc98xy.csv" ) ); t0Points = Utilities.loadData( t0Points, new File( dataDirectory, "acc99xy.csv" ) ); t0Points = Utilities.loadData( t0Points, new File( dataDirectory, "acc00xy.csv" ) ); t0Points = Utilities.loadData( t0Points, new File( dataDirectory, "acc01xy.csv" ) ); output = new File( outDataDirectory, "All_9701_" + distances + ".asc" ); } Grid2DSquareCellDouble kernelWeightsInDistanceGrid = fgws.getKernelWeightsInDistance( t0Points, grid2DSquareCellDouble, distance, weightIntersect, weightFactor ); System.out.println( kernelWeightsInDistanceGrid.toString() ); new ESRIAsciiGridExporter().toAsciiFile( kernelWeightsInDistanceGrid, output ); } } } public void run1() { FixedGWS fgws = new FixedGWS(); String dataDirectory = "C:/Work/Projects/PhD/Data/XY/GB"; String outDataDirectory = "C:/Work/Projects/PhD/Data/GWS/FixedKernel0"; File workspace = new File( "C:/Work/Projects/PhD/Workspace" ); Grid2DSquareCellDoubleFactory grid2DSquareCellDoubleFactory = new Grid2DSquareCellDoubleFactory( workspace ); BigDecimal[] dimensions = new BigDecimal[ 5 ]; // Cellsize //dimensions[ 0 ] = new BigDecimal( "20" ); dimensions[ 0 ] = BigDecimal.TEN; double cellsize = dimensions[ 0 ].doubleValue(); double noDataValue = -9999.0d; // Define Study Area // // Leeds - Bradford Region // String region = "lb"; // long nrows = 2375L * 2L; // long ncols = 2685L * 2L; // dimensions[ 1 ] = new BigDecimal( "403205" ); // dimensions[ 2 ] = new BigDecimal( "412605" ); // dimensions[ 1 ] = new BigDecimal( "403200" ); // dimensions[ 2 ] = new BigDecimal( "412600" ); // Leeds City Centre String region = "lcc"; long nrows = 400L; long ncols = 500L; dimensions[ 1 ] = new BigDecimal( "428005" ); dimensions[ 2 ] = new BigDecimal( "432005" ); //dimensions[ 1 ] = new BigDecimal( "428000" ); //dimensions[ 2 ] = new BigDecimal( "432000" ); // // Test // String region = "test"; // long nrows = 60L; // long ncols = 50L; // dimensions[ 1 ] = new BigDecimal( "428000" ); // dimensions[ 2 ] = new BigDecimal( "432000" ); BigDecimal nrowsBigDecimal = new BigDecimal( nrows ); BigDecimal ncolsBigDecimal = new BigDecimal( ncols ); dimensions[ 3 ] = dimensions[ 1 ].add( dimensions[ 0 ].multiply( ncolsBigDecimal ) ); dimensions[ 4 ] = dimensions[ 2 ].add( dimensions[ 0 ].multiply( nrowsBigDecimal ) ); // Generate input Grid2DSquareCellDouble grid2DSquareCellDouble = grid2DSquareCellDoubleFactory.createGrid2DSquareCellDouble( nrows, ncols, dimensions, noDataValue ); // Set Kernel Parameters double weightIntersect = 1.0d; double weightFactor = 1.0d; double maxNrowsNcols = Math.max( nrows, ncols ); //int divisions = 2; int divisions = 10; double distance; //int distanceFactor = ( int ) Math.ceil( maxNrowsNcols / Math.pow( 2, divisions ) ); int distanceFactor = 10; System.out.println( "distance factor " + distanceFactor ); for ( int i = 0; i < 2; i ++ ) { Point2D.Double[] t0Points = null; File output = null; if ( i == 1 ) { //t0Points = Utilities.loadData( new File( dataDirectory, "92Fatalxy.csv" ) ); //t0Points = Utilities.loadData( t0Points, new File( dataDirectory, "93Fatalxy.csv" ) ); //t0Points = Utilities.loadData( t0Points, new File( dataDirectory, "94Fatalxy.csv" ) ); //t0Points = Utilities.loadData( t0Points, new File( dataDirectory, "95Fatalxy.csv" ) ); //t0Points = Utilities.loadData( t0Points, new File( dataDirectory, "96Fatalxy.csv" ) ); //output = new File( outDataDirectory, "Fatal_9296_" + distances + ".asc" ); t0Points = Utilities.loadData( new File( dataDirectory, "acc92xy.csv" ) ); t0Points = Utilities.loadData( t0Points, new File( dataDirectory, "acc93xy.csv" ) ); t0Points = Utilities.loadData( t0Points, new File( dataDirectory, "acc94xy.csv" ) ); t0Points = Utilities.loadData( t0Points, new File( dataDirectory, "acc95xy.csv" ) ); t0Points = Utilities.loadData( t0Points, new File( dataDirectory, "acc96xy.csv" ) ); } if ( i == 0 ) { t0Points = Utilities.loadData( new File( dataDirectory, "acc97xy.csv" ) ); t0Points = Utilities.loadData( t0Points, new File( dataDirectory, "acc98xy.csv" ) ); t0Points = Utilities.loadData( t0Points, new File( dataDirectory, "acc99xy.csv" ) ); t0Points = Utilities.loadData( t0Points, new File( dataDirectory, "acc00xy.csv" ) ); t0Points = Utilities.loadData( t0Points, new File( dataDirectory, "acc01xy.csv" ) ); } System.out.println( "Number of points : " + t0Points.length ); //int distances = 4; for ( int distances = 2; distances <= 512; distances *= 2 ) { // 4,8,16,32,64,128,256,512,1024,2048 = 10 iterations distance = cellsize * distances; if ( i == 1 ) { output = new File( outDataDirectory, "All_9296_" + distances + ".asc" ); } else { output = new File( outDataDirectory, "All_9701_" + distances + ".asc" ); } Grid2DSquareCellDouble kernelWeightsInDistanceGrid = fgws.getKernelWeightsInDistance( divisions, t0Points, grid2DSquareCellDouble, distance, weightIntersect, weightFactor, distanceFactor ); System.out.println( kernelWeightsInDistanceGrid.toString() ); new ESRIAsciiGridExporter().toAsciiFile( kernelWeightsInDistanceGrid, output ); } } } }