Geographic Information Systems Asked by mijfro on July 3, 2021
I constructed a GeoJSON file (exemple below) that works fine with http://geojson.io. This GeoJSON file has style properties e.g. ‘fill’ (hex colour) and ‘fill-opacity’. They appear on geojson.io but when I open the file in QGIS 3.10 by adding a vector layer, the colours properties don’t show.
{"type":"FeatureCollection", "features": [
{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[4.904782,46.160867],[4.932978,46.183458],[4.958471,46.153297],[4.926307,46.119968],[4.909106,46.129304],[4.903015,46.157966],[4.904782,46.160867]]]},"properties":{"code":"01001","densite":48.9,"fill":"#33a7c2","fill-opacity":0.5,"nom":"L'Abergement-Clémenciat","population":767,"stroke-width":0,"surface":15.7},"id":"0"},
{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[5.404077,46.007933],[5.426148,46.030981],[5.441272,46.025699],[5.444129,46.017196],[5.431219,45.983352],[5.424755,45.986633],[5.404077,46.007933]]]},"properties":{"code":"01002","densite":26.7,"fill":"#40b5c4","fill-opacity":0.5,"nom":"L'Abergement-de-Varey","population":243,"stroke-width":0,"surface":9.1},"id":"1"},
{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[5.327218,45.956848],[5.33756,45.984154],[5.347269,45.982477],[5.397014,45.981931],[5.413537,45.978836],[5.408842,45.942285],[5.386062,45.930905],[5.341149,45.948446],[5.327218,45.956848]]]},"properties":{"code":"01004","densite":574.7,"fill":"#2259a6","fill-opacity":0.5,"nom":"Ambérieu-en-Bugey","population":14081,"stroke-width":0,"surface":24.5},"id":"2"},
{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[4.886433,46.016032],[4.909751,46.01918],[4.947804,46.000368],[4.942665,45.979454],[4.927599,45.979931],[4.89574,45.979919],[4.88082,45.985732],[4.886433,46.016032]]]},"properties":{"code":"01005","densite":104.4,"fill":"#1f93c0","fill-opacity":0.5,"nom":"Ambérieux-en-Dombes","population":1671,"stroke-width":0,"surface":16},"id":"3"},
{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[5.570681,45.753687],[5.58358,45.762878],[5.590151,45.760441],[5.611119,45.749335],[5.614595,45.734707],[5.581117,45.740454],[5.570681,45.753687]]]},"properties":{"code":"01006","densite":18.3,"fill":"#55bec1","fill-opacity":0.5,"nom":"Ambléon","population":110,"stroke-width":0,"surface":6},"id":"4"},
{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[5.299163,45.997168],[5.31167,46.025402],[5.324878,46.041649],[5.334895,46.037575],[5.404077,46.007933],[5.424755,45.986633],[5.413537,45.978836],[5.397014,45.981931],[5.359756,45.995581],[5.347269,45.982477],[5.33756,45.984154],[5.299163,45.997168]]]},"properties":{"code":"01007","densite":79.9,"fill":"#289cc1","fill-opacity":0.5,"nom":"Ambronay","population":2684,"stroke-width":0,"surface":33.6},"id":"5"},
{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[5.309871,45.942847],[5.34196,45.945042],[5.361923,45.937116],[5.322747,45.922551],[5.309871,45.942847]]]},"properties":{"code":"01008","densite":144.2,"fill":"#1e88bc","fill-opacity":0.5,"nom":"Ambutrix","population":750,"stroke-width":0,"surface":5.2},"id":"6"},
{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[5.642366,45.807903],[5.662188,45.776358],[5.656838,45.760535],[5.64793,45.763158],[5.646657,45.771722],[5.642366,45.807903]]]},"properties":{"code":"01009","densite":48,"fill":"#33a7c2","fill-opacity":0.5,"nom":"Andert-et-Condon","population":336,"stroke-width":0,"surface":7},"id":"7"},
{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[5.759821,45.889161],[5.766034,45.936107],[5.816108,45.936625],[5.828334,45.938518],[5.815207,45.87666],[5.759821,45.889161]]]},"properties":{"code":"01010","densite":38,"fill":"#39adc3","fill-opacity":0.5,"nom":"Anglefort","population":1124,"stroke-width":0,"surface":29.6},"id":"8"},
{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[5.641231,46.216895],[5.645631,46.22045],[5.661482,46.230984],[5.693443,46.22128],[5.643649,46.177811],[5.634104,46.179186],[5.635595,46.184271],[5.641231,46.216895]]]},"properties":{"code":"01011","densite":25.5,"fill":"#46b8c3","fill-opacity":0.5,"nom":"Apremont","population":383,"stroke-width":0,"surface":15},"id":"9"},
{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[5.473186,45.989872],[5.483332,46.020687],[5.517273,46.023749],[5.550525,46.01624],[5.554992,46.005325],[5.522918,45.983055],[5.481082,45.970653],[5.473186,45.989872]]]},"properties":{"code":"01012","densite":15,"fill":"#59bfc0","fill-opacity":0.5,"nom":"Aranc","population":326,"stroke-width":0,"surface":21.7},"id":"10"},
{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[5.464421,45.914082],[5.474257,45.919993],[5.490901,45.913944],[5.525779,45.890373],[5.525134,45.863399],[5.512397,45.855919],[5.464421,45.914082]]]},"properties":{"code":"01013","densite":10.5,"fill":"#6dc6be","fill-opacity":0.5,"nom":"Arandas","population":148,"stroke-width":0,"surface":14.1},"id":"11"},
{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[5.659473,46.2918],[5.684926,46.31082],[5.725034,46.261067],[5.714583,46.256425],[5.659473,46.2918]]]},"properties":{"code":"01014","densite":142.6,"fill":"#1e88bc","fill-opacity":0.5,"nom":"Arbent","population":3379,"stroke-width":0,"surface":23.7},"id":"12"},
{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[5.604925,45.708015],[5.623456,45.719947],[5.640689,45.747767],[5.64793,45.763158],[5.656838,45.760535],[5.676472,45.708344],[5.676312,45.696625],[5.661048,45.694019],[5.617312,45.674177],[5.604925,45.708015]]]},"properties":{"code":"01015","densite":28.3,"fill":"#40b5c4","fill-opacity":0.5,"nom":"Arboys en Bugey","population":640,"stroke-width":0,"surface":22.6},"id":"13"},
{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[4.914201,46.481352],[4.929086,46.504022],[5.006992,46.477989],[5.006579,46.461765],[4.989191,46.459813],[4.914201,46.481352]]]},"properties":{"code":"01016","densite":26.4,"fill":"#40b5c4","fill-opacity":0.5,"nom":"Arbigny","population":462,"stroke-width":0,"surface":17.5},"id":"14"},
{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[5.465818,45.950228],[5.489177,45.947562],[5.501823,45.940984],[5.490901,45.913944],[5.474257,45.919993],[5.465818,45.950228]]]},"properties":{"code":"01017","densite":56.2,"fill":"#2fa4c2","fill-opacity":0.5,"nom":"Argis","population":438,"stroke-width":0,"surface":7.8},"id":"15"},
{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[5.558633,45.865141],[5.593227,45.862867],[5.612849,45.853302],[5.609256,45.848315],[5.573841,45.845877],[5.558633,45.865141]]]},"properties":{"code":"01019","densite":3.8,"fill":"#9ed9b8","fill-opacity":0.5,"nom":"Armix","population":26,"stroke-width":0,"surface":6.9},"id":"16"},
{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[4.801092,46.001306],[4.801745,46.007185],[4.808435,46.007398],[4.822385,46.004403],[4.837319,45.973237],[4.801092,46.001306]]]},"properties":{"code":"01021","densite":248,"fill":"#1f78b4","fill-opacity":0.5,"nom":"Ars-sur-Formans","population":1389,"stroke-width":0,"surface":5.6},"id":"17"},
{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[5.703578,45.874708],[5.704561,45.861516],[5.696419,45.861517],[5.678995,45.862864],[5.703578,45.874708]]]},"properties":{"code":"01022","densite":371.8,"fill":"#2168ad","fill-opacity":0.5,"nom":"Artemare","population":1227,"stroke-width":0,"surface":3.3},"id":"18"},
{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[4.865908,46.375624],[4.887947,46.402769],[4.897991,46.399032],[4.896086,46.384523],[4.876317,46.369452],[4.865908,46.375624]]]},"properties":{"code":"01023","densite":13.4,"fill":"#5fc1c0","fill-opacity":0.5,"nom":"Asnières-sur-Saône","population":63,"stroke-width":0,"surface":4.7},"id":"19"},
{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[5.148056,46.298647],[5.219786,46.315016],[5.217267,46.292878],[5.16267,46.255984],[5.150862,46.275507],[5.148056,46.298647]]]},"properties":{"code":"01024","densite":173,"fill":"#1e83ba","fill-opacity":0.5,"nom":"Attignat","population":3270,"stroke-width":0,"surface":18.9},"id":"20"}
]}
you have to use data defined overrides for that, see picture below
if you want to take the opacity field in count, we have to change the data defined override and use an expression to put the separate opacity and color fields together. QGIS is expecting the opacity information within the color value as an alpha value between 0 and 100. The expression then would be:
set_color_part( "fill",'alpha', "fill-opacity" *100)
in the data defined override dialog select "edit" and enter the expression:
Correct answer by eurojam on July 3, 2021
A little change and it worked for me.
set_color_part( "fill",'alpha', to_int(255*"fill-opacity"))
Answered by Leandro on July 3, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP