Commit 4d2a6feb authored by Jonathan Lambrechts's avatar Jonathan Lambrechts
Browse files

read tiled geotiff

parent 16eadbc6
Pipeline #1322 passed with stage
in 34 minutes and 40 seconds
......@@ -73,10 +73,9 @@ slimPreEvaluatorGeoTIFF::slimPreEvaluatorGeoTIFF(const char *filename) {
if(GTIFKeyGet( _gtif, GTModelTypeGeoKey, &_modelType, 0, 1) != 1)
Msg::Error("no model type defined in geotiff file");
if(_modelType == ModelGeographic && GTIFKeyGet( _gtif, GeogAngularUnitsGeoKey, &_angularUnit, 0, 1) == 1)
if(_angularUnit != Angular_Degree)
Msg::Error("geotiff unit is not decimal degrees (Angular_Degree)");
if(_angularUnit != Angular_Degree)
Msg::Error("geotiff unit is not decimal degrees (Angular_Degree)");
printf("model type : %i\n", _modelType);
/*
double *tiepoint;
......@@ -84,11 +83,31 @@ slimPreEvaluatorGeoTIFF::slimPreEvaluatorGeoTIFF(const char *filename) {
TIFFGetField(_tiff, TIFFTAG_GEOTIEPOINTS, &count, &tiepoint);
TIFFGetField(_tiff, TIFFTAG_GEOPIXELSCALE, &count, &tiepoint);
*/
_data = new char[bitspersample/8*_sizex*_sizey];
for (int i = 0; i < _sizey; ++i) {
if(TIFFReadScanline(_tiff, _data+i*_sizex*bitspersample/8, i, 0) !=1)
Msg::Error("error reading tiff file %s", filename);
int tileWidth, tileLength;
int datasize = bitspersample/8;
_data = new char[datasize*_sizex*_sizey];
if (TIFFGetField(_tiff, TIFFTAG_TILEWIDTH, &tileWidth) ==1 &&
TIFFGetField(_tiff, TIFFTAG_TILELENGTH, &tileLength) ==1) {
int tileSize = TIFFTileSize(_tiff);
char *buf = new char[tileSize];
for (int y = 0; y < _sizey; y += tileLength){
for (int x = 0; x < _sizex; x += tileWidth){
TIFFReadTile(_tiff, buf, x, y, 0, 0);
for (int j = 0; j < tileLength && y+j < _sizey; ++j) {
int s0 = ((y+j)*_sizex+x)*datasize;
int s1 = j*tileWidth*datasize;
int l = std::min(tileWidth, _sizex - x) * datasize;
memcpy(_data+s0, buf+s1, l);
}
}
}
delete [] buf;
}
else {
for (int i = 0; i < _sizey; ++i) {
if(TIFFReadScanline(_tiff, _data+i*_sizex*datasize, i, 0) !=1)
Msg::Error("error reading tiff file %s", filename);
}
}
}
......
......@@ -5,6 +5,7 @@
#include "proj_api.h"
#include "unrefMesher.h"
#include "dgMessage.h"
#include "dgConfig.h"
static double evalPythonCallback(PyObject *callback, double x, double y, double z) {
PyObject *args = Py_BuildValue("(ddd)", x, y, z);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment