def generate_vector_numeric_map(self, numeric_property): """Generate stops array for use with match expression in mapbox template""" vector_stops = [] function_type = getattr(self, '{}_function_type'.format(numeric_property)) lookup_property = getattr(self, '{}_property'.format(numeric_property)) numeric_stops = getattr(self, '{}_stops'.format(numeric_property)) default = getattr(self, '{}_default'.format(numeric_property)) if function_type == 'match': match_width = numeric_stops # if join data specified as filename or URL, parse JSON to list of Python dicts if type(self.data) == str: self.data = geojson_to_dict_list(self.data) for row in self.data: # map value to JSON feature using the numeric property value = numeric_map(row[lookup_property], numeric_stops, default) # link to vector feature using data_join_property (from JSON object) vector_stops.append([row[self.data_join_property], value]) return vector_stops
def generate_vector_width_map(self): """Generate width stops array for use with match expression in mapbox template""" vector_stops = [] if self.line_width_function_type == 'match': match_width = self.line_width_stops for row in self.data: # map width to JSON feature using width_property width = numeric_map(row[self.line_width_property], self.line_width_stops, self.line_width_default) # link to vector feature using data_join_property (from JSON object) vector_stops.append([row[self.data_join_property], width]) return vector_stops
def test_numeric_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 numeric_map(50.0, stops, 42) == 5000.0
def test_numeric_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 numeric_map(-1.0, stops, 42) == 0
def test_numeric_map_no_stops(): """Return default if length of stops argument is 0""" stops = [] assert numeric_map(117.0, stops, 42) == 42
def test_numeric_map_match(): """Match value from numeric stops""" match_stops = [['road', 1.0], ['fence', 15.0], ['wall', 10.0]] assert numeric_map('fence', match_stops, 0.0) == 15.0
def test_numeric_map(): """Map interpolated (or matched) value from numeric stops""" stops = [[0.0, 0], [50.0, 5000.0], [1000.0, 100000.0]] assert numeric_map(117.0, stops, 0.0) == 11700.0