def _overlay_map(self): print "\noverlaying relief map\n" srtm = SRTMManager(srtm_format=self.srtm_format, patch_mode=self.patch_mode) c = 0 # just a counter to track completion total_samples = self.lng_sample_points * self.lat_sample_points for y in range(1, self.lat_sample_points): for x in range(1, self.lng_sample_points): sample_lat = self.south_lat + y * self.lat_interval sample_lng = self.west_lng + x * self.lng_interval alt = srtm.get_altitude(sample_lat, sample_lng) if alt: if alt < self.valley["alt"]: self.valley["alt"] = alt self.valley["lat"] = sample_lat self.valley["lng"] = sample_lng if alt > self.peak["alt"]: self.peak["alt"] = alt self.peak["lat"] = sample_lat self.peak["lng"] = sample_lng self.outfile[self.lat_sample_points - y][x] = alt c += 1.0 if (c % 1000) == 0: percent_complete = (c / total_samples) * 100.0 update_status(percent_complete) self._save_cache()
def overlay_gps(self, gpx, thickness=2, elevation_delta=20): print "\noverlaying gps\n" srtm = SRTMManager(srtm_format=self.srtm_format, patch_mode=self.patch_mode) prev_pixel = None prev_alt = 0 # get a circle to draw at every point circ = filled_circle(int(thickness)) for track in gpx.tracks: for segment in track.segments: for point in segment.points: p_lat, p_lng = point.latitude, point.longitude alt = srtm.get_altitude(p_lat, p_lng) if not alt: alt = prev_alt else: prev_alt = alt # we need to get the percentage of the map where the # point is and convert it to number of pixels lat_pt = abs(p_lat - self.south_lat) lng_pt = abs(self.east_lng - p_lng) if lat_pt < self.lat_delta and lng_pt < self.lng_delta: lat_pct = lat_pt / self.lat_delta lng_pct = lng_pt / self.lng_delta pixel_lat = int(math.floor(lat_pct * self.lat_sample_points)) pixel_lng = int(math.floor(lng_pct * self.lng_sample_points)) # draw a line between the pixels if prev_pixel: coords = bresenham_line( (pixel_lat, pixel_lng), (prev_pixel['lat'], prev_pixel['lng'])) for pixel in coords: x, y = pixel pixel_y = self.lat_sample_points - x pixel_x = self.lng_sample_points - y for point in circ: x, y = point circ_x = pixel_x + x circ_y = pixel_y + y if circ_x >= self.lng_sample_points: circ_x = self.lng_sample_points - 1 if circ_y >= self.lat_sample_points: circ_y = self.lat_sample_points - 1 self.outfile[circ_y, circ_x] = alt + \ int(elevation_delta) prev_pixel = {'lat': pixel_lat, 'lng': pixel_lng}