public Extractor(String dataDir, String cellWeightsFile, GriddedDataDetails gridDetails, TimeUnit timeUnit) { this.mGridDetails = gridDetails; this.mTimeUnit = timeUnit; InitializeGriddedData(dataDir); InitializeExtractionPoints(cellWeightsFile); }
public Grid(GriddedDataDetails gridDetails) { this.xRes = gridDetails.horizontalGridSize; this.yRes = gridDetails.verticalGridSize; this.mbr.xMin = gridDetails.lowerLeftLatitude; this.mbr.yMin = gridDetails.lowerLeftLongitude; this.mbr.xMax = this.mbr.xMin + (this.xRes * (decimal)gridDetails.columns); this.mbr.yMax = this.mbr.yMin + (this.yRes * (decimal)gridDetails.rows); }
public Delineator(String shapeFile, GriddedDataDetails griddedDataDetails, String outDir) { shpFilepath = shapeFile; this.outDir = outDir; this.griddedDataDetails = griddedDataDetails; shapes = new Shape[0]; dataGrid = new Grid(griddedDataDetails); calcDisplayGrid(); polygonBitmap = new Bitmap(2048, 2048); Graphics gfx = Graphics.FromImage(polygonBitmap); gfx.Clear(Color.White); }
public GriddedDataFile(GriddedDataDetails grid, String fltFile, bool text = false) { // Save filename filename = Path.GetFileNameWithoutExtension(fltFile); this.nColumns = grid.columns; this.nRows = grid.rows; this.xLowerLeft = grid.lowerLeftLongitude; this.yLowerLeft = grid.lowerLeftLatitude; this.xCellSize = grid.horizontalGridSize; this.yCellSize = grid.verticalGridSize; nodataValue = -9999.9f; lsbfirst = true; textFormat = text; this.fltFile = fltFile; }
public GriddedDataset(String[] fltFiles, GriddedDataDetails grid, int dateString, TimeUnit timeUnit, bool binaryFormat = true) { mTimeUnit = timeUnit; mDateString = dateString; mFilenameLookup = new Dictionary <DateTime, GriddedDataFile>(); if (binaryFormat) { foreach (String fltFile in fltFiles) { DateTime fromDate = stripPrecision(computeDate(fltFile, dateString), mTimeUnit); if (mFilenameLookup.ContainsKey(fromDate)) { String oldFile = Path.GetFileNameWithoutExtension(mFilenameLookup[fromDate].getFilename()); throw new Exception("Duplicate entry for date " + fromDate + ". Filename1 = " + oldFile + " Filename2 = " + fltFile); } else { mFilenameLookup.Add(fromDate, new GriddedDataFile(grid, fltFile)); } } } else { foreach (String textFolder in fltFiles) { DateTime fromDate = stripPrecision(computeDate(textFolder, dateString), mTimeUnit); GriddedDataFile newData = new GriddedDataFile(textFolder); if (mFilenameLookup.ContainsKey(fromDate)) { String oldFile = Path.GetFileNameWithoutExtension(mFilenameLookup[fromDate].getFilename()); throw new Exception("Duplicate entry for date " + fromDate + ". Filename1 = " + oldFile + " Filename2 = " + textFolder); } else { mFilenameLookup.Add(fromDate, newData); } } } }
static void Main(string[] args) { if (args.Length == 0) { PrintHelpCommand(); Console.WriteLine("Press any key to continue....."); Console.ReadKey(); return; } else { Dictionary <String, String> arguments = InterpretCommandLineArguments(args); foreach (KeyValuePair <String, String> kvp in arguments) { //Console.WriteLine("Found " + kvp.Key + " / " + kvp.Value); } if (arguments.ContainsKey("HELP") || arguments.ContainsKey("H")) { PrintHelpCommand(); Console.WriteLine("Press any key to exit....."); Console.ReadKey(); return; } else if (arguments.ContainsKey("GUI")) { GUI gui = new GUI(); gui.ShowDialog(); } // Both else if (arguments.ContainsKey("ALL")) { if (arguments.ContainsKey("SHAPEFILE") && arguments.ContainsKey("GRID") && arguments.ContainsKey("OUTDIR") && arguments.ContainsKey("DATADIR") && arguments.ContainsKey("TIMEUNIT")) { // Check output directory exists or can be created if (!Directory.Exists(arguments["OUTDIR"])) { try { Directory.CreateDirectory(arguments["OUTDIR"]); } catch (Exception) { throw new Exception("Failure creating output directory ( " + arguments["OUTDIR"] + " )"); } } // Set Grid GriddedDataDetails gridDetails = new GriddedDataDetails(); if (arguments.ContainsKey("GRID")) { try { gridDetails = InterpretGridString(arguments["GRID"]); } catch (Exception e) { Console.WriteLine("Error"); Console.WriteLine(e.Message); return; } } // Create weight file Delineator delineator = new Delineator(arguments["SHAPEFILE"], gridDetails, arguments["OUTDIR"]); delineator.Delineate(arguments.ContainsKey("BOUNDARY"), arguments.ContainsKey("AREA")); // Extract data for weight file Extractor extractor = new Extractor(arguments["DATADIR"], delineator.getWeightFile(), gridDetails, (TimeUnit)Enum.Parse(typeof(TimeUnit), arguments["TIMEUNIT"])); extractor.Extract(arguments["OUTDIR"]); extractor.ProduceStatPlots(new Size(2048, 2048), arguments["OUTDIR"], arguments.ContainsKey("PLOTTIME"), arguments.ContainsKey("STATS"), arguments.ContainsKey("PLOTSTAT")); } else { Console.WriteLine("Mode all (-ALL) requires arguments for shapefile location (-SHAPEFILE), data directory (-DATADIR), data time unit (-TIMEUNIT), grid details (-GRID) and output directory (-OUTDIR)"); return; } } // Just get grid cells else if (arguments.ContainsKey("DELINEATE")) { if (arguments.ContainsKey("SHAPEFILE") && arguments.ContainsKey("GRID") && arguments.ContainsKey("OUTDIR")) { // Check output directory exists or can be created if (!Directory.Exists(arguments["OUTDIR"])) { try { Directory.CreateDirectory(arguments["OUTDIR"]); } catch (Exception) { throw new Exception("Failure creating output directory ( " + arguments["OUTDIR"] + " )"); } } // Set Grid GriddedDataDetails gridDetails = new GriddedDataDetails(); if (arguments.ContainsKey("GRID")) { try { gridDetails = InterpretGridString(arguments["GRID"]); } catch (Exception e) { Console.WriteLine("Error"); Console.WriteLine(e.Message); return; } } // Create weight file Delineator delineator = new Delineator(arguments["SHAPEFILE"], gridDetails, arguments["OUTDIR"]); delineator.Delineate(arguments.ContainsKey("BOUNDARY"), arguments.ContainsKey("AREA")); } else { Console.WriteLine("Mode cell calculation (-DELINEATE) requires arguments for shapefile location (-SHAPEFILE), grid details (-GRID) and output weight file name (-WEIGHTFILE)"); return; } } // Extract data else if (arguments.ContainsKey("EXTRACT")) { if (arguments.ContainsKey("WEIGHTFILE") && arguments.ContainsKey("DATADIR") && arguments.ContainsKey("TIMEUNIT") && arguments.ContainsKey("OUTDIR")) { // Check output directory exists or can be created if (!Directory.Exists(arguments["OUTDIR"])) { try { Directory.CreateDirectory(arguments["OUTDIR"]); } catch (Exception) { throw new Exception("Failure creating output directory ( " + arguments["OUTDIR"] + " )"); } } // Set Grid GriddedDataDetails gridDetails = new GriddedDataDetails(); if (arguments.ContainsKey("GRID")) { try { gridDetails = InterpretGridString(arguments["GRID"]); } catch (Exception e) { Console.WriteLine("Error"); Console.WriteLine(e.Message); return; } } // Extract data for weight file Extractor extractor = new Extractor(arguments["DATADIR"], arguments["WEIGHTFILE"], gridDetails, (TimeUnit)Enum.Parse(typeof(TimeUnit), arguments["TIMEUNIT"])); extractor.Extract(arguments["OUTDIR"]); extractor.ProduceStatPlots(new Size(2048, 2048), arguments["OUTDIR"], arguments.ContainsKey("PLOTTIME"), arguments.ContainsKey("STATS"), arguments.ContainsKey("PLOTSTAT")); } else { Console.WriteLine("Mode cell calculation (-EXTRACT) requires arguments for output weight file name (-WEIGHTFILE), data directory (-DATADIR), data time unit (-TIMEUNIT), grid details (-GRID) and output directory (-OUTDIR)"); return; } } else { Console.WriteLine("Incorrect arguments"); PrintHelpCommand(); } } }