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));
}
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)));
}
}
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);
}
Aggregations