def generate_vector_height_map(self): """Generate height stops array for use with match expression in mapbox template""" vector_stops = [] if self.height_function_type == 'match': match_height = self.height_stops for row in self.data: # map height to JSON feature using height_property height = height_map(row[self.height_property], self.height_stops, self.height_default) # link to vector feature using data_join_property (from JSON object) vector_stops.append([row[self.data_join_property], height]) return vector_stops
def test_height_map_exact(): """Compute mapping for lookup value exactly matching numeric stop in stops""" stops = [[0.0, 0], [50.0, 5000.0], [1000.0, 100000.0]] assert height_map(50.0, stops, 42) == 5000.0
def test_height_map_default(): """Default value when look up does not match any stop in stops""" stops = [[0.0, 0], [50.0, 5000.0], [1000.0, 100000.0]] assert height_map(-1.0, stops, 42) == 0
def test_height_map_no_stops(): """Return default if length of stops argument is 0""" stops = [] assert height_map(117.0, stops, 42) == 42
def test_height_map_match(): """Interpolate height from numeric height stops""" match_stops = [['road', 1.0], ['fence', 15.0], ['wall', 10.0]] assert height_map('fence', match_stops, 0.0) == 15.0
def test_height_map(): """Interpolate height from numeric height stops""" stops = [[0.0, 0], [50.0, 5000.0], [1000.0, 100000.0]] assert height_map(117.0, stops, 0.0) == 11700.0