jorgealmerio / valuetool

QGis plugin to display in a table or plot the values from the visible raster layers at the current mouse position
4 stars 7 forks source link

More precise layer validity check #19

Closed jfbourdon closed 3 years ago

jfbourdon commented 3 years ago

The current way (layer.dataProvider().xSize() & layer.dataProvider().ySize()) was returning 0 / False for some combinaison of raster width and height. Using and instead of & solve the issue:

Explanation:

10 & 15  # return 10 / True
10 & 16  # return 0 / False

# In binary representation:
# 10 => 01010
# 15 => 01111
# 16 => 10000

# So a bitwise AND will return :
01010 & 01111  # return 01010 or simply 10 (once converted back to decimals) / True
01010 & 10000  # return 00000 or simply 0 / False

# But a logical AND will return:
10 and 15  # return 15 / True
10 and 16  # return 16 / True
jfbourdon commented 3 years ago

The provider type is now checked to make sure no WMS raster layer or similar are passing through, only thoses read by GDAL. However, I'm not sure if it covers all cases. Should fix #18.