use of net.osmand.GPXUtilities.Track in project OsmAnd-tools by osmandapp.
the class MapRouterLayer method calculateAltitude.
protected GPXFile calculateAltitude(GPXFile gpxFile, File[] missingFile) {
File srtmFolder = new File(DataExtractionSettings.getSettings().getBinaryFilesDir(), "srtm");
if (!srtmFolder.exists()) {
return null;
}
IndexHeightData hd = new IndexHeightData();
hd.setSrtmData(srtmFolder);
for (Track tr : gpxFile.tracks) {
for (TrkSegment s : tr.segments) {
for (int i = 0; i < s.points.size(); i++) {
WptPt wpt = s.points.get(i);
double h = hd.getPointHeight(wpt.lat, wpt.lon, missingFile);
if (h != IndexHeightData.INEXISTENT_HEIGHT) {
wpt.ele = h;
} else if (i == 0) {
return null;
}
}
}
}
return gpxFile;
}
use of net.osmand.GPXUtilities.Track in project OsmAnd-tools by osmandapp.
the class MapRouterLayer method displayGpxFiles.
private void displayGpxFiles() {
DataTileManager<Entity> points = new DataTileManager<Entity>(9);
if (selectedGPXFile != null) {
for (Track t : selectedGPXFile.tracks) {
for (TrkSegment ts : t.segments) {
Way w = new Way(-1);
int id = 0;
for (WptPt p : ts.points) {
net.osmand.osm.edit.Node n = new net.osmand.osm.edit.Node(p.lat, p.lon, -1);
w.addNode(n);
n.putTag(OSMTagKey.NAME.getValue(), String.valueOf(id));
n.putTag("gpx", "yes");
n.putTag("colour", "blue");
points.registerObject(n.getLatitude(), n.getLongitude(), n);
id++;
}
w.putTag("gpx", "yes");
w.putTag("colour", "green");
LatLon n = w.getLatLon();
points.registerObject(n.getLatitude(), n.getLongitude(), w);
}
}
}
if (directionPointsFile != null) {
List<net.osmand.osm.edit.Node> pnts = directionPointsFile.queryInBox(new QuadRect(0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE), new ArrayList<net.osmand.osm.edit.Node>());
for (net.osmand.osm.edit.Node n : pnts) {
points.registerObject(n.getLatitude(), n.getLongitude(), n);
}
}
// load from file
map.setPoints(points);
}
use of net.osmand.GPXUtilities.Track in project OsmAnd-tools by osmandapp.
the class MapPanelSelector method drawGpxFiles.
private void drawGpxFiles(Collection<GPXFile> files) {
DataTileManager<Entity> points = new DataTileManager<>(4);
List<Way> ways = new ArrayList<>();
for (GPXFile file : files) {
for (Track track : file.tracks) {
for (TrkSegment segment : track.segments) {
Way w = new Way(-1);
for (WptPt point : segment.points) {
w.addNode(new Node(point.lat, point.lon, -1));
}
ways.add(w);
}
}
for (Way w : ways) {
LatLon n = w.getLatLon();
points.registerObject(n.getLatitude(), n.getLongitude(), w);
}
panel.setPoints(points);
}
}
use of net.osmand.GPXUtilities.Track in project OsmAnd-tools by osmandapp.
the class GpxController method calculateSrtmAltitude.
public GPXFile calculateSrtmAltitude(GPXFile gpxFile, File[] missingFile) {
if (srtmLocation == null) {
return null;
}
if (srtmLocation.startsWith("http://") || srtmLocation.startsWith("https://")) {
String serverUrl = srtmLocation + "/gpx/process-srtm";
ByteArrayOutputStream baos = new ByteArrayOutputStream();
GPXUtilities.writeGpx(new OutputStreamWriter(baos), gpxFile, null);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
MultiValueMap<String, String> fileMap = new LinkedMultiValueMap<>();
ContentDisposition contentDisposition = ContentDisposition.builder("form-data").name("file").filename("route.gpx").build();
fileMap.add(HttpHeaders.CONTENT_DISPOSITION, contentDisposition.toString());
HttpEntity<byte[]> fileEntity = new HttpEntity<>(baos.toByteArray(), fileMap);
MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
body.add("file", fileEntity);
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(body, headers);
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<byte[]> response = restTemplate.postForEntity(serverUrl, requestEntity, byte[].class);
if (response.getStatusCode().is2xxSuccessful()) {
return GPXUtilities.loadGPXFile(new ByteArrayInputStream(response.getBody()));
} else {
return null;
}
} else {
File srtmFolder = new File(srtmLocation);
if (!srtmFolder.exists()) {
return null;
}
IndexHeightData hd = new IndexHeightData();
hd.setSrtmData(srtmFolder);
for (Track tr : gpxFile.tracks) {
for (TrkSegment s : tr.segments) {
for (int i = 0; i < s.points.size(); i++) {
WptPt wpt = s.points.get(i);
double h = hd.getPointHeight(wpt.lat, wpt.lon, missingFile);
if (h != IndexHeightData.INEXISTENT_HEIGHT) {
wpt.ele = h;
} else if (i == 0) {
return null;
}
}
}
}
}
return gpxFile;
}
use of net.osmand.GPXUtilities.Track in project OsmAnd-tools by osmandapp.
the class OsmGpxWriteContext method writeTrack.
public void writeTrack(OsmGpxFile gpxInfo, Map<String, String> extraTrackTags, GPXFile gpxFile, GPXTrackAnalysis analysis, String routeIdPrefix) throws IOException, SQLException {
Map<String, String> gpxTrackTags = new LinkedHashMap<String, String>();
if (qp.details < QueryParams.DETAILS_TRACKS) {
boolean validTrack = false;
for (Track t : gpxFile.tracks) {
for (TrkSegment s : t.segments) {
if (s.points.isEmpty()) {
continue;
}
if (!validatedTrackSegment(s)) {
continue;
}
validTrack = true;
}
}
if (validTrack) {
serializer.startTag(null, "node");
serializer.attribute(null, "id", id-- + "");
serializer.attribute(null, "action", "modify");
serializer.attribute(null, "version", "1");
serializer.attribute(null, "lat", latLonFormat.format(gpxFile.findPointToShow().lat));
serializer.attribute(null, "lon", latLonFormat.format(gpxFile.findPointToShow().lon));
tagValue(serializer, "route", "segment");
tagValue(serializer, "route_type", "track");
tagValue(serializer, "route_radius", gpxFile.getOuterRadius());
addGenericTags(gpxTrackTags, null);
addGpxInfoTags(gpxTrackTags, gpxInfo, routeIdPrefix);
addAnalysisTags(gpxTrackTags, analysis);
seraizeTags(extraTrackTags, gpxTrackTags);
serializer.endTag(null, "node");
}
} else {
for (Track t : gpxFile.tracks) {
for (TrkSegment s : t.segments) {
if (s.points.isEmpty()) {
continue;
}
if (!validatedTrackSegment(s)) {
continue;
}
segments++;
long idStart = id;
for (WptPt p : s.points) {
long nid = id--;
writePoint(nid, p, null, null, null);
}
long endid = id;
serializer.startTag(null, "way");
serializer.attribute(null, "id", id-- + "");
serializer.attribute(null, "action", "modify");
serializer.attribute(null, "version", "1");
for (long nid = idStart; nid > endid; nid--) {
serializer.startTag(null, "nd");
serializer.attribute(null, "ref", nid + "");
serializer.endTag(null, "nd");
}
tagValue(serializer, "route", "segment");
tagValue(serializer, "route_type", "track");
tagValue(serializer, "route_radius", gpxFile.getOuterRadius());
addGenericTags(gpxTrackTags, t);
addGpxInfoTags(gpxTrackTags, gpxInfo, routeIdPrefix);
addAnalysisTags(gpxTrackTags, analysis);
addElevationTags(gpxTrackTags, s);
seraizeTags(extraTrackTags, gpxTrackTags);
serializer.endTag(null, "way");
}
}
for (WptPt p : gpxFile.getPoints()) {
long nid = id--;
writePoint(nid, p, "point", routeIdPrefix + gpxInfo.id, gpxInfo.name);
}
}
tracks++;
}
Aggregations