Beispiel #1
0
 private GpxData downloadRawGps(String url, ProgressMonitor progressMonitor)
     throws IOException, OsmTransferException, SAXException {
   boolean done = false;
   GpxData result = null;
   for (int i = 0; !done; ++i) {
     progressMonitor.subTask(tr("Downloading points {0} to {1}...", i * 5000, ((i + 1) * 5000)));
     InputStream in = getInputStream(url + i, progressMonitor.createSubTaskMonitor(1, true));
     if (in == null) {
       break;
     }
     progressMonitor.setTicks(0);
     GpxReader reader = new GpxReader(in);
     gpxParsedProperly = reader.parse(false);
     GpxData currentGpx = reader.data;
     if (result == null) {
       result = currentGpx;
     } else if (currentGpx.hasTrackPoints()) {
       result.mergeFrom(currentGpx);
     } else {
       done = true;
     }
     in.close();
     activeConnection = null;
   }
   result.fromServer = true;
   return result;
 }
  private OsmDataLayer makeLayer(
      String name, FilePlacement placement, OsmBuilder.Mode mode, ProgressMonitor monitor) {
    monitor.beginTask(tr("Building JOSM layer"), 100);
    OsmBuilder builder = new OsmBuilder(placement);
    DataSet data =
        builder.build(this.data.getLayers(), mode, monitor.createSubTaskMonitor(50, false));
    monitor.setTicks(50);
    monitor.setCustomText(tr("Postprocessing layer"));
    OsmDataLayer result = new OsmDataLayer(data, name, null);
    result.onPostLoadFromFile();

    monitor.finishTask();
    return result;
  }
 private GpxData downloadRawGps(Bounds b, ProgressMonitor progressMonitor)
     throws IOException, OsmTransferException, SAXException {
   boolean done = false;
   GpxData result = null;
   String url =
       "trackpoints?bbox="
           + b.getMinLon()
           + ','
           + b.getMinLat()
           + ','
           + b.getMaxLon()
           + ','
           + b.getMaxLat()
           + "&page=";
   for (int i = 0; !done; ++i) {
     progressMonitor.subTask(tr("Downloading points {0} to {1}...", i * 5000, (i + 1) * 5000));
     try (InputStream in =
         getInputStream(url + i, progressMonitor.createSubTaskMonitor(1, true))) {
       if (in == null) {
         break;
       }
       progressMonitor.setTicks(0);
       GpxReader reader = new GpxReader(in);
       gpxParsedProperly = reader.parse(false);
       GpxData currentGpx = reader.getGpxData();
       if (result == null) {
         result = currentGpx;
       } else if (currentGpx.hasTrackPoints()) {
         result.mergeFrom(currentGpx);
       } else {
         done = true;
       }
     }
     activeConnection = null;
   }
   if (result != null) {
     result.fromServer = true;
     result.dataSources.add(new DataSource(b, "OpenStreetMap server"));
   }
   return result;
 }
  private void saveLayer(java.io.File file, FilePlacement placement, ProgressMonitor monitor) {
    monitor.beginTask(tr("Saving to file."), 1000);

    OsmBuilder builder = new OsmBuilder(placement);
    DataSet data =
        builder.build(
            this.data.getLayers(), OsmBuilder.Mode.Final, monitor.createSubTaskMonitor(500, false));
    OsmDataLayer layer = new OsmDataLayer(data, file.getName(), file);

    monitor.setCustomText(tr(" Writing to file"));
    monitor.setTicks(500);

    OsmExporter exporter = new OsmExporter();

    try {
      exporter.exportData(file, layer);
    } catch (IOException e) {
      // TODO:
    }

    monitor.finishTask();
  }
  private PathOptimizer loadPDF(File fileName, ProgressMonitor monitor) {

    monitor.beginTask("", 100);
    monitor.setTicks(0);
    monitor.setCustomText(tr("Preparing"));

    double nodesTolerance = 0.0;
    Color color = null;
    int maxPaths = Integer.MAX_VALUE;

    if (this.mergeCloseNodesCheck.isSelected()) {
      try {
        nodesTolerance = Double.parseDouble(this.mergeCloseNodesTolerance.getText());
      } catch (Exception e) {
        JOptionPane.showMessageDialog(Main.parent, tr("Tolerance is not a number"));
        return null;
      }
    }

    if (this.colorFilterCheck.isSelected()) {
      try {
        String colString = this.colorFilterColor.getText().replace("#", "");
        color = new Color(Integer.parseInt(colString, 16));
      } catch (Exception e) {
        JOptionPane.showMessageDialog(Main.parent, tr("Could not parse color"));
        return null;
      }
    }

    if (this.limitPathCountCheck.isSelected()) {
      try {
        maxPaths = Integer.parseInt(this.limitPathCount.getText());
      } catch (Exception e) {
        JOptionPane.showMessageDialog(Main.parent, tr("Could not parse max path count"));
        return null;
      }
    }

    monitor.setTicks(10);
    monitor.setCustomText(tr("Parsing file"));

    PathOptimizer data =
        new PathOptimizer(nodesTolerance, color, this.splitOnColorChangeCheck.isSelected());

    try {
      PdfBoxParser parser = new PdfBoxParser(data);
      parser.parse(fileName, maxPaths, monitor.createSubTaskMonitor(80, false));

    } catch (FileNotFoundException e1) {
      JOptionPane.showMessageDialog(Main.parent, tr("File not found."));
      return null;
    } catch (Exception e) {
      e.printStackTrace();
      JOptionPane.showMessageDialog(Main.parent, tr("Error while parsing: {0}", e.getMessage()));
      return null;
    }

    monitor.setTicks(80);

    if (this.removeParallelSegmentsCheck.isSelected()) {
      try {
        double tolerance = Double.parseDouble(this.removeParallelSegmentsTolerance.getText());
        monitor.setCustomText(tr("Removing parallel segments"));
        data.removeParallelLines(tolerance);
      } catch (Exception e) {
        JOptionPane.showMessageDialog(Main.parent, tr("Max distance is not a number"));
        return null;
      }
    }

    if (nodesTolerance > 0.0) {
      monitor.setTicks(83);
      monitor.setCustomText(tr("Joining nodes"));
      data.mergeNodes();
    }

    monitor.setTicks(85);
    monitor.setCustomText(tr("Joining adjacent segments"));
    data.mergeSegments();

    if (this.removeSmallObjectsCheck.isSelected()) {
      try {
        double tolerance = Double.parseDouble(this.removeSmallObjectsSize.getText());
        monitor.setTicks(90);
        monitor.setCustomText(tr("Removing small objects"));

        data.removeSmallObjects(tolerance);
      } catch (Exception e) {
        JOptionPane.showMessageDialog(Main.parent, tr("Tolerance is not a number"));
        return null;
      }
    }

    if (this.removeLargeObjectsCheck.isSelected()) {
      try {
        double tolerance = Double.parseDouble(this.removeLargeObjectsSize.getText());
        monitor.setTicks(90);
        monitor.setCustomText(tr("Removing large objects"));
        data.removeLargeObjects(tolerance);
      } catch (Exception e) {
        JOptionPane.showMessageDialog(Main.parent, tr("Tolerance is not a number"));
        return null;
      }
    }

    monitor.setTicks(95);
    monitor.setCustomText(tr("Finalizing layers"));
    data.splitLayersByPathKind(
        this.splitOnShapeClosedCheck.isSelected(),
        this.splitOnSingleSegmentCheck.isSelected(),
        this.splitOnOrthogonalCheck.isSelected());
    data.finish();

    monitor.finishTask();
    return data;
  }