Add default geo transform for global maps if it is not specified.

This commit is contained in:
kalbl
2016-10-25 23:32:08 +02:00
parent d2539b7ac5
commit c3eae0347c
2 changed files with 32 additions and 11 deletions

View File

@@ -438,8 +438,24 @@ namespace globebrowsing {
}
std::array<double, 6> TileDataset::getGeoTransform() const {
std::array<double, 6> padfTransform;
CPLErr err = _dataset->GetGeoTransform(&padfTransform[0]);
if (err == CE_Failure) {
GeodeticPatch globalCoverage(Geodetic2(0,0), Geodetic2(M_PI / 2, M_PI));
padfTransform[1] = Angle<Scalar>::fromRadians(
globalCoverage.size().lon).asDegrees() / _dataset->GetRasterXSize();
padfTransform[5] = -Angle<Scalar>::fromRadians(
globalCoverage.size().lat).asDegrees() / _dataset->GetRasterYSize();
padfTransform[0] = Angle<Scalar>::fromRadians(
globalCoverage.getCorner(Quad::NORTH_WEST).lon).asDegrees();
padfTransform[3] = Angle<Scalar>::fromRadians(
globalCoverage.getCorner(Quad::NORTH_WEST).lat).asDegrees();
padfTransform[2] = 0;
padfTransform[4] = 0;
}
return padfTransform;
}
//////////////////////////////////////////////////////////////////////////////////
// ReadTileData helper functions //
@@ -447,11 +463,8 @@ namespace globebrowsing {
PixelCoordinate TileDataset::geodeticToPixel(const Geodetic2& geo) const {
double padfTransform[6];
CPLErr err = _dataset->GetGeoTransform(padfTransform);
ghoul_assert(err != CE_Failure, "Failed to get transform");
std::array<double, 6> padfTransform = getGeoTransform();
Scalar Y = Angle<Scalar>::fromRadians(geo.lat).asDegrees();
Scalar X = Angle<Scalar>::fromRadians(geo.lon).asDegrees();
@@ -484,10 +497,9 @@ namespace globebrowsing {
}
Geodetic2 TileDataset::pixelToGeodetic(const PixelCoordinate& p) const {
double padfTransform[6];
CPLErr err = _dataset->GetGeoTransform(padfTransform);
ghoul_assert(err != CE_Failure, "Failed to get transform");
std::array<double, 6> padfTransform = getGeoTransform();
Geodetic2 geodetic;
// Should be using radians and not degrees?
geodetic.lon = padfTransform[0] + p.x * padfTransform[1] + p.y * padfTransform[2];
geodetic.lat = padfTransform[3] + p.x * padfTransform[4] + p.y * padfTransform[5];
return geodetic;

View File

@@ -147,6 +147,15 @@ namespace globebrowsing {
// ReadTileData helper functions //
//////////////////////////////////////////////////////////////////////////////////
/**
Returns the geo transform from raster space to projection coordinates as defined
by GDAL.
If the transform is not available, the function returns a transform to map
the pixel coordinates to cover the whole geodetic lat long space.
*/
std::array<double, 6> getGeoTransform() const;
PixelCoordinate geodeticToPixel(const Geodetic2& geo) const;
Geodetic2 pixelToGeodetic(const PixelCoordinate& p) const;
IODescription getIODescription(const TileIndex& tileIndex) const;
@@ -189,4 +198,4 @@ namespace globebrowsing {
} // namespace globebrowsing
} // namespace openspace
#endif // __TILE_DATASET_H__
#endif // __TILE_DATASET_H__