private static void export( GeoSetExporter exporter, GeoSet geoSet, String filePath, ProgressIndicator progressIndicator) throws IOException { // export the GeoSet to the file if (progressIndicator != null) { exporter.setProgressIndicator(progressIndicator); progressIndicator.start(); } exporter.export(geoSet, filePath); // FIXME this is an ugly hack !!! ??? if (exporter instanceof TableLinkExporter) { TableLinkExporter tableLinkExporter = (TableLinkExporter) exporter; TableLink tableLink = null; if (geoSet instanceof GeoMap && ((GeoMap) geoSet).tableLinkGetNumber() > 0) { tableLink = ((GeoMap) geoSet).tableLinkGet(0); // !!! ??? } else { ika.table.Table table = new ika.table.Table("US-ASCII"); table.setName("table"); table.addColumn("ID"); final int rowCount = tableLinkExporter.getFeatureCount(); for (int i = 0; i < rowCount; i++) { table.addRow(new Object[] {new Double(i)}); } tableLink = new TableLink(table, geoSet); } tableLinkExporter.exportTableForGeometry(filePath, tableLink); } }
/** * Exports map features to a file. The user is asked to select a file path to a new file. This is * designed for vector data. * * @param exporter The GeoSetExporter to export the exporterMap. If null, the user is asked to * select a GeoSetExporter from a list. * @param geoSet The GeoSet to export. * @param fileName A default file name without extension. If null, the name of the GeoSet is used. * @param frame The Frame for which the dialog for selecting a file is displayed. * @param pageFormat The page format for exporting to vector graphics formats (not georeferenced * formats). If null and the exporter is a VectorGraphicsExporter, the page format of the * exporter is used. If this is also null, a default page format is used that includes the * whole GeoSet to export. * @param askScale If true and if exporting to a vector graphics format (not a georeferenced GIS * format), the user is asked for a scale that is applied to the data prior to export. */ public static void export( GeoSetExporter exporter, GeoSet geoSet, String fileName, Frame frame, PageFormat pageFormat, boolean askScale, String applicationName, String documentName, String documentAuthor, String documentSubject, String documentKeyWords, ProgressIndicator progressIndicator) { try { if (exporter == null) { exporter = GeoExportGUI.askExporter(frame); } if (exporter == null) { return; // user cancelled } // construct a message for the file selection dialog exporter.setApplicationName(applicationName); exporter.setDocumentName(documentName); exporter.setDocumentAuthor(documentAuthor); exporter.setDocumentSubject(documentSubject); exporter.setDocumentKeyWords(documentKeyWords); String msg = "Save " + exporter.getFileFormatName() + " File"; // construct a file name if (fileName == null) { fileName = geoSet.getName(); } String ext = exporter.getFileExtension(); fileName = FileUtils.forceFileNameExtension(fileName, ext); // ask the user for a file. String filePath = FileUtils.askFile(frame, msg, fileName, false, ext); if (filePath == null) { return; // user canceled } // ask the user for a scale for graphics file formats if the exporter // does not have a valid page format. Don't do this for georeferenced // GIS export formats. if (exporter instanceof VectorGraphicsExporter) { VectorGraphicsExporter gExporter = (VectorGraphicsExporter) exporter; if (pageFormat == null) { pageFormat = gExporter.getPageFormat(); } if (pageFormat == null) { pageFormat = new PageFormat(); pageFormat.setAutomatic(true); Rectangle2D box = geoSet.getBounds2D(GeoObject.UNDEFINED_SCALE); pageFormat.setPageWorldCoordinates(box); } if (askScale) { if (!GeoExportGUI.askScale(exporter, pageFormat, geoSet, frame)) { return; } } else { gExporter.setPageFormat(pageFormat); } } else if (exporter instanceof RasterImageExporter) { String rasterSizeMsg = "Please enter the width of the image in pixels:"; String rasterTitle = "Image Width"; String widthStr = (String) JOptionPane.showInputDialog( frame, rasterSizeMsg, rasterTitle, JOptionPane.QUESTION_MESSAGE, null, null, new Integer(1000)); if (widthStr == null) { return; // user canceled } try { int width = (int) Double.parseDouble(widthStr); ((RasterImageExporter) exporter).setImageWidth(width); } catch (NumberFormatException exc) { ErrorDialog.showErrorDialog("Please enter a valid number for the image width."); return; } } if (progressIndicator == null) { GeoExportGUI.export(exporter, geoSet, filePath, null); } else { new GeoExportTask(exporter, geoSet, filePath, progressIndicator).execute(); } } catch (Exception e) { // show an error message. String msg = "The data could not be exported."; ika.utils.ErrorDialog.showErrorDialog(msg, "Export Error", e, frame); e.printStackTrace(); } }