diff --git a/Code/Projections/otbCoordinateToName.cxx b/Code/Projections/otbCoordinateToName.cxx index 669f0182779630c5cdb1177e2a65fb9471b988e8..48fa198ec4c23ec5fdfb18a4009632038bcf6352 100644 --- a/Code/Projections/otbCoordinateToName.cxx +++ b/Code/Projections/otbCoordinateToName.cxx @@ -37,6 +37,8 @@ CoordinateToName::CoordinateToName(): m_Threader = itk::MultiThreader::New(); + m_UpdateDistance = 0.01;//about 1km at equator + } /** diff --git a/Code/Projections/otbCoordinateToName.h b/Code/Projections/otbCoordinateToName.h index d55718cfbf37ef656d36c535a7eddb0213bd7420..c1835def41e2305c25acb441371d8f43d0ee810f 100644 --- a/Code/Projections/otbCoordinateToName.h +++ b/Code/Projections/otbCoordinateToName.h @@ -20,6 +20,7 @@ #include "itkObject.h" #include "itkObjectFactory.h" +#include "itkPoint.h" #include "itkMultiThreader.h" namespace otb @@ -50,12 +51,36 @@ public: /** Method for creation through the object factory. */ itkNewMacro(Self); + typedef itk::Point<double,2> PointType; + itkGetMacro( Lon, double ); itkGetMacro( Lat, double ); itkSetMacro( Lon, double ); itkSetMacro( Lat, double ); + /** + * Set the lon/lat only if they are far enough from the current point to + * avoid triggering too many updates + */ + bool SetLonLat(PointType point) + { + if ((vcl_abs(point[0] - m_Lon) > m_UpdateDistance) || (vcl_abs(point[1] - m_Lat) > m_UpdateDistance)) + { + std::cout << "Update lon/lat " << m_Lon << ", " << m_Lat << " -> " << point << std::endl; + m_Lon = point[0]; + m_Lat = point[1]; + //TODO Check whether it is better to have something imprecise or nothing at all + m_IsValid = false; + return true; + } + else + { + std::cout << "Keeping lon/lat" << std::endl; + return false; + } + } + std::string GetPlaceName() const { if (m_IsValid) @@ -105,6 +130,9 @@ private: double m_Lat; bool m_Multithread; bool m_IsValid; + //Minimum distance to trigger an update of the coordinates + //specified in degrees + double m_UpdateDistance; std::string m_PlaceName; std::string m_CountryName; diff --git a/Code/Visualization/otbImageLayer.h b/Code/Visualization/otbImageLayer.h index 5c87ff1f5b6dbf68a0617ffcd0091e32744ac254..88cfff086ab980748aafeab32a323eb25cd640db 100644 --- a/Code/Visualization/otbImageLayer.h +++ b/Code/Visualization/otbImageLayer.h @@ -29,6 +29,8 @@ #include "otbRenderingImageFilter.h" #include "otbGenericRSTransform.h" +#include "otbCoordinateToName.h" + namespace otb { /** \class ImageLayer @@ -246,6 +248,7 @@ private: /** Coordinate transform */ TransformType::Pointer m_Transform; + CoordinateToName::Pointer m_CoordinateToName; /** General info about the image*/ std::string m_PlaceName;//FIXME the call should be done by a more general method outside of the layer diff --git a/Code/Visualization/otbImageLayer.txx b/Code/Visualization/otbImageLayer.txx index a75e08af3a8916487eac45eb3fe3b355bc75ed0d..7329ad3a832f58dcb5a55f29b0e3751d8fdc53da 100644 --- a/Code/Visualization/otbImageLayer.txx +++ b/Code/Visualization/otbImageLayer.txx @@ -59,6 +59,7 @@ ImageLayer<TImage,TOutputImage> m_ScaledExtractRenderingFilter->SetInput(m_ScaledExtractFilter->GetOutput()); m_Transform = TransformType::New(); + m_CoordinateToName = CoordinateToName::New(); m_PlaceName = ""; m_CountryName = ""; @@ -273,18 +274,16 @@ ImageLayer<TImage,TOutputImage> if (m_Transform->GetTransformAccuracy() == Projection::PRECISE) oss<< "(precise location)" << std::endl; if (m_Transform->GetTransformAccuracy() == Projection::ESTIMATE) oss<< "(estimated location)" << std::endl; -// if ((m_PlaceName == "") && (m_CountryName == "")) -// { -// CoordinateToName::Pointer conv = CoordinateToName::New(); -// conv->SetLon(point[0]); -// conv->SetLat(point[1]); -// conv->Evaluate(); -// -// m_PlaceName = conv->GetPlaceName(); -// m_CountryName = conv->GetCountryName(); -// } -// if (m_PlaceName != "") oss << "Near " << m_PlaceName; -// if (m_CountryName != "") oss << " in " << m_CountryName; + if (m_CoordinateToName->SetLonLat(point)) + { + m_CoordinateToName->Evaluate(); + } + + m_PlaceName = m_CoordinateToName->GetPlaceName(); + m_CountryName = m_CoordinateToName->GetCountryName(); + + if (m_PlaceName != "") oss << "Near " << m_PlaceName; + if (m_CountryName != "") oss << " in " << m_CountryName; } else {