def _compute_points(self): """Compute the alt=fct(dist) array and store it in c.points""" rasters = [get_raster(layer) for layer in self.layers] # Simplify input line with a tolerance of 2 m if self.nb_points < len(self.linestring.coords): linestring = self.linestring.simplify(12.5) else: linestring = self.linestring coords = self._create_points(linestring.coords, self.nb_points) zvalues = {} for i in xrange(0, len(self.layers)): zvalues[self.layers[i]] = [] for j in xrange(0, len(coords)): z = rasters[i].getVal(coords[j][0], coords[j][1]) zvalues[self.layers[i]].append(z) factor = lambda x: float(1) / (abs(x) + 1) zvalues2 = {} for i in xrange(0, len(self.layers)): zvalues2[self.layers[i]] = [] for j in xrange(0, len(zvalues[self.layers[i]])): s = 0 d = 0 if zvalues[self.layers[i]][j] is None: zvalues2[self.layers[i]].append(None) continue for k in xrange(-self.ma_offset, self.ma_offset + 1): p = j + k if p < 0 or p >= len(zvalues[self.layers[i]]): continue if zvalues[self.layers[i]][p] is None: continue s += zvalues[self.layers[i]][p] * factor(k) d += factor(k) zvalues2[self.layers[i]].append(s / d) dist = 0 prev_coord = None if self.json: profile = [] # If the renderer is a csv file else: profile = {'headers': ['Distance'], 'rows': []} for i in self.layers: profile['headers'].append(i) profile['headers'].append('Easting') profile['headers'].append('Northing') for j in xrange(0, len(coords)): if prev_coord is not None: dist += self._dist(prev_coord, coords[j]) alts = {} for i in xrange(0, len(self.layers)): if zvalues2[self.layers[i]][j] is not None: alts[self.layers[i]] = self._filter_alt( zvalues2[self.layers[i]][j]) if len(alts) > 0: rounded_dist = self._filter_dist(dist) if self.json: profile.append({ 'alts': alts, 'dist': rounded_dist, 'easting': self._filter_coordinate(coords[j][0]), 'northing': self._filter_coordinate(coords[j][1]) }) # For csv file else: temp = [rounded_dist] for i in alts.iteritems(): temp.append(i[1]) temp.append(self._filter_coordinate(coords[j][0])) temp.append(self._filter_coordinate(coords[j][1])) profile['rows'].append(temp) prev_coord = coords[j] return profile
def height(self): rasters = [get_raster(layer) for layer in self.layers] alt = self._filter_alt(rasters[0].getVal(self.lon, self.lat)) return {'height': str(alt)}