31 #ifndef __EMSCRIPTEN__
37 msg =
"CVImageGeoTiff::loadGeoTiff: File not found: " + geoTiffFile;
50 msg =
"CVImageGeoTiff::loadGeoTiff: JSON File not found: " + jsonFileName;
51 msg +=
"\nA GEOTiff file must have a JSON file aside with the same name.";
52 msg +=
"\nYou can generate this JSON file with the tool gdalinfo.";
60 cv::Mat imgGeoTiff = cv::imread(geoTiffFile,
61 cv::IMREAD_LOAD_GDAL | cv::IMREAD_ANYDEPTH);
63 if (imgGeoTiff.type() != CV_32FC1)
65 "GEOTiff image must be of 32-bit float type.",
70 std::ifstream jsonFile(jsonFileName);
75 vector<double> upperLeft;
76 vector<double> lowerRight;
82 description = jsonData[
"description"].get<
string>();
83 geocsc = jsonData[
"coordinateSystem"][
"wkt"].get<
string>();
84 size = jsonData[
"size"].get<vector<int>>();
85 upperLeft = jsonData[
"cornerCoordinates"][
"upperLeft"].get<vector<double>>();
86 lowerRight = jsonData[
"cornerCoordinates"][
"lowerRight"].get<vector<double>>();
87 _noDataValue = jsonData[
"bands"][0][
"noDataValue"].get<
double>();
89 catch (json::exception& e)
91 msg =
"Error reading JSON-File: " + jsonFileName;
92 msg +=
"\nException: ";
101 if (size.size() < 2 || size[0] != imgGeoTiff.cols || size[1] != imgGeoTiff.rows)
103 msg =
"Mismatch between geotiff image size and size json tag:";
104 msg +=
"\nGEOTiff image width : " + to_string(imgGeoTiff.cols);
105 msg +=
"\nGEOTiff image height: " + to_string(imgGeoTiff.rows);
106 msg +=
"\nJSON Size tag[0] : " + to_string(size[0]);
107 msg +=
"\nJSON Size tag[1] : " + to_string(size[1]);
117 msg =
"GeoTiff file seams not have WGS84 coordinates.";
124 _cvMat = imgGeoTiff.clone();
142 double latPerPix = dLatDEG / (double)
_cvMat.rows;
143 double lonPerPix = dLonDEG / (
double)
_cvMat.cols;
148 double pixPosLat = offsetLat / latPerPix;
149 double pixPosLon = offsetLon / lonPerPix;
152 pixPosLat =
_cvMat.rows - pixPosLat;
154 if (pixPosLat < 0.0 || pixPosLat >
_cvMat.rows - 1.0)
156 SL_LOG(
"Invalid pixPosLat %3.2f", pixPosLat);
159 if (pixPosLon < 0.0 || pixPosLon >
_cvMat.cols - 1.0)
161 SL_LOG(
"Invalid pixPosLon %3.2f", pixPosLon);
166 cv::Point2f pt((
float)pixPosLon, (
float)pixPosLat);
168 cv::getRectSubPix(
_cvMat, cv::Size(1, 1), pt, patch);
170 float heightMatPix =
_cvMat.at<
float>((int)pixPosLat, (
int)pixPosLon);
171 float heightMatSubPix = patch.at<
float>(0, 0);
172 return heightMatSubPix;
CVVec3d _upperleftLatLonAlt
CVVec3d _lowerRightLatLonAlt
Upper-left corner of DEM in WGS84 coords.
double _noDataValue
Lower-right corner of DEM in WGS84 coords.
void loadGeoTiff(const string &filename)
Loads a GEOTiff file into the OpenCV image matrix.
float getAltitudeAtLatLon(double lat, double lon) const
Returns the altitude in m at the given position in WGS84 latitude-longitude.
CVPixelFormatGL _format
OpenGL pixel format.
void clearData()
Deletes all data and resets the image parameters.
static CVPixelFormatGL cvType2glPixelFormat(int cvType)
Converts OpenCV mat type to OpenGL pixel format.
CVMat _cvMat
OpenCV mat matrix image type.
bool fileExists(const string &pathfilename)
Returns true if a file exists.
bool containsString(const string &container, const string &search)
Returns true if container contains the search string.
string getFileNameWOExt(const string &pathFilename)
Returns the filename without extension.
string getPath(const string &pathFilename)
Returns the path w. '\' of path-filename string.
void exitMsg(const char *tag, const char *msg, const int line, const char *file)
Terminates the application with a message. No leak checking.