sbenten / d3MapRenderer

A python QGIS plugin to export of polygons, polylines and point vector layers from shapefiles to topojson for display within a web page using the d3 JavaScript library, with additional options of popup information via d3-tip, charts from c3.js and a legend.
http://maprenderer.org/d3/
MIT License
32 stars 3 forks source link

Assigning incorrect colors for a stylized layer #35

Closed smitty1788 closed 7 years ago

smitty1788 commented 7 years ago

d3 renderer seems to be applying incorrect colors to certain polygons. I have a side by side view below. You can see the polygons colored for 1 in QGIS are being assigned the color for 2 in the generated map. Thanks so much

d3.png

sbenten commented 7 years ago

Which branch is the code from? 0.10 or the Master branch? Is it a categorised or graduated symbol layer? Lastly (honest) can you past the output from the Qgis Log Messages panel for the plugin. Should help me figure out what it's doing wrong. Thanks

sbenten commented 7 years ago

Failed to replicate it with the Open Data off the Washington DC portal...however, I can see that it hasn't added the correct CSS class to any of the homicide class in your example. I've run both categorized and graduated symbologies to no avail. Attached are the log messages for each as an example for you to post back.

2017-01-27T10:06:06 0 model EXPORT start ================================================== 2017-01-27T10:06:06 0 model Title = [2016 Homicides] 2017-01-27T10:06:06 0 model Header = [False] 2017-01-27T10:06:06 0 model Width = [800] 2017-01-27T10:06:06 0 model Height = [600] 2017-01-27T10:06:06 0 model Main layer = [2016Homicides] 2017-01-27T10:06:06 0 model IDField = [GEOID] 2017-01-27T10:06:06 0 model Projection = [Albers] 2017-01-27T10:06:06 0 model Simplify = [] 2017-01-27T10:06:06 0 model Output = [D:\Downloads\Temp] 2017-01-27T10:06:06 0 model Zoom/Pan = [False] 2017-01-27T10:06:06 0 model Legend = [True] 2017-01-27T10:06:06 0 model LegendPos = [Top Left] 2017-01-27T10:06:06 0 model IncExtras = [False] 2017-01-27T10:06:06 0 model Extras = [2016Homicides] 2017-01-27T10:06:06 0 model IncPopup = [True] 2017-01-27T10:06:06 0 model PopupPos = [Bubble] 2017-01-27T10:06:06 0 model Popup = [

NUMPOINTS{NUMPOINTS}
] 2017-01-27T10:06:06 0 model IncViz = [False] 2017-01-27T10:06:06 0 model Chart = [Line Chart] 2017-01-27T10:06:06 0 model VizWidth = [240] 2017-01-27T10:06:06 0 model DataRanges = [] 2017-01-27T10:06:06 0 model Labels = [] 2017-01-27T10:06:06 0 model EXPORT copying folders and files 2017-01-27T10:06:06 0 model EXPORT 2016Homicides 2017-01-27T10:06:07 0 qgisWrapper Adding field: d3Css 2017-01-27T10:06:07 0 model CATEGORIZED: idx NUMPOINTS 0::0::FILL SYMBOL (1 layers) color 255,255,178,255:1 1::1::FILL SYMBOL (1 layers) color 255,215,109,255:1 2::2::FILL SYMBOL (1 layers) color 254,166,73,255:1 3::3::FILL SYMBOL (1 layers) color 248,108,48,255:1 4::4::FILL SYMBOL (1 layers) color 230,47,33,255:1 ::::FILL SYMBOL (1 layers) color 189,0,38,255:1

2017-01-27T10:06:07 0 model setCategorizedSymbol 2017-01-27T10:06:07 0 model Filter: "NUMPOINTS" = 0 2017-01-27T10:06:07 0 model Filter: "NUMPOINTS" = 1 2017-01-27T10:06:07 0 model Filter: "NUMPOINTS" = 2 2017-01-27T10:06:07 0 model Filter: "NUMPOINTS" = 3 2017-01-27T10:06:07 0 model Filter: "NUMPOINTS" = 4 2017-01-27T10:06:07 0 model Filter: "NUMPOINTS" = 2017-01-27T10:06:07 0 model EXPORT popup data 2017-01-27T10:06:07 0 model EXPORT complete ========================================================

2017-01-27T10:09:17 0 model EXPORT start ================================================== 2017-01-27T10:09:17 0 model Title = [2016 Homicides Graduated Colors] 2017-01-27T10:09:17 0 model Header = [False] 2017-01-27T10:09:17 0 model Width = [800] 2017-01-27T10:09:17 0 model Height = [800] 2017-01-27T10:09:17 0 model Main layer = [2016Homicides] 2017-01-27T10:09:17 0 model IDField = [GEOID] 2017-01-27T10:09:17 0 model Projection = [Albers] 2017-01-27T10:09:17 0 model Simplify = [] 2017-01-27T10:09:17 0 model Output = [D:\Downloads\Temp] 2017-01-27T10:09:17 0 model Zoom/Pan = [False] 2017-01-27T10:09:17 0 model Legend = [False] 2017-01-27T10:09:17 0 model LegendPos = [Top Left] 2017-01-27T10:09:17 0 model IncExtras = [False] 2017-01-27T10:09:17 0 model Extras = [2016Homicides] 2017-01-27T10:09:17 0 model IncPopup = [True] 2017-01-27T10:09:17 0 model PopupPos = [Bubble] 2017-01-27T10:09:17 0 model Popup = [

NUMPOINTS{NUMPOINTS}
] 2017-01-27T10:09:17 0 model IncViz = [False] 2017-01-27T10:09:17 0 model Chart = [Line Chart] 2017-01-27T10:09:17 0 model VizWidth = [240] 2017-01-27T10:09:17 0 model DataRanges = [] 2017-01-27T10:09:17 0 model Labels = [] 2017-01-27T10:09:17 0 model EXPORT copying folders and files 2017-01-27T10:09:17 0 model EXPORT 2016Homicides 2017-01-27T10:09:17 0 qgisWrapper Adding field: d3Css 2017-01-27T10:09:17 0 model GRADUATED: attr NUMPOINTS 0 - 0.8:: 0.0000 - 0.8000 ::FILL SYMBOL (1 layers) color 254,240,217,255 0.8 - 1.6:: 0.8000 - 1.6000 ::FILL SYMBOL (1 layers) color 253,204,138,255 1.6 - 2.4:: 1.6000 - 2.4000 ::FILL SYMBOL (1 layers) color 252,141,89,255 2.4 - 3.2:: 2.4000 - 3.2000 ::FILL SYMBOL (1 layers) color 227,74,51,255 3.2 - 4:: 3.2000 - 4.0000 ::FILL SYMBOL (1 layers) color 179,0,0,255

2017-01-27T10:09:17 0 model setGraduatedSymbol 2017-01-27T10:09:17 0 model Filter: "NUMPOINTS" >= 0.0 and "NUMPOINTS" <= 0.8 2017-01-27T10:09:17 0 model Filter: "NUMPOINTS" >= 0.8 and "NUMPOINTS" <= 1.6 2017-01-27T10:09:17 0 model Filter: "NUMPOINTS" >= 1.6 and "NUMPOINTS" <= 2.4 2017-01-27T10:09:17 0 model Filter: "NUMPOINTS" >= 2.4 and "NUMPOINTS" <= 3.2 2017-01-27T10:09:17 0 model Filter: "NUMPOINTS" >= 3.2 and "NUMPOINTS" <= 4.0 2017-01-27T10:09:17 0 model EXPORT popup data 2017-01-27T10:09:17 0 model EXPORT complete =========================================================

smitty1788 commented 7 years ago

Simon,

Sorry for the delay. I'm not at my work computer at the moment. I was using the 0.10 branch. The symbology was graduated. I will reply with the log as soon as I sit down at the computer when I get into work.

sbenten commented 7 years ago

No worries. If you could also add a screenshot of the symbols it would be of help. I suspect the values in the symbology are not correctly interpreted in the plugin, and the values in the data are on the cusp. For example, the plugin uses "NUMPOINTS" >= 0.8 and "NUMPOINTS" <= 1.6 to filter the data and assign the style class to all those records. It might be better for the plugin to use "NUMPOINTS" >= 0.8 and "NUMPOINTS" < 1.6 and on the last graduation just "NUMPOINTS" >= 3.2 Thanks

smitty1788 commented 7 years ago

I think what you just listed might be the exact problem, which I can probably fix myself by just changing the ranges slightly. Here is everything though. Below is the log. I'm also linking the shapefile and style file I used for this.

http://pc.cd/otQotalK

On another note, I just want to say this plugin is amazing for production flow. I use it for producing probably 4-5 maps per week. Putting together the D3 code by hand is obviously doable, but production would really slow down. This is speeding up everything! Please continue to develop this as its so great! More style options are always welcome too =p

2017-01-27T08:12:59 0 osHelper Windows 2017-01-27T08:13:48 0 model 2.18.3 2017-01-27T08:13:48 0 model 2.7.4 (default, Apr 6 2013, 19:54:46) [MSC v.1500 32 bit (Intel)] 2017-01-27T08:13:48 0 osHelper Windows 2017-01-27T08:13:48 0 osHelper Windows 2017-01-27T08:13:48 0 osHelper Windows 2017-01-27T08:13:48 0 winHelper Query registry for HKEY_CURRENT_USER\Software\node.js\InstallPath 2017-01-27T08:13:48 2 winHelper No more data is available: Software\node.js 2017-01-27T08:13:48 0 osHelper Windows 2017-01-27T08:13:48 0 osHelper Windows 2017-01-27T08:13:48 0 osHelper Windows 2017-01-27T08:13:48 0 winHelper Query registry for HKEY_CURRENT_USER\Software\node.js\InstallPath 2017-01-27T08:13:48 2 winHelper No more data is available: Software\node.js 2017-01-27T08:14:17 0 model EXPORT start ================================================== 2017-01-27T08:14:17 0 model Title = [Homicide in 2015] 2017-01-27T08:14:17 0 model Header = [True] 2017-01-27T08:14:17 0 model Width = [800] 2017-01-27T08:14:17 0 model Height = [600] 2017-01-27T08:14:17 0 model Main layer = [Homicide_CT] 2017-01-27T08:14:17 0 model IDField = [OBJECTID] 2017-01-27T08:14:17 0 model Projection = [Miller] 2017-01-27T08:14:17 0 model Simplify = [] 2017-01-27T08:14:17 0 model Output = [G:\DC Policy Center\Crime Incidents\Maps\Homicide] 2017-01-27T08:14:17 0 model Zoom/Pan = [True] 2017-01-27T08:14:17 0 model Legend = [True] 2017-01-27T08:14:17 0 model LegendPos = [Bottom Left] 2017-01-27T08:14:17 0 model IncExtras = [False] 2017-01-27T08:14:17 0 model Extras = [Homicide_CT] 2017-01-27T08:14:17 0 model IncPopup = [True] 2017-01-27T08:14:17 0 model PopupPos = [Bubble] 2017-01-27T08:14:17 0 model Popup = [

Homicide_3{Homicide_3}
] 2017-01-27T08:14:17 0 model IncViz = [False] 2017-01-27T08:14:17 0 model Chart = [Line Chart] 2017-01-27T08:14:17 0 model VizWidth = [240] 2017-01-27T08:14:17 0 model DataRanges = [] 2017-01-27T08:14:17 0 model Labels = [] 2017-01-27T08:14:17 0 model EXPORT copying folders and files 2017-01-27T08:14:18 0 model EXPORT Homicide_CT 2017-01-27T08:14:18 0 qgisWrapper Adding field: d3Css 2017-01-27T08:14:18 0 model GRADUATED: attr Homicide_3 0 - 0::No Homicides::FILL SYMBOL (1 layers) color 166,166,166,255 0.1 - 1::1::FILL SYMBOL (1 layers) color 254,240,217,255 1 - 2::2::FILL SYMBOL (1 layers) color 253,216,164,255 2 - 3::3::FILL SYMBOL (1 layers) color 252,183,121,255 3 - 4::4::FILL SYMBOL (1 layers) color 252,141,89,255 4 - 5::5::FILL SYMBOL (1 layers) color 235,96,63,255 5 - 6::6::FILL SYMBOL (1 layers) color 211,49,33,255 6 - 7::7::FILL SYMBOL (1 layers) color 179,0,0,255

2017-01-27T08:14:18 0 model setGraduatedSymbol 2017-01-27T08:14:18 0 model Filter: "Homicide_3" >= 0.0 and "Homicide_3" <= 0.0 2017-01-27T08:14:19 0 model Filter: "Homicide_3" >= 0.1 and "Homicide_3" <= 1.0 2017-01-27T08:14:19 0 model Filter: "Homicide_3" >= 1.0 and "Homicide_3" <= 2.0 2017-01-27T08:14:19 0 model Filter: "Homicide_3" >= 2.0 and "Homicide_3" <= 3.0 2017-01-27T08:14:19 0 model Filter: "Homicide_3" >= 3.0 and "Homicide_3" <= 4.0 2017-01-27T08:14:19 0 model Filter: "Homicide_3" >= 4.0 and "Homicide_3" <= 5.0 2017-01-27T08:14:19 0 model Filter: "Homicide_3" >= 5.0 and "Homicide_3" <= 6.0 2017-01-27T08:14:19 0 model Filter: "Homicide_3" >= 6.0 and "Homicide_3" <= 7.0 2017-01-27T08:14:19 0 model EXPORT popup data 2017-01-27T08:14:20 0 model EXPORT complete =========================================================

sbenten commented 7 years ago

Actually the Qgis source code has it working the other way: QString filterFunc = QString( "%1 > %2 AND %1 <= %3" ) .arg( attrName.replace( "\"", "\"\"" ) ) .arg( mLowerValue ).arg( mUpperValue ); I've altered the plugin to work this way with the condition of ">=" for the lowest range of values. Works now with your example shp (thanks for that). Just checking I haven't regressed anything... Yeah, some more styles would be good, please raise an issue for anything not listed. Currently I'm refactoring the master branch to get some end to end unit tests in place before the Qgis 3 upgrade. Then it'll be back to more styles ;)

sbenten commented 7 years ago

Fixing on Master as part of code refactoring