Search in sources :

Example 6 with GPXTrackAnalysis

use of net.osmand.GPXUtilities.GPXTrackAnalysis in project OsmAnd-tools by osmandapp.

the class MapApiController method listFiles.

@GetMapping(value = "/list-files")
@ResponseBody
public ResponseEntity<String> listFiles(@RequestParam(name = "name", required = false) String name, @RequestParam(name = "type", required = false) String type, @RequestParam(name = "allVersions", required = false, defaultValue = "false") boolean allVersions) throws IOException, SQLException {
    PremiumUserDevice dev = checkUser();
    if (dev == null) {
        return tokenNotValid();
    }
    UserFilesResults res = userdataController.generateFiles(dev.userid, name, type, allVersions, true);
    for (UserFileNoData nd : res.uniqueFiles) {
        String ext = nd.name.substring(nd.name.lastIndexOf('.') + 1);
        if (nd.type.equalsIgnoreCase("gpx") && ext.equalsIgnoreCase("gpx") && !analysisPresent(ANALYSIS, nd.details)) {
            GPXTrackAnalysis analysis = null;
            Optional<UserFile> of = userFilesRepository.findById(nd.id);
            UserFile uf = of.get();
            if (uf != null) {
                try {
                    InputStream in = uf.data != null ? new ByteArrayInputStream(uf.data) : userdataController.getInputStream(uf);
                    if (in != null) {
                        GPXFile gpxFile = GPXUtilities.loadGPXFile(new GZIPInputStream(in));
                        if (gpxFile != null) {
                            analysis = getAnalysis(uf, gpxFile);
                        }
                    }
                } catch (RuntimeException e) {
                }
                saveAnalysis(ANALYSIS, uf, analysis);
                nd.details = uf.details.deepCopy();
            }
        }
        if (analysisPresent(ANALYSIS, nd.details)) {
            nd.details.get(ANALYSIS).getAsJsonObject().remove("speedData");
            nd.details.get(ANALYSIS).getAsJsonObject().remove("elevationData");
        }
        if (analysisPresent(SRTM_ANALYSIS, nd.details)) {
            nd.details.get(SRTM_ANALYSIS).getAsJsonObject().remove("speedData");
            nd.details.get(SRTM_ANALYSIS).getAsJsonObject().remove("elevationData");
        }
    }
    return ResponseEntity.ok(gson.toJson(res));
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) UserFilesResults(net.osmand.server.controllers.pub.UserdataController.UserFilesResults) ByteArrayInputStream(java.io.ByteArrayInputStream) UserFile(net.osmand.server.api.repo.PremiumUserFilesRepository.UserFile) GZIPInputStream(java.util.zip.GZIPInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) GPXTrackAnalysis(net.osmand.GPXUtilities.GPXTrackAnalysis) GPXFile(net.osmand.GPXUtilities.GPXFile) PremiumUserDevice(net.osmand.server.api.repo.PremiumUserDevicesRepository.PremiumUserDevice) UserFileNoData(net.osmand.server.api.repo.PremiumUserFilesRepository.UserFileNoData) GetMapping(org.springframework.web.bind.annotation.GetMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 7 with GPXTrackAnalysis

use of net.osmand.GPXUtilities.GPXTrackAnalysis in project OsmAnd-tools by osmandapp.

the class GpxController method uploadGpx.

@PostMapping(path = { "/upload-session-gpx" }, produces = "application/json")
public ResponseEntity<String> uploadGpx(@RequestPart(name = "file") @Valid @NotNull @NotEmpty MultipartFile file, HttpServletRequest request, HttpSession httpSession) throws IOException {
    GPXSessionContext ctx = session.getGpxResources(httpSession);
    File tmpGpx = File.createTempFile("gpx_" + httpSession.getId(), ".gpx");
    double fileSizeMb = file.getSize() / (double) (1 << 20);
    double filesSize = getCommonSavedFilesSize(ctx.files);
    double maxSizeMb = getCommonMaxSizeFiles();
    if (fileSizeMb + filesSize > maxSizeMb) {
        return ResponseEntity.badRequest().body(String.format("You don't have enough cloud space to store this file!" + "\nUploaded file size: %.1f MB." + "\nMax cloud space: %.0f MB." + "\nAvailable free space: %.1f MB.", fileSizeMb, maxSizeMb, maxSizeMb - filesSize));
    }
    InputStream is = file.getInputStream();
    FileOutputStream fous = new FileOutputStream(tmpGpx);
    Algorithms.streamCopy(is, fous);
    is.close();
    fous.close();
    ctx.tempFiles.add(tmpGpx);
    GPXFile gpxFile = GPXUtilities.loadGPXFile(tmpGpx);
    if (gpxFile.error != null) {
        return ResponseEntity.badRequest().body("Error reading gpx!");
    } else {
        GPXSessionFile sessionFile = new GPXSessionFile();
        ctx.files.add(sessionFile);
        gpxFile.path = file.getOriginalFilename();
        GPXTrackAnalysis analysis = gpxFile.getAnalysis(System.currentTimeMillis());
        sessionFile.file = tmpGpx;
        sessionFile.size = fileSizeMb;
        cleanupFromNan(analysis);
        sessionFile.analysis = analysis;
        GPXFile srtmGpx = calculateSrtmAltitude(gpxFile, null);
        GPXTrackAnalysis srtmAnalysis = null;
        if (srtmGpx != null) {
            srtmAnalysis = srtmGpx.getAnalysis(System.currentTimeMillis());
        }
        sessionFile.srtmAnalysis = srtmAnalysis;
        if (srtmAnalysis != null) {
            cleanupFromNan(srtmAnalysis);
        }
        return ResponseEntity.ok(gson.toJson(Map.of("info", sessionFile)));
    }
}
Also used : GPXSessionFile(net.osmand.server.controllers.pub.UserSessionResources.GPXSessionFile) GPXSessionContext(net.osmand.server.controllers.pub.UserSessionResources.GPXSessionContext) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) GPXTrackAnalysis(net.osmand.GPXUtilities.GPXTrackAnalysis) GPXFile(net.osmand.GPXUtilities.GPXFile) GPXFile(net.osmand.GPXUtilities.GPXFile) GPXSessionFile(net.osmand.server.controllers.pub.UserSessionResources.GPXSessionFile) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 8 with GPXTrackAnalysis

use of net.osmand.GPXUtilities.GPXTrackAnalysis in project OsmAnd-tools by osmandapp.

the class MapRouterLayer method displayTrackInfo.

protected void displayTrackInfo(GPXFile gpxFile, String header) {
    GPXTrackAnalysis analysis = selectedGPXFile.getAnalysis(gpxFile.modifiedTime);
    StringBuilder msg = new StringBuilder();
    msg.append(String.format("Track: distance %.1f, distance no gaps %.1f, tracks %d, points %d\n", analysis.totalDistance, analysis.totalDistanceWithoutGaps, analysis.totalTracks, analysis.wptPoints));
    if (analysis.hasElevationData) {
        msg.append(String.format("Ele: min - %.1f, max - %.1f, avg - %.1f, uphill - %.1f, downhill - %.1f\n", analysis.minElevation, analysis.maxElevation, analysis.avgElevation, analysis.diffElevationUp, analysis.diffElevationDown));
    }
    if (analysis.hasSpeedData) {
        msg.append(String.format("Speed: min - %.1f, max - %.1f, avg - %.1f, dist+speed - %.1f, dist+speed no gaps - %.1f\n", analysis.minSpeed, analysis.maxSpeed, analysis.avgSpeed, analysis.totalDistanceMoving, analysis.totalDistanceMovingWithoutGaps));
    }
    if (analysis.startTime != analysis.endTime) {
        msg.append(String.format("Time: start - %s, end - %s, span - %.1f min, span no gaps - %.1f min\n", new Date(analysis.startTime), new Date(analysis.endTime), analysis.timeSpan / 60000.0, analysis.timeSpanWithoutGaps / 60000.0));
    }
    log.info(header + " " + msg);
    JOptionPane.showMessageDialog(OsmExtractionUI.MAIN_APP.getFrame(), msg, header, JOptionPane.INFORMATION_MESSAGE);
}
Also used : GPXTrackAnalysis(net.osmand.GPXUtilities.GPXTrackAnalysis) Date(java.util.Date)

Aggregations

GPXTrackAnalysis (net.osmand.GPXUtilities.GPXTrackAnalysis)8 GPXFile (net.osmand.GPXUtilities.GPXFile)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 InputStream (java.io.InputStream)4 GZIPInputStream (java.util.zip.GZIPInputStream)3 PremiumUserDevice (net.osmand.server.api.repo.PremiumUserDevicesRepository.PremiumUserDevice)3 UserFile (net.osmand.server.api.repo.PremiumUserFilesRepository.UserFile)3 GetMapping (org.springframework.web.bind.annotation.GetMapping)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 ResponseEntity (org.springframework.http.ResponseEntity)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 Array (java.sql.Array)1 ResultSet (java.sql.ResultSet)1 Date (java.util.Date)1 IProgress (net.osmand.IProgress)1 OsmGpxWriteContext (net.osmand.obf.OsmGpxWriteContext)1 IndexCreator (net.osmand.obf.preparation.IndexCreator)1 IndexCreatorSettings (net.osmand.obf.preparation.IndexCreatorSettings)1 MapRenderingTypesEncoder (net.osmand.osm.MapRenderingTypesEncoder)1