Commit bef386fd authored by Julien Osman's avatar Julien Osman
Browse files

Merge branch 'integrate-mr-870' into 'release-8.0'

Integrate Merge Request 870 in release 8

See merge request !906
parents 26085b00 978d722c
Pipeline #10348 passed with stages
in 155 minutes and 8 seconds
......@@ -39,7 +39,7 @@ def GenerateRstForPythonAPi(rst_dir):
print("Generating rst for Python API")
# Instenciate an ImageMetadata object to retrieve the keys
# Instentiate an ImageMetadata object to retrieve the keys
imd = otbApplication.ImageMetadata()
# Render the page
......
......@@ -150,7 +150,7 @@ SuperBuild: Build OTB and all dependencies
OTB’s compilation is customized by specifying configuration variables.
The most important configuration variables are shown in the
table above. The simplest way to provide
table above. The simplest way to provide
configuration variables is via the command line ``-D`` option:
::
......@@ -285,7 +285,7 @@ FindXXX.cmake scripts, or with the ``XXX_INCLUDEDIR`` and
``XXX_LIBRARY`` variables.
Additionally, decide which module you wish to enable, together with tests and
examples. Refer to table above for the list of CMake variables.
examples. Refer to table above for the list of CMake variables.
OTB is modular. It is possible to only build some modules
instead of the whole set. To deactivate a module (and the ones that
......@@ -295,7 +295,7 @@ depend on it) switch off the CMake variable
Some of the OTB capabilities are considered as optional, and you can
deactivate the related modules thanks to a set of CMake variables
starting with ``OTB_USE_XXX``. The table below shows which modules
starting with ``OTB_USE_XXX``. The table below shows which modules
are associated to these variables. It is very important to notice that
these variable override the variable ``OTB_BUILD_DEFAULT_MODULES``.
......@@ -366,7 +366,8 @@ hours to run them all, depending on compilation options
(release mode does make a difference) and hardware.
To run the tests, first make sure to set the option
``BUILD_TESTING`` to ``ON`` before building the library.
``BUILD_TESTING`` to ``ON`` before building the library. If you want to run the tests for the
python API, you will also need to install the python module `pytest`.
For some of the tests, you also need the test data and the baselines (~1GB). These files are stored
using `git-lfs` in the `Data` folder at the root of otb sources. To download them, you have to make
......
......@@ -58,6 +58,32 @@ inline std::ostream& Join(std::ostream& os, TRange const& range, std::string con
}
return os;
}
/**
* Joins elements from a map (second) into a stream.
* \tparam Tmap Map type
* \param os destination stream
* \param[in] range Range to print
* \param[in] separator Separator string to use between elements.
*
* \return the stream
* \throw None At least, this function is exception neutral.
*/
template <typename Tmap>
inline std::ostream& JoinMap(std::ostream& os, Tmap const& range, std::string const& separator)
{
if (!boost::empty(range))
{
typename boost::range_iterator<Tmap const>::type first = boost::begin(range);
typename boost::range_iterator<Tmap const>::type const last = boost::end(range);
os << first->second;
for (++first; first != last; ++first)
{
os << separator << first->second;
}
}
return os;
}
} // end namespace otb
#ifndef OTB_MANUAL_INSTANTIATION
......
......@@ -20,6 +20,7 @@
#include "otbImageMetadata.h"
#include "otbSpatialReference.h"
#include "otbJoinContainer.h"
namespace otb
{
......@@ -201,11 +202,8 @@ bool ImageMetadataBase::Has(const MDStr& key) const
std::string ImageMetadataBase::GetKeyListStr() const
{
std::ostringstream oss;
for (const auto& kv : MetaData::MDStrNames.left)
oss << kv.second << " ";
auto returnString = oss.str();
returnString.pop_back();
return returnString;
JoinMap(oss, MetaData::MDStrNames.left, " ");
return oss.str();
}
// -------------------- LUT1D utility function ----------------------------
......
......@@ -50,4 +50,4 @@ if ( OTB_WRAP_PYTHON )
message( WARNING
"OTB wrappers will be done without support for NumPy (not found).")
endif()
endif()
\ No newline at end of file
endif()
......@@ -91,7 +91,6 @@ class ImageMetadataBase
{
public:
std::string GetProjectedGeometry() const;
std::string GetProjectionWKT() const;
std::string GetProjectionProj() const;
std::string GetKeyListNum() const;
......@@ -113,7 +112,7 @@ public:
std::string __repr__() {
std::ostringstream oss;
oss << *$self;
return oss.str().c_str();
return oss.str();
}
}
......@@ -174,6 +173,14 @@ public:
return it != otb::MetaData::MDGeomNames.right.end();
}
bool is_extra(const std::string& key) {
return $self->Has(key);
}
std::string get_extra(const std::string& key) {
return $self->operator[](key);
}
bool has(const std::string& key) const {
auto it_num = otb::MetaData::MDNumNames.right.find(key);
if (it_num != otb::MetaData::MDNumNames.right.end())
......@@ -199,7 +206,7 @@ public:
if (it_geom != otb::MetaData::MDGeomNames.right.end())
return $self->Has(it_geom->second);
return false;
return $self->Has(key);
}
void __setitem__(const std::string& key, const double val) {
......@@ -214,7 +221,13 @@ public:
if (it != otb::MetaData::MDStrNames.right.end())
$self->Add(it->second, val);
else
$self->Add(key, val);
{
auto it2 = otb::MetaData::MDGeomNames.right.find(key);
if (it2 != otb::MetaData::MDGeomNames.right.end())
$self->Add(it2->second, val);
else
$self->Add(key, val);
}
}
void __setitem__(const std::string& key, const otb::MetaData::LUT1D& val) {
auto it = otb::MetaData::MDL1DNames.right.find(key);
......@@ -263,6 +276,8 @@ public:
return self.get_time(key)
elif self.is_geom(key):
return None # TODO: the geom part of the Imagemetadata is not wrapped yet
elif self.is_extra(key):
return self.get_extra(key)
else:
return None
}
......
......@@ -180,3 +180,8 @@ add_test( NAME pyTvNoUpdateParameter
${OTB_DATA_ROOT}/Input/training/training.shp
)
add_test( NAME pyTuImageMetadata
COMMAND ${TEST_DRIVER} Execute
${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/PythonTestDriver.py
PythonImageMetadataTest
)
# -*- coding: utf-8 -*-
#
# Copyright (C) 2005-2020 Centre National d'Etudes Spatiales (CNES)
#
# This file is part of Orfeo Toolbox
#
# https://www.orfeo-toolbox.org/
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
def test(otb, argv):
imd = otb.ImageMetadataBase()
# Setters
imd["OrbitNumber"] = 2.0
imd["SensorID"] = "PHR"
imd["ProjectionWKT"] = "UTM projRef"
imd["Comment"] = "Test extra keys"
# is_xxx
assert imd.is_num("OrbitNumber")
assert not imd.is_num("SensorID")
assert imd.is_str("SensorID")
assert not imd.is_str("OrbitNumber")
assert imd.is_l1d("SpectralSensitivity")
assert not imd.is_l1d("SensorID")
assert imd.is_time("ProductionDate")
assert not imd.is_time("SensorID")
assert imd.is_geom("ProjectionWKT")
assert not imd.is_geom("SensorID")
assert imd.is_extra("Comment")
assert not imd.is_extra("SensorID")
# get_xxx
assert imd.get_num("OrbitNumber") == 2.0
assert imd.get_str("SensorID") == "PHR"
assert imd.get_extra("Comment") == "Test extra keys"
# Getters
assert imd["OrbitNumber"] == 2.0
assert imd["SensorID"] == "PHR"
# assert imd["ProjectionWKT"] == "UTM projRef" # This getter is not implemented yet
assert imd["Comment"] == "Test extra keys"
# has
assert imd.has("OrbitNumber")
assert imd.has("SensorID")
assert imd.has("Comment")
assert not imd.has("Comment2")
assert not imd.has("RadiometricLevel")
# GetProjectedGeometry
assert imd.GetProjectedGeometry() == "UTM projRef"
# GetProjectionProj
imd["ProjectionProj"] = "Proj String"
assert imd.GetProjectionProj() == "Proj String"
......@@ -33,8 +33,8 @@ if(MSVC)
# Use pre-built swig executable (no linking is required, no install done)
ExternalProject_Add(SWIG
PREFIX SWIG
URL "https://downloads.sourceforge.net/project/swig/swigwin/swigwin-3.0.12/swigwin-3.0.12.zip"
URL_MD5 a49524dad2c91ae1920974e7062bfc93
URL "https://downloads.sourceforge.net/project/swig/swigwin/swigwin-4.0.2/swigwin-4.0.2.zip"
URL_MD5 009926b512aee9318546bdd4c7eab6f9
INSTALL_DIR ${SB_INSTALL_PREFIX}
DOWNLOAD_DIR ${DOWNLOAD_LOCATION}
CONFIGURE_COMMAND ""
......@@ -52,8 +52,8 @@ else()
ExternalProject_Add(SWIG
PREFIX SWIG
URL "https://downloads.sourceforge.net/project/swig/swig/swig-3.0.12/swig-3.0.12.tar.gz"
URL_MD5 82133dfa7bba75ff9ad98a7046be687c
URL "https://downloads.sourceforge.net/project/swig/swig/swig-4.0.2/swig-4.0.2.tar.gz"
URL_MD5 7c3e46cb5af2b469722cafa0d91e127b
BINARY_DIR ${SWIG_SB_BUILD_DIR}
INSTALL_DIR ${SB_INSTALL_PREFIX}
DOWNLOAD_DIR ${DOWNLOAD_LOCATION}
......
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