Example #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;
 }
Example #2
0
  @Override
  public void importData(File file, ProgressMonitor progressMonitor) throws IOException {
    final String fileName = file.getName();

    try (InputStream is = Compression.getUncompressedFileInputStream(file)) {
      GpxReader r = new GpxReader(is);
      boolean parsedProperly = r.parse(true);
      r.getGpxData().storageFile = file;
      addLayers(
          loadLayers(r.getGpxData(), parsedProperly, fileName, tr("Markers from {0}", fileName)));
    } catch (SAXException e) {
      Main.error(e);
      throw new IOException(tr("Parsing data for layer ''{0}'' failed", fileName), e);
    }
  }
Example #3
0
 public static GpxImporterData loadLayers(
     InputStream is,
     final File associatedFile,
     final String gpxLayerName,
     String markerLayerName,
     ProgressMonitor progressMonitor)
     throws IOException {
   try {
     final GpxReader r = new GpxReader(is);
     final boolean parsedProperly = r.parse(true);
     r.getGpxData().storageFile = associatedFile;
     return loadLayers(r.getGpxData(), parsedProperly, gpxLayerName, markerLayerName);
   } catch (SAXException e) {
     Main.error(e);
     throw new IOException(tr("Parsing data for layer ''{0}'' failed", gpxLayerName), e);
   }
 }
 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;
 }