Skip to content

Commit

Permalink
extended the old ascii2png kml bounds fix to vector kml output
Browse files Browse the repository at this point in the history
the original fix was to deal with png layers not quite extending to the right spots/bounds in the domain. The fix was necessary this time because negative input min and max bounds would result in vectors not being drawn in google earth. The locations of the vectors and values would pop up, but no arrows would be drawn.

The problem this time turned out to be because the bounds in the overall LatLonAltBox of the kmz would get reversed. The fix worked because it keeps track of all four points of the bounding box, rather than just two. I suspect that the fix will also be more robust for when we allow more types of projections in WindNinja, as the bounding box can take on varying orientations during reprojections.

The original fix is described in e765438 and 395c93e. This fix should come in real handy for issue #544
  • Loading branch information
latwood committed Feb 11, 2025
1 parent 8240174 commit 357ab5e
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/ninja/KmlVector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -500,8 +500,28 @@ bool KmlVector::writeRegion(VSILFILE *fileOut)

if(coordTransform != 0)
{
coordTransform->Transform(1, &westExtent, &southExtent);
coordTransform->Transform(1, &eastExtent, &northExtent);
double xll = westExtent;
double yll = southExtent;
double xul = westExtent;
double yul = northExtent;
double xur = eastExtent;
double yur = northExtent;
double xlr = eastExtent;
double ylr = southExtent;
coordTransform->Transform(1, &xll, &yll);
coordTransform->Transform(1, &xul, &yul);
coordTransform->Transform(1, &xur, &yur);
coordTransform->Transform(1, &xlr, &ylr);
northExtent = std::max(yul,yur);
southExtent = std::min(yll,ylr);
// calculating for east and west gets more complicated for the rare case that it crosses between -180 and 180 degrees
eastExtent = std::max(xlr,xur);
westExtent = std::min(xll,xul);
// check if crosses between -180 and 180 degrees, swap min for max or max for min if swapped dirs around circle
if ( std::max(xlr,xur) - std::min(xlr,xur) > 180 )
eastExtent = std::min(xlr,xur);
if ( std::max(xll,xul) - std::min(xll,xul) > 180 )
westExtent = std::max(xll,xul);
}

VSIFPrintfL(fileOut, "\n<Region>");
Expand Down

0 comments on commit 357ab5e

Please sign in to comment.