Commit edb9d609 authored by Julien Michel's avatar Julien Michel

ENH: Adding a GetGlobalExtent() method to DataSource

parent 86710785
......@@ -402,6 +402,48 @@ int otb::ogr::DataSource::Size(bool doForceComputation) const
/*=================================[ Misc ]==================================*/
/*===========================================================================*/
void otb::ogr::DataSource::GetGlobalExtent(double & ulx,
double & uly,
double & lrx,
double & lry,
bool force) const
{
OGREnvelope sExtent;
const_iterator lit = this->begin();
const OGRErr res = lit->ogr().GetExtent(&sExtent,force);
if(res!= OGRERR_NONE)
{
itkGenericExceptionMacro(<< "Cannot retrieve extent of layer <"
<<lit->GetName()<<">: " << CPLGetLastErrorMsg());
}
++lit;
for(; lit!=this->end();++lit)
{
OGREnvelope cExtent;
const OGRErr cres = lit->ogr().GetExtent(&cExtent,force);
if(cres!= OGRERR_NONE)
{
itkGenericExceptionMacro(<< "Cannot retrieve extent of layer <"
<<lit->GetName()<<">: " << CPLGetLastErrorMsg());
}
// Merge with previous layer
sExtent.Merge(cExtent);
}
ulx = sExtent.MinX;
uly = sExtent.MinY;
lrx = sExtent.MaxX;
lry = sExtent.MaxY;
}
/*virtual*/
void otb::ogr::DataSource::PrintSelf(
std::ostream& os, itk::Indent indent) const
......
......@@ -212,6 +212,23 @@ public:
*/
int Size(bool doForceComputation) const;
/** Allow to retrieve the union of the extents of all layers
* \param[out] ulx reference to upper-left x coordinate of the
* extent
* \param[out] uly reference to upper-left y coordinate of the
* extent
* \param[out] lrx reference to lower-right x coordinate of the
* extent
* \param[out] uly reference to lower-right y coordinate of the
* extent
* \param[in] force Force computation of layers extents if not
* available. May force the driver to walk all geometries to
* compute the extent.
* \throw itk::ExceptionObject if the layers extents can not be retrieved.
*/
void GetGlobalExtent(double & ulx, double & uly, double & lrx, double & lry, bool force = false) const;
/** Grafts data and information from one data source to another.
* \deprecated \c OGRLayer has an embedded input iterator. As a consequence,
* the layer cannot support multiple access to its elements.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment