orcaomar / qgis_range_filters

A widget for doing range filtering of QGIS data from the legend area.
GNU General Public License v3.0
6 stars 0 forks source link

The plugin fails in QGIS 3.24.2 #1

Closed 9ls1 closed 1 year ago

9ls1 commented 2 years ago

Just what I was looking for. Downloaded the plugin as a zip-file and installed it from zip in QGIS 3.24.2. Added a polygon layer and added the the plugin to the legend-property, but it throws an error:

`An error has occurred while executing Python code:

TypeError: unsupported operand type(s) for -: 'NoneType' and 'NoneType' Traceback (most recent call last): File "C:\Users/.../AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\qgis_range_filters-master\data_layer_range_filter_widget.py", line 165, in createWidget return DataLayerRangeFilterWidget(layer) File "C:\Users/.../AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\qgis_range_filters-master\data_layer_range_filter_widget.py", line 116, in init self._add_slider(field.name()) File "C:\Users/.../AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\qgis_range_filters-master\data_layer_range_filter_widget.py", line 133, in _add_slider slider = RangeSlider(self, field_name, field_min, field_max) File "C:\Users/.../AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\qgis_range_filters-master\data_layer_range_filter_widget.py", line 38, in init self.on_value_changed() File "C:\Users/.../AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\qgis_range_filters-master\data_layer_range_filter_widget.py", line 89, in on_value_changed (start_actual_val, end_actual_val) = self._getStartEndValues() File "C:\Users/.../AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\qgis_range_filters-master\data_layer_range_filter_widget.py", line 76, in _getStartEndValues start_actual_val = (start_slider_val/100.0) * (self.fmax - self.fmin) + self.fmin TypeError: unsupported operand type(s) for -: 'NoneType' and 'NoneType'`

Do you have any plans updating/supporting the plugin? Or have you asked QGIS to include such an option in the core version?

agiudiceandrea commented 1 year ago

@9ls1, are your fields numeric?

9ls1 commented 1 year ago

The data set contains several fields: some string, integer and real: image

agiudiceandrea commented 1 year ago

@9ls1, it seems to me the issue is due to the fact that the plugins only obviously calculates the min and max values for numeric fields, so the non numeric fields trigger the error in the line start_actual_val = (start_slider_val/100.0) * (self.fmax - self.fmin) + self.fmin, since self.fmax and self.fmin are None.

9ls1 commented 1 year ago

Ok, so the data set can ONLY have numeric fields, no combination with some fields being numeric, others being string?

agiudiceandrea commented 1 year ago

@9ls1, I think I found the actual cause: not the non numeric fields (which are not used by the plugin), but the numeric fields that have all the values NULL.

9ls1 commented 1 year ago

@agiudiceandrea, @orcaomar: Finally, I remembered this and found the time to look closer into the matter. My findings so far:

  1. A numeric field cannot have ALL their values equal to NULL (as @agiudiceandrea states in his/her comment).
  2. It seems like the maximum number of type numeric and integer fields is four. If I have more then four numeric fields I get the error message.
  3. The layer has 23 features. This gets narrowed down to 16 when adding the "Data Range Filter". Why?
  4. The slider "floors" the maximum value in the field? A polygon in my data set has the maximum value = 74797,9247. The slider's max. value (on the right side) shows 74797 resulting in the polygon not being visible (included).
  5. The layer has four numeric fields. However in the "Filter" I see only: "fid" > 4.000000 AND "fid" < 34.000000 AND "artype" > 12.000000 AND "artype" < 60.000000 AND "areal" > 372.704900 AND "areal" < 74797.924700 Why is not delta_m2 included in the filter? It is included in the legend in the layers panel.
  6. Removing the legend widget in a) Layers properties is not enough. One has to also b) clear the Filter. Shouldn't doing a) do the trick alone?

Anyway, I find this legend widget very useful and would really like to see it included in QGIS. Any chances for that?

Four numeric fields: 4numericfields

23 features: 23features_beforeslider

16 features filtered: 16features_afterslider

orcaomar commented 1 year ago

Hey all, sorry I haven't looked at this plugin in quite a while but I'm stoked that others see it could be useful.. and maybe even use it! I'll look into this in the next week or so, try to tidy it up a bit and include a number of different types of fields on the latest QGIS build

orcaomar commented 1 year ago

This is resolved by this:

722a19a

which simply makes sure that the numeric field being processed actually has a valid min and max. Thanks @9ls1