mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-05 02:20:11 -05:00
Add default geo transform for global maps if it is not specified.
This commit is contained in:
@@ -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 //
|
// ReadTileData helper functions //
|
||||||
@@ -447,11 +463,8 @@ namespace globebrowsing {
|
|||||||
|
|
||||||
PixelCoordinate TileDataset::geodeticToPixel(const Geodetic2& geo) const {
|
PixelCoordinate TileDataset::geodeticToPixel(const Geodetic2& geo) const {
|
||||||
|
|
||||||
double padfTransform[6];
|
std::array<double, 6> padfTransform = getGeoTransform();
|
||||||
CPLErr err = _dataset->GetGeoTransform(padfTransform);
|
|
||||||
|
|
||||||
ghoul_assert(err != CE_Failure, "Failed to get transform");
|
|
||||||
|
|
||||||
Scalar Y = Angle<Scalar>::fromRadians(geo.lat).asDegrees();
|
Scalar Y = Angle<Scalar>::fromRadians(geo.lat).asDegrees();
|
||||||
Scalar X = Angle<Scalar>::fromRadians(geo.lon).asDegrees();
|
Scalar X = Angle<Scalar>::fromRadians(geo.lon).asDegrees();
|
||||||
|
|
||||||
@@ -484,10 +497,9 @@ namespace globebrowsing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Geodetic2 TileDataset::pixelToGeodetic(const PixelCoordinate& p) const {
|
Geodetic2 TileDataset::pixelToGeodetic(const PixelCoordinate& p) const {
|
||||||
double padfTransform[6];
|
std::array<double, 6> padfTransform = getGeoTransform();
|
||||||
CPLErr err = _dataset->GetGeoTransform(padfTransform);
|
|
||||||
ghoul_assert(err != CE_Failure, "Failed to get transform");
|
|
||||||
Geodetic2 geodetic;
|
Geodetic2 geodetic;
|
||||||
|
// Should be using radians and not degrees?
|
||||||
geodetic.lon = padfTransform[0] + p.x * padfTransform[1] + p.y * padfTransform[2];
|
geodetic.lon = padfTransform[0] + p.x * padfTransform[1] + p.y * padfTransform[2];
|
||||||
geodetic.lat = padfTransform[3] + p.x * padfTransform[4] + p.y * padfTransform[5];
|
geodetic.lat = padfTransform[3] + p.x * padfTransform[4] + p.y * padfTransform[5];
|
||||||
return geodetic;
|
return geodetic;
|
||||||
|
|||||||
@@ -147,6 +147,15 @@ namespace globebrowsing {
|
|||||||
// ReadTileData helper functions //
|
// 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;
|
PixelCoordinate geodeticToPixel(const Geodetic2& geo) const;
|
||||||
Geodetic2 pixelToGeodetic(const PixelCoordinate& p) const;
|
Geodetic2 pixelToGeodetic(const PixelCoordinate& p) const;
|
||||||
IODescription getIODescription(const TileIndex& tileIndex) const;
|
IODescription getIODescription(const TileIndex& tileIndex) const;
|
||||||
@@ -189,4 +198,4 @@ namespace globebrowsing {
|
|||||||
} // namespace globebrowsing
|
} // namespace globebrowsing
|
||||||
} // namespace openspace
|
} // namespace openspace
|
||||||
|
|
||||||
#endif // __TILE_DATASET_H__
|
#endif // __TILE_DATASET_H__
|
||||||
|
|||||||
Reference in New Issue
Block a user