Exemplo n.º 1
0
  private String extractStencilScript(InputStream stencilFileStream)
      throws AlgorithmExecutionException {
    try {
      return FileUtilities.readEntireInputStream(stencilFileStream);
    } catch (IOException ioException) {
      String exceptionMessage = "A problem occurred while trying to read the source Stencil file.";

      throw new AlgorithmExecutionException(exceptionMessage, ioException);
    }
  }
Exemplo n.º 2
0
  public File writePostScriptToFile(String projectionName, String authorName, String dataLabel)
      throws IOException, AlgorithmExecutionException, TransformException {

    File psFile =
        FileUtilities.createTemporaryFileInDefaultTemporaryDirectory(
            "geoMaps", OUTPUT_FILE_EXTENSION);

    BufferedWriter out = new BufferedWriter(new FileWriter(psFile));

    writeCodeHeader(out, psFile.getName());

    out.write(createPostScriptUtilityDefinitions());
    out.write("\n");

    out.write((new PageHeader(dataLabel, pageHeightInPoints)).toPostScript() + "\n");
    out.write((new PageFooter()).toPostScript() + "\n");

    out.write("% Save the default clipping path so we can clip the map safely" + "\n");
    out.write("gsave" + "\n");
    out.write("\n");

    out.write(mapDisplayer.toPostScript());
    out.write("\n");

    FeaturePrinter featurePrinter =
        new FeaturePrinter(
            featureCollection, geometryProjector, mapDisplayer, shapefileFeatureNameKey);
    featurePrinter.printFeatures(out, featureColorMap);

    CirclePrinter circlePrinter = new CirclePrinter(geometryProjector, mapDisplayer);
    circlePrinter.printCircles(out, circles);

    out.write("% Restore the default clipping path" + "\n");
    out.write("grestore" + "\n");
    out.write("\n");

    PageMetadata pageMetadata = new PageMetadata(TITLE, subtitle);
    pageMetadata.add(projectionName + " Projection");
    pageMetadata.add(timestamp());
    pageMetadata.add(authorName);
    out.write(pageMetadata.toPostScript());
    out.write("\n");

    out.write(legend.toPostScript());
    out.write("\n");

    out.write("showpage" + "\n");

    out.close();

    GeoMapsAlgorithm.logger.log(LogService.LOG_INFO, "Done.");

    return psFile;
  }
Exemplo n.º 3
0
  @Override
  public Data[] execute() throws AlgorithmExecutionException {
    LogService logger = getLogger();
    Data inputData = getInputData();

    logger.log(LogService.LOG_INFO, "Creating PostScript..");
    CSVWriter csvWriter = null;

    try {
      File barSizesFile =
          FileUtilities.createTemporaryFileInDefaultTemporaryDirectory("barSizes", CSV_FILE_SUFFIX);
      csvWriter = new CSVWriter(new FileWriter(barSizesFile));
      String[] header = new String[] {"Record Name", "Width", "Height", "Area (Width x Height)"};
      csvWriter.writeNext(header);
      String postScriptCode = createPostScriptCode(csvWriter);
      csvWriter.close();

      File temporaryPostScriptFile =
          writePostScriptCodeToTemporaryFile(postScriptCode, "horizontal-line-graph");

      return formOutData(temporaryPostScriptFile, barSizesFile, inputData);
    } catch (IOException e) {
      String message =
          String.format("An error occurred when creating %s.", getLabel(inputData.getMetadata()));
      message += e.getMessage();
      throw new AlgorithmExecutionException(message, e);
    } catch (PostScriptCreationException e) {
      String exceptionMessage =
          String.format(
              "An error occurred when creating the PostScript for the %s.",
              getLabel(inputData.getMetadata()) + e.getMessage());
      throw new AlgorithmExecutionException(exceptionMessage, e);
    } finally {
      if (csvWriter != null) {
        try {
          csvWriter.close();
        } catch (IOException e) {
          throw new AlgorithmExecutionException(e.getMessage(), e);
        }
      }
    }
  }
Exemplo n.º 4
0
  private Data createInputData(String testDataPath) throws Exception {
    File file = FileUtilities.safeLoadFileFromClasspath(RowItemTest.class, testDataPath);

    return new BasicData(file, ISI_MIME_TYPE);
  }