private void button3_Click(object sender, EventArgs e) { if (!File.Exists(shapeFileBox.Text)) { MessageBox.Show("Shapefile doesn't exist"); return; } if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) { mDelineator = new Delineator(shapeFileBox.Text, getGridInfo(), folderBrowserDialog1.SelectedPath); mDelineator.Delineate(true, true); weightFileBox.Text = mDelineator.getWeightFile(); pictureBox1.Image = mDelineator.polygonBitmap; } }
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(); } } }