I am using python to generate a json file which contains a lot of polygons and a value is assigned to each polygon, which looks like:
[{'cell':{'type':'Polygon', 'coordinates':[[[121,47],[122,48],[122,47],[121,47]]]}, 'value':2.45},
{'cell':{'type':'Polygon', 'coordinates':[[[120,48],[123,48.5],[122,48],[120,48]]]}, 'value':1.45},
...]
I want to plot these polygons on geojson.io and every cell is of color red. But the opacity of each polygon is dependent on the value, the higher value, the more opaque; the smaller value, the less opaque.
I think I should do normalization of all the values at first, and then I need to use the
Feature(properties={'fill':'#ff0000', 'opacity':normalized_value})
But I think this is a little bit complicated. Can I just use the original values for each cell in the properties, and the opacity will be automatically adjusted?
So I went onto geojson.io. And I got:
I'm ignoring the coordinates at the moment, as they take up too much space. First lets make a small class, that returns a dict. with the settings it must have, the colour and the opacity.
If you want to be able to use the cell format you have. You can do this.
This is not the best working system. When I executed it, and copied the output I got triangles that were in the top-right of china... However the triangles opacity were different.
I didn't really do anything with the shape, as that was not asked. However I made it possible to change the input to valid output. All red, with relative opacity.
You can check if it looks alright here. However hover over the shapes to see what there settings are. Mine come up blue, with the colour settings '#ff0000'.