public static void main(String[] args) {

		// Add a shutdown hook
		final Thread mainThread = Thread.currentThread();
		Runtime.getRuntime().addShutdownHook(new Thread() {
			public void run() {
				progress.cancel();
				try {
					mainThread.join();
				} catch (InterruptedException e) {
					LOGGER.log(Level.WARNING,
							"Failed to wait for the main thread to finish", e);
				}
			}
		});

		boolean valid = true;
		boolean requiredArguments = false;

		for (int i = 0; valid && i < args.length; i++) {

			String arg = args[i];

			// Handle optional arguments
			if (arg.startsWith(ARGUMENT_PREFIX)) {

				String argument = arg.substring(ARGUMENT_PREFIX.length());

				switch (argument) {

				case ARGUMENT_COMPRESS_FORMAT:
					if (i < args.length) {
						compressFormat = args[++i];
					} else {
						valid = false;
						System.out
								.println("Error: Compress Format argument '"
										+ arg
										+ "' must be followed by an image format");
					}
					break;

				case ARGUMENT_COMPRESS_QUALITY:
					if (i < args.length) {
						compressQuality = Float.valueOf(args[++i]);
					} else {
						valid = false;
						System.out
								.println("Error: Compress Quality argument '"
										+ arg
										+ "' must be followed by a value between 0.0 and 1.0");
					}
					break;

				case ARGUMENT_GOOGLE_TILES:
					googleTiles = true;
					break;

				case ARGUMENT_BOUNDING_BOX:
					if (i < args.length) {
						String bbox = args[++i];
						String[] bboxParts = bbox.split(",");
						if (bboxParts.length != 4) {
							valid = false;
							System.out
									.println("Error: Bounding Box argument '"
											+ arg
											+ "' value must be in the format: minLon,minLat,maxLon,maxLat");
						} else {
							double minLon = Double.valueOf(bboxParts[0]);
							double minLat = Double.valueOf(bboxParts[1]);
							double maxLon = Double.valueOf(bboxParts[2]);
							double maxLat = Double.valueOf(bboxParts[3]);
							boundingBox = new BoundingBox(minLon, minLat,
									maxLon, maxLat);
						}
					} else {
						valid = false;
						System.out
								.println("Error: Bounding Box argument '"
										+ arg
										+ "' must be followed by bbox values: minLon,minLat,maxLon,maxLat");
					}
					break;

				case ARGUMENT_EPSG:
					if (i < args.length) {
						epsg = Long.valueOf(args[++i]);
					} else {
						valid = false;
						System.out.println("Error: EPSG argument '" + arg
								+ "' must be followed by a value");
					}
					break;

				case ARGUMENT_URL_EPSG:
					if (i < args.length) {
						urlEpsg = Long.valueOf(args[++i]);
					} else {
						valid = false;
						System.out.println("Error: URL EPSG argument '" + arg
								+ "' must be followed by a value");
					}
					break;

				case ARGUMENT_TMS:
					tms = true;
					break;

				default:
					valid = false;
					System.out.println("Error: Unsupported arg: '" + arg + "'");
				}

			} else {
				// Set required arguments in order
				if (geoPackageFile == null) {
					geoPackageFile = new File(arg);
				} else if (tileTable == null) {
					tileTable = arg;
				} else if (url == null) {
					url = arg;
				} else if (minZoom == null) {
					minZoom = Integer.valueOf(arg);
				} else if (maxZoom == null) {
					maxZoom = Integer.valueOf(arg);
					requiredArguments = true;
				} else {
					valid = false;
					System.out.println("Error: Unsupported extra argument: "
							+ arg);
				}
			}
		}

		if (compressFormat == null && compressQuality != null) {
			System.out
					.println("Error: Compress quality requires a compress format");
			valid = false;
		} else if (boundingBox == null && epsg != null) {
			System.out.println("Error: EPSG requires a bounding box");
			valid = false;
		}

		if (!valid || !requiredArguments) {
			printUsage();
		} else {
			// Read the tiles
			try {
				generate();
			} catch (Exception e) {
				printUsage();
				throw e;
			}
		}
	}
public static void main ( String [ ] args ) { final Thread mainThread = Thread . currentThread ( ) ; Runtime . getRuntime ( ) . addShutdownHook ( new Thread ( ) { public void run ( ) { progress . cancel ( ) ; try { mainThread . join ( ) ; } catch ( InterruptedException e ) { LOGGER . log ( Level . WARNING , "Failed to wait for the main thread to finish" , e ) ; } } } ) ; boolean valid = true ; boolean requiredArguments = false ; for ( int i = 0 ; valid && i < args . length ; i ++ ) { String arg = args [ i ] ; if ( arg . startsWith ( ARGUMENT_PREFIX ) ) { String argument = arg . substring ( ARGUMENT_PREFIX . length ( ) ) ; switch ( argument ) { case ARGUMENT_COMPRESS_FORMAT : if ( i < args . length ) { compressFormat = args [ ++ i ] ; } else { valid = false ; System . out . println ( "Error: Compress Format argument '" + arg + "' must be followed by an image format" ) ; } break ; case ARGUMENT_COMPRESS_QUALITY : if ( i < args . length ) { compressQuality = Float . valueOf ( args [ ++ i ] ) ; } else { valid = false ; System . out . println ( "Error: Compress Quality argument '" + arg + "' must be followed by a value between 0.0 and 1.0" ) ; } break ; case ARGUMENT_GOOGLE_TILES : googleTiles = true ; break ; case ARGUMENT_BOUNDING_BOX : if ( i < args . length ) { String bbox = args [ ++ i ] ; String [ ] bboxParts = bbox . split ( "," ) ; if ( bboxParts . length != 4 ) { valid = false ; System . out . println ( "Error: Bounding Box argument '" + arg + "' value must be in the format: minLon,minLat,maxLon,maxLat" ) ; } else { double minLon = Double . valueOf ( bboxParts [ 0 ] ) ; double minLat = Double . valueOf ( bboxParts [ 1 ] ) ; double maxLon = Double . valueOf ( bboxParts [ 2 ] ) ; double maxLat = Double . valueOf ( bboxParts [ 3 ] ) ; boundingBox = new BoundingBox ( minLon , minLat , maxLon , maxLat ) ; } } else { valid = false ; System . out . println ( "Error: Bounding Box argument '" + arg + "' must be followed by bbox values: minLon,minLat,maxLon,maxLat" ) ; } break ; case ARGUMENT_EPSG : if ( i < args . length ) { epsg = Long . valueOf ( args [ ++ i ] ) ; } else { valid = false ; System . out . println ( "Error: EPSG argument '" + arg + "' must be followed by a value" ) ; } break ; case ARGUMENT_URL_EPSG : if ( i < args . length ) { urlEpsg = Long . valueOf ( args [ ++ i ] ) ; } else { valid = false ; System . out . println ( "Error: URL EPSG argument '" + arg + "' must be followed by a value" ) ; } break ; case ARGUMENT_TMS : tms = true ; break ; default : valid = false ; System . out . println ( "Error: Unsupported arg: '" + arg + "'" ) ; } } else { if ( geoPackageFile == null ) { geoPackageFile = new File ( arg ) ; } else if ( tileTable == null ) { tileTable = arg ; } else if ( url == null ) { url = arg ; } else if ( minZoom == null ) { minZoom = Integer . valueOf ( arg ) ; } else if ( maxZoom == null ) { maxZoom = Integer . valueOf ( arg ) ; requiredArguments = true ; } else { valid = false ; System . out . println ( "Error: Unsupported extra argument: " + arg ) ; } } } if ( compressFormat == null && compressQuality != null ) { System . out . println ( "Error: Compress quality requires a compress format" ) ; valid = false ; } else if ( boundingBox == null && epsg != null ) { System . out . println ( "Error: EPSG requires a bounding box" ) ; valid = false ; } if ( ! valid || ! requiredArguments ) { printUsage ( ) ; } else { try { generate ( ) ; } catch ( Exception e ) { printUsage ( ) ; throw e ; } } }
Main method to generate tiles in a GeoPackage

@param args
arguments