@Override
 public GpxData parseRawGps(ProgressMonitor progressMonitor) throws OsmTransferException {
   progressMonitor.beginTask("", 1);
   try {
     progressMonitor.indeterminateSubTask(getTaskName());
     if (crosses180th) {
       // API 0.6 does not support requests crossing the 180th meridian, so make two requests
       GpxData result = downloadRawGps(new Bounds(lat1, lon1, lat2, 180.0), progressMonitor);
       result.mergeFrom(downloadRawGps(new Bounds(lat1, -180.0, lat2, lon2), progressMonitor));
       return result;
     } else {
       // Simple request
       return downloadRawGps(new Bounds(lat1, lon1, lat2, lon2), progressMonitor);
     }
   } catch (IllegalArgumentException e) {
     // caused by HttpUrlConnection in case of illegal stuff in the response
     if (cancel) return null;
     throw new OsmTransferException("Illegal characters within the HTTP-header response.", e);
   } catch (IOException e) {
     if (cancel) return null;
     throw new OsmTransferException(e);
   } catch (SAXException e) {
     throw new OsmTransferException(e);
   } catch (OsmTransferException e) {
     throw e;
   } catch (RuntimeException e) {
     if (cancel) return null;
     throw e;
   } finally {
     progressMonitor.finishTask();
   }
 }
예제 #2
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 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;
 }