Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bounding box of rotated projection #1434

Merged
merged 2 commits into from
May 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Tests/src/MercatorProjection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,3 +266,19 @@ TEST_CASE("GetDimensions()")

REQUIRE(projection.GetDimensions().GetDisplayText()==expectedBox.GetDisplayText());
}

TEST_CASE("GetDimensions() with rotation")
{
osmscout::MercatorProjection projection;
osmscout::GeoBox expectedBox(osmscout::GeoCoord(51.49061,7.42522),
osmscout::GeoCoord(51.53420,7.50528));

projection.Set(defaultCenter,
0.524, // 30°
osmscout::Magnification(osmscout::Magnification::magClose),
defaultDpi,
defaultWidth,
defaultHeight);

REQUIRE(projection.GetDimensions().GetDisplayText()==expectedBox.GetDisplayText());
}
22 changes: 14 additions & 8 deletions libosmscout/src/osmscout/projection/MercatorProjection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,21 +124,27 @@ namespace osmscout {

PixelToGeo(0.0,0.0,topLeft);

GeoCoord topRight;

PixelToGeo((double)width,0.0,topRight);

GeoCoord bottomLeft;

PixelToGeo(0.0,(double)height,bottomLeft);

GeoCoord bottomRight;

PixelToGeo((double)width,(double)height,bottomRight);

// evaluate bounding box, crop bounding box to valid Mercator area

boundingBox=GeoBox(topLeft,bottomRight);

if (angle!=0.0) {
// be aware that top-left, bottom-right bounding box may not include top-right and bottom-left coordinates when projection is rotated
GeoCoord topRight;

PixelToGeo((double)width,0.0,topRight);

GeoCoord bottomLeft;

PixelToGeo(0.0,(double)height,bottomLeft);

boundingBox.Include(GeoBox(topRight, bottomLeft));
}

boundingBox.CropTo(GeoBox(GeoCoord(MinLat,MinLon),
GeoCoord(MaxLat,MaxLon)));

Expand Down
Loading