package phd; /** * This file is distributed as part of the uk.ac.leeds.ccg.grids library * This library is a resource for manipulating spatial data stored as grids. * Copyright (C) 2002 Andy Turner * * 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 */ import uk.ac.leeds.ccg.grids.*; import java.io.File; public class GenerateData { public GenerateData(){} AbstractGrid2DSquareCellDoubleFactory gridFactory; public static void main(String[] args) throws java.io.IOException { GenerateData g = new GenerateData(); g.run(); } public void run() { System.out.println( "Initialising..." ); long time = System.currentTimeMillis(); //generateInitialDensityGrid(); //generateInitialDensityGridWithZeroForRoadOrAccidentCellsIfNoAccident(); //generateInitialDensityGridWithAllZerosIfNoAccident(); generateGridFromUngenerateFile(); System.out.println( "Processing complete in " + Utilities.time( System.currentTimeMillis() - time ) ); } public void generateGridFromUngenerateFile() { Grid2DSquareCellDoubleJAIFactory jf = new Grid2DSquareCellDoubleJAIFactory(); // Leeds - Bradford Region int nrows = 2375; int ncols = 2685; double xllcorner = 403200.0d; double yllcorner = 412600.0d; double noDataValue = -9999.0d; String ungenerateDataDirectory = "D:/andyt/Projects/PhD/Data/arc/leeds/coverages/"; String outputDataDirectory = "D:/andyt/Projects/PhD/Data/arc/leeds/grids/20/road/junctions/"; File ungenerateFile = new File( ungenerateDataDirectory, "mways_np.ungenerate" ); File gridFile = new File( outputDataDirectory, "mways.asc" ); AbstractGrid2DSquareCellDouble grid = jf.createGrid2DSquareCellDouble( nrows, ncols, xllcorner, yllcorner, 20.0d, noDataValue ); grid.addToGrid( ungenerateFile, "idxy" ); System.out.println( "Exchanging" ); Grid2DSquareCellDoubleExchange.toAsciiFile( grid, gridFile ); } public void generateInitialDensityGrid() { Grid2DSquareCellDoubleJAIFactory jf = new Grid2DSquareCellDoubleJAIFactory(); // Leeds - Bradford Region //int nrows = 2375; //int ncols = 2685; //double xllcorner = 403200.0d; //double yllcorner = 412600.0d; // Leeds City Centre int nrows = 200; int ncols = 250; double xllcorner = 428000.0d; double yllcorner = 432000.0d; String xyDataDirectory = "D:/andyt/Projects/PhD/Data/XY/GB/"; //String outputDataDirectory = "D:/andyt/Projects/PhD/Data/arc/leeds/grids/20/acc/"; String outputDataDirectory = "D:/andyt/Projects/PhD/Data/arc/leeds/grids/20/temp/acc/"; AbstractGrid2DSquareCellDouble grid; File xyFile; File gridFile; // 92to01 xyFile = new File( xyDataDirectory, "acc92to01xy.csv" ); grid = jf.createGrid2DSquareCellDouble( nrows, ncols, xllcorner, yllcorner, 20.0d, -9999.0d ); grid.addToGrid( xyFile, "xy" ); System.out.println( "Exchanging 92to01" ); gridFile = new File( outputDataDirectory, "acc92to01.asc" ); Grid2DSquareCellDoubleExchange.toAsciiFile( grid, gridFile ); // 92to96 xyFile = new File( xyDataDirectory, "acc92to96xy.csv" ); grid = jf.createGrid2DSquareCellDouble( nrows, ncols, xllcorner, yllcorner, 20.0d, -9999.0d ); grid.addToGrid( xyFile, "xy" ); System.out.println( "Exchanging 92to96" ); gridFile = new File( outputDataDirectory, "acc92to96.asc" ); Grid2DSquareCellDoubleExchange.toAsciiFile( grid, gridFile ); // 97to01 xyFile = new File( xyDataDirectory, "acc97to01xy.csv" ); grid = jf.createGrid2DSquareCellDouble( nrows, ncols, xllcorner, yllcorner, 20.0d, -9999.0d ); grid.addToGrid( xyFile, "xy" ); System.out.println( "Exchanging 97to01" ); gridFile = new File( outputDataDirectory, "acc97to01.asc" ); Grid2DSquareCellDoubleExchange.toAsciiFile( grid, gridFile ); // 92 93 94 95 96 97 98 99 for ( int i = 92; i < 100; i++ ) { xyFile = new File( xyDataDirectory, "acc" + i + "xy.csv" ); grid = jf.createGrid2DSquareCellDouble( nrows, ncols, xllcorner, yllcorner, 20.0d, -9999.0d ); grid.addToGrid( xyFile, "xy" ); System.out.println( "Exchanging " + i); gridFile = new File( outputDataDirectory, "acc" + i + ".asc" ); Grid2DSquareCellDoubleExchange.toAsciiFile( grid, gridFile ); } // 01 02 for ( int i = 0; i < 2; i++ ) { xyFile = new File( xyDataDirectory, "acc0" + i + "xy.csv" ); grid = jf.createGrid2DSquareCellDouble( nrows, ncols, xllcorner, yllcorner, 20.0d, -9999.0d ); grid.addToGrid( xyFile, "xy" ); System.out.println( "Exchanging 0" + i ); gridFile = new File( outputDataDirectory, "acc0" + i + ".asc" ); Grid2DSquareCellDoubleExchange.toAsciiFile( grid, gridFile ); } } public void generateInitialDensityGridWithZeroForRoadOrAccidentCellsIfNoAccident() { Grid2DSquareCellDoubleJAIFactory jf = new Grid2DSquareCellDoubleJAIFactory(); String xyDataDirectory = "D:/andyt/Projects/PhD/Data/XY/GB/"; AbstractGrid2DSquareCellDouble zerower; String outputDataDirectory; // Leeds - Bradford Region int nrows = 2375; int ncols = 2685; double xllcorner = 403200.0d; double yllcorner = 412600.0d; zerower = jf.createGrid2DSquareCellDouble( new File ( "D:/andyt/Projects/PhD/Data/arc/leeds/grids/20/road/roadn.asc" ) ); outputDataDirectory = "D:/andyt/Projects/PhD/Data/arc/leeds/grids/20/acc/"; // Leeds City Centre /*int nrows = 200; int ncols = 250; double xllcorner = 428000.0d; double yllcorner = 432000.0d; zerower = jf.createGrid2DSquareCellDouble( new File ( "D:/andyt/Projects/PhD/Data/arc/leeds/grids/20/temp/road/roadn.asc" ) ); outputDataDirectory = "D:/andyt/Projects/PhD/Data/arc/leeds/grids/20/temp/acc/"; */ //String AbstractGrid2DSquareCellDouble grid; File xyFile; File gridFile; // 92to01 xyFile = new File( xyDataDirectory, "acc92to01xy.csv" ); grid = jf.createGrid2DSquareCellDouble( nrows, ncols, xllcorner, yllcorner, 20.0d, -9999.0d ); grid.addToGrid( xyFile, "xy" ); grid.addToGrid( zerower, 0.0d ); System.out.println( "Exchanging 92to01" ); gridFile = new File( outputDataDirectory, "acc92to01n.asc" ); Grid2DSquareCellDoubleExchange.toAsciiFile( grid, gridFile ); // 92to96 xyFile = new File( xyDataDirectory, "acc92to96xy.csv" ); grid = jf.createGrid2DSquareCellDouble( nrows, ncols, xllcorner, yllcorner, 20.0d, -9999.0d ); grid.addToGrid( xyFile, "xy" ); grid.addToGrid( zerower, 0.0d ); System.out.println( "Exchanging 92to96" ); gridFile = new File( outputDataDirectory, "acc92to96n.asc" ); Grid2DSquareCellDoubleExchange.toAsciiFile( grid, gridFile ); // 97to01 xyFile = new File( xyDataDirectory, "acc97to01xy.csv" ); grid = jf.createGrid2DSquareCellDouble( nrows, ncols, xllcorner, yllcorner, 20.0d, -9999.0d ); grid.addToGrid( xyFile, "xy" ); grid.addToGrid( zerower, 0.0d ); System.out.println( "Exchanging 97to01" ); gridFile = new File( outputDataDirectory, "acc97to01n.asc" ); Grid2DSquareCellDoubleExchange.toAsciiFile( grid, gridFile ); // 92 93 94 95 96 97 98 99 for ( int i = 92; i < 100; i++ ) { xyFile = new File( xyDataDirectory, "acc" + i + "xy.csv" ); grid = jf.createGrid2DSquareCellDouble( nrows, ncols, xllcorner, yllcorner, 20.0d, -9999.0d ); grid.addToGrid( xyFile, "xy" ); grid.addToGrid( zerower, 0.0d ); System.out.println( "Exchanging " + i); gridFile = new File( outputDataDirectory, "acc" + i + "n.asc" ); Grid2DSquareCellDoubleExchange.toAsciiFile( grid, gridFile ); } // 01 02 for ( int i = 0; i < 2; i++ ) { xyFile = new File( xyDataDirectory, "acc0" + i + "xy.csv" ); grid = jf.createGrid2DSquareCellDouble( nrows, ncols, xllcorner, yllcorner, 20.0d, -9999.0d ); grid.addToGrid( xyFile, "xy" ); grid.addToGrid( zerower, 0.0d ); System.out.println( "Exchanging 0" + i ); gridFile = new File( outputDataDirectory, "acc0" + i + "n.asc" ); Grid2DSquareCellDoubleExchange.toAsciiFile( grid, gridFile ); } } public void generateInitialDensityGridWithAllZerosIfNoAccident() { Grid2DSquareCellDoubleJAIFactory jf = new Grid2DSquareCellDoubleJAIFactory(); String xyDataDirectory = "D:/andyt/Projects/PhD/Data/XY/GB/"; String outputDataDirectory; // Leeds - Bradford Region int nrows = 2375; int ncols = 2685; double xllcorner = 403200.0d; double yllcorner = 412600.0d; outputDataDirectory = "D:/andyt/Projects/PhD/Data/arc/leeds/grids/20/acc/"; // Leeds City Centre /*int nrows = 200; int ncols = 250; double xllcorner = 428000.0d; double yllcorner = 432000.0d; outputDataDirectory = "D:/andyt/Projects/PhD/Data/arc/leeds/grids/20/temp/acc/"; */ //String AbstractGrid2DSquareCellDouble grid; File xyFile; File gridFile; // 92to01 xyFile = new File( xyDataDirectory, "acc92to01xy.csv" ); grid = jf.createGrid2DSquareCellDouble( nrows, ncols, xllcorner, yllcorner, 20.0d, -9999.0d ); grid.addToGrid( xyFile, "xy" ); grid.addToGrid( 0.0d ); System.out.println( "Exchanging 92to01" ); gridFile = new File( outputDataDirectory, "acc92to01zero.asc" ); Grid2DSquareCellDoubleExchange.toAsciiFile( grid, gridFile ); // 92to96 xyFile = new File( xyDataDirectory, "acc92to96xy.csv" ); grid = jf.createGrid2DSquareCellDouble( nrows, ncols, xllcorner, yllcorner, 20.0d, -9999.0d ); grid.addToGrid( xyFile, "xy" ); grid.addToGrid( 0.0d ); System.out.println( "Exchanging 92to96" ); gridFile = new File( outputDataDirectory, "acc92to96zero.asc" ); Grid2DSquareCellDoubleExchange.toAsciiFile( grid, gridFile ); // 97to01 xyFile = new File( xyDataDirectory, "acc97to01xy.csv" ); grid = jf.createGrid2DSquareCellDouble( nrows, ncols, xllcorner, yllcorner, 20.0d, -9999.0d ); grid.addToGrid( xyFile, "xy" ); grid.addToGrid( 0.0d ); System.out.println( "Exchanging 97to01" ); gridFile = new File( outputDataDirectory, "acc97to01zero.asc" ); Grid2DSquareCellDoubleExchange.toAsciiFile( grid, gridFile ); // 92 93 94 95 96 97 98 99 for ( int i = 92; i < 100; i++ ) { xyFile = new File( xyDataDirectory, "acc" + i + "xy.csv" ); grid = jf.createGrid2DSquareCellDouble( nrows, ncols, xllcorner, yllcorner, 20.0d, -9999.0d ); grid.addToGrid( xyFile, "xy" ); grid.addToGrid( 0.0d ); System.out.println( "Exchanging " + i); gridFile = new File( outputDataDirectory, "acc" + i + "zero.asc" ); Grid2DSquareCellDoubleExchange.toAsciiFile( grid, gridFile ); } // 01 02 for ( int i = 0; i < 2; i++ ) { xyFile = new File( xyDataDirectory, "acc0" + i + "xy.csv" ); grid = jf.createGrid2DSquareCellDouble( nrows, ncols, xllcorner, yllcorner, 20.0d, -9999.0d ); grid.addToGrid( xyFile, "xy" ); grid.addToGrid( 0.0d ); System.out.println( "Exchanging 0" + i ); gridFile = new File( outputDataDirectory, "acc0" + i + "zero.asc" ); Grid2DSquareCellDoubleExchange.toAsciiFile( grid, gridFile ); } } }