Ejemplo n.º 1
0
void Kml::generateBoundingBox(const Layer* pGeoLayer)
{
   VERIFYNRV(pGeoLayer != NULL);

   // Translate the view's corner coordinates into layer coordinates
   View* pView = pGeoLayer->getView();
   VERIFYNRV(pView != NULL);

   LocationType worldLowerLeft;
   LocationType worldUpperLeft;
   LocationType worldUpperRight;
   LocationType worldLowerRight;
   pView->getVisibleCorners(worldLowerLeft, worldUpperLeft, worldUpperRight, worldLowerRight);

   LocationType dataLowerLeft;
   LocationType dataUpperLeft;
   LocationType dataUpperRight;
   LocationType dataLowerRight;
   pGeoLayer->translateWorldToData(worldLowerLeft.mX, worldLowerLeft.mY, dataLowerLeft.mX, dataLowerLeft.mY);
   pGeoLayer->translateWorldToData(worldUpperLeft.mX, worldUpperLeft.mY, dataUpperLeft.mX, dataUpperLeft.mY);
   pGeoLayer->translateWorldToData(worldUpperRight.mX, worldUpperRight.mY, dataUpperRight.mX, dataUpperRight.mY);
   pGeoLayer->translateWorldToData(worldLowerRight.mX, worldLowerRight.mY, dataLowerRight.mX, dataLowerRight.mY);

   // Translate the layer coordinates into geocoordinates
   vector<LocationType> corners;
   corners.push_back(dataLowerLeft);
   corners.push_back(dataUpperLeft);
   corners.push_back(dataUpperRight);
   corners.push_back(dataLowerRight);

   RasterElement* pGeoElement = dynamic_cast<RasterElement*>(pGeoLayer->getDataElement());
   VERIFYNRV(pGeoElement != NULL);

   vector<LocationType> geoCorners = pGeoElement->convertPixelsToGeocoords(corners);

   // Determine the geo bounding box
   double north = -90.0;
   double south = 90.0;
   double east = -180.0;
   double west = 180.0;

   for (vector<LocationType>::iterator iter = geoCorners.begin(); iter != geoCorners.end(); ++iter)
   {
      LocationType geocoord = *iter;
      north = std::max(geocoord.mX, north);
      south = std::min(geocoord.mX, south);
      east = std::max(geocoord.mY, east);
      west = std::min(geocoord.mY, west);
   }

   // Write the info to the file calling StringUtilities first to get higher precision
   // instead of calling XmlWriter::addText() and passing in the double value
   string northText = StringUtilities::toXmlString(north);
   string southText = StringUtilities::toXmlString(south);
   string eastText = StringUtilities::toXmlString(east);
   string westText = StringUtilities::toXmlString(west);

   mXml.pushAddPoint(mXml.addElement("LatLonAltBox"));
   mXml.addText(northText, mXml.addElement("north"));
   mXml.addText(southText, mXml.addElement("south"));
   mXml.addText(eastText, mXml.addElement("east"));
   mXml.addText(westText, mXml.addElement("west"));
   mXml.popAddPoint();
}