Select multiple values from a jason file


I try to visualize several neighborhoods at the same time in my app. Using a slider. However, when I add this slider in my code, it only takes the relevant district. I want if the slider shows 8 for example. That I see district 0 to 8. Can someone help me?

This my code:

These are my Parameters:
class Parametrization(ViktorParametrization):
trees = NumberField(“Trees”, default=10, min=10, max=10000, step=10, suffix=“pieces”, variant=“slider”)
green_roofs = NumberField(“Green_roofs”, default=10, min=10, max=10000, step=10, suffix=“m2”, variant=“slider”)
rain_barrels = NumberField(“Rain_barrels”, default=10, min=10, max=10000, step=10, suffix=“pieces”, variant=“slider”)
intensity = NumberField(“Intensity”, default=1, min=1, max=44, step=1, suffix=“hours”, variant=“slider”)
# rain = NumberField(“Rain”, default=5, min=5, max=100, step=5, suffix=“mm/h”, variant=“slider”)
# size = NumberField(“Size”, default=1, min=1, max=44, step=1, suffix=“%”, variant=“slider”)
# size = OptionField(‘Size’, options=[‘0’, ‘1’, ‘2’,‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’, ‘10’, ‘11’, ‘12’, ‘13’, ‘14’, ‘15’, ‘16’, ‘17’, ‘18’, ‘19’, ‘20’, ‘21’, ‘22’, ‘23’, ‘24’, ‘25’, ‘26’, ‘27’, ‘28’, ‘29’, ‘30’, ‘31’, ‘32’, ‘33’, ‘34’, ‘35’, ‘36’, ‘37’, ‘38’, ‘39’, ‘40’, ‘41’, ‘42’, ‘43’], default=‘0’)
size = OptionField(‘Size’, options=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43], default=‘0’)
rain = OptionField(‘Rain’, options=[‘5’, ‘10’, ‘15’, ‘20’, ‘25’, ‘30’, ‘35’, ‘40’, ‘45’, ‘50’, ‘55’, ‘60’, ‘65’, ‘70’, ‘75’, ‘80’, ‘85’, ‘90’, ‘95’, ‘100’], default=‘5’)
groenvakken = OptionField(‘Groenvakken’, options=[‘Aan’, ‘Uit’, ‘Aan1’], default=‘Aan’)
waterdelen = OptionField(‘Waterdelen’, options=[‘Aan’, ‘Uit’, ‘Aan1’], default=‘Aan’)
set_params_btn = SetParamsButton(“Set params”, “set_param_a”, longpoll=True)
button = DownloadButton(‘Perform download’, method=‘perform_download’)

Hi Ties,

First, it might be nice to know that you can use ``` before and after text to format it as code, that makes it easier to read. If you use multiple lines, you can even add the language so the syntax highlights. like this:

def example_code(a)
   return a -1

your code can be summarised as follows

list_features = [ ]
for i in range(len(data(features))): # for every feature in my data
    list_coordinates = [] # create a list of coordinates 
    for j in range( ...)  :  # for every point in my feature, convert it to RD
         ... bla bla ... 
    # convert the list_coordinates to a mappolygon, and add it to the list_features 
    list_features.append(MapPolygon(list_coordinates, color=color))

In order to only plot once, you would not use the first loop for i in all_features, but only plot for the selected district:

list_features = [ ]
i = params.selected_district.
list_coordinates = [] # create a list of coordinates 
for j in range( ...)  :  # for every point in my feature, convert it to RD
    ... bla bla ... 
# convert the list_coordinates to a mappolygon, and add it to the list_features 
list_features.append(MapPolygon(list_coordinates, color=color))

Thanks Puijterwaal for your help.

        f = open('wijken.json')
        data = json.load(f)
        list_features = []
        i = params.selected_district.size
        list_coordinates = []
        for j in range(len(data["features"][i]["geometry"]["coordinates"][0])):
            coordinates_rd = tuple(data["features"][i]["geometry"]["coordinates"][0][j])
            lat, lon = RDWGSConverter.from_rd_to_wgs(coordinates_rd)
            print(lat, lon)
            list_coordinates.append(MapPoint(lat, lon))
        list_features.append(MapPolygon(list_coordinates, color=Color(60, 123, 250)))

I have now this but it still doesent work.

Hi Ties,

You will have to be a little more specific, what does not work? Does it not plot at all? Does it not plot the right geometry? Does it throw an error? That will help you figuring out the problem!

kind regards,
Paulien

It does not plot a geometry.
This is my error code:
File ************* line 103, in getattr
return object.getattribute(self, k)
AttributeError: ‘Munch’ object has no attribute ‘selected_district’