go-spatial icon indicating copy to clipboard operation
go-spatial copied to clipboard

Get incorrect value when the type of the tif is float32

Open IBAS0742 opened this issue 4 years ago • 0 comments

https://github.com/jblindsay/go-spatial/blob/master/geospatialfiles/raster/geotiff/geotiff.go#L851

I find a bug, when I try to read a tif and only import the paht of 'geospatialfiles/raster/geotiff". The blockWidth's value is 128, and my tif files size is 15*12, so I get an error value from the 2nd row.

I change the code and get all correct value, I think the code of decode of float64 maybe wrong also.

case 32:
  for y := ymin; y < ymax; y++ {
	  for x := xmin; x < xmax; x++ {
		  if g.off <= len(g.buf) {
			  bits := g.ByteOrder.Uint32(g.buf[g.off : g.off+4])
			  float := math.Float32frombits(bits)
			  i := y*width + x
			  g.Data[i] = float64(float)
			  g.off += 4
		  }
	  }
	  if xmax * 4 < blockWidth {
		  g.off = g.off - xmax * 4 + blockWidth * 4
	  }
  }

My tif file can be found here

IBAS0742 avatar Oct 19 '21 13:10 IBAS0742