From 3fc7b0385d2d1a7c506dbc887680b66dd354c4dc Mon Sep 17 00:00:00 2001 From: James Hogan Date: Thu, 20 Nov 2008 03:05:14 +0000 Subject: [PATCH] Loading of landsat meta data file and coordinates, displays schematic cuboid --- geo/CMakeLists.txt | 2 + geo/tcGeoData.cpp | 28 ++++++ geo/tcGeoData.h | 2 +- geo/tcGlobe.cpp | 7 ++ geo/tcLandsatData.cpp | 70 +++++++++++++ geo/{tcPhotographyData.h => tcLandsatData.h} | 34 +++---- geo/tcLandsatMetaData.cpp | 141 +++++++++++++++++++++++++++ geo/{tcGeoData.h => tcLandsatMetaData.h} | 65 ++++++------ geo/tcPhotographyData.h | 2 + 9 files changed, 295 insertions(+), 56 deletions(-) create mode 100644 geo/tcLandsatData.cpp copy geo/{tcPhotographyData.h => tcLandsatData.h} (74%) create mode 100644 geo/tcLandsatMetaData.cpp copy geo/{tcGeoData.h => tcLandsatMetaData.h} (65%) diff --git a/geo/CMakeLists.txt b/geo/CMakeLists.txt index e05c3f1..6763f70 100644 --- a/geo/CMakeLists.txt +++ b/geo/CMakeLists.txt @@ -17,6 +17,8 @@ set(tecorrec_geo_SRCS tcSensor.cpp tcSpectrum.cpp tcRangeSpectrum.cpp + tcLandsatMetaData.cpp + tcLandsatData.cpp ) set(tecorrec_geo_HEADERS diff --git a/geo/tcGeoData.cpp b/geo/tcGeoData.cpp index faed2e6..b774809 100644 --- a/geo/tcGeoData.cpp +++ b/geo/tcGeoData.cpp @@ -23,6 +23,9 @@ */ #include "tcGeoData.h" +#include + +#include /* * Constructors + destructor @@ -46,4 +49,29 @@ tcGeoData::~tcGeoData() /// Render schematic drawing. void tcGeoData::renderSchematic(double meanRadius, tcObserver* const observer) { + double boxHeight[2] = {1.0, 1.005}; + glColor3f(1.0f, 0.0f, 1.0f); + for (int i = 0; i < 2; ++i) + { + glBegin(GL_LINE_LOOP); + { + glVertex3((meanRadius*boxHeight[i]) * (GLvec3d)m_coordinates[0][0]); + glVertex3((meanRadius*boxHeight[i]) * (GLvec3d)m_coordinates[0][1]); + glVertex3((meanRadius*boxHeight[i]) * (GLvec3d)m_coordinates[1][1]); + glVertex3((meanRadius*boxHeight[i]) * (GLvec3d)m_coordinates[1][0]); + } + glEnd(); + } + glBegin(GL_LINES); + { + for (int i = 0; i < 2; ++i) + { + for (int j = 0; j < 2; ++j) + { + glVertex3((meanRadius*boxHeight[0]) * (GLvec3d)m_coordinates[i][j]); + glVertex3((meanRadius*boxHeight[1]) * (GLvec3d)m_coordinates[i][j]); + } + } + } + glEnd(); } diff --git a/geo/tcGeoData.h b/geo/tcGeoData.h index 70c42a9..ce086a7 100644 --- a/geo/tcGeoData.h +++ b/geo/tcGeoData.h @@ -64,7 +64,7 @@ class tcGeoData /// Render schematic drawing. virtual void renderSchematic(double meanRadius, tcObserver* const observer); - private: + protected: /* * Variables diff --git a/geo/tcGlobe.cpp b/geo/tcGlobe.cpp index 6582b0b..8886ccc 100644 --- a/geo/tcGlobe.cpp +++ b/geo/tcGlobe.cpp @@ -24,6 +24,7 @@ #include "tcGlobe.h" #include "tcPhotographyData.h" +#include "tcLandsatData.h" #include "tcSrtmModel.h" #include #include @@ -42,6 +43,7 @@ tcGlobe::tcGlobe(double meanRadius) , m_elevation(new tcSrtmModel()) , m_data() { + addDataSet(new tcLandsatData("/home/james/cs/pro/data/LE71950281999206EDC01/")); } /// Destructor. @@ -255,6 +257,11 @@ void tcGlobe::render(tcObserver* const observer) } #endif + // Draw data diagramatically + foreach (tcPhotographyData* data, m_data) + { + data->renderSchematic(m_meanRadius, observer); + } // Go through cells const int dlon = 30; diff --git a/geo/tcLandsatData.cpp b/geo/tcLandsatData.cpp new file mode 100644 index 0000000..ddfd403 --- /dev/null +++ b/geo/tcLandsatData.cpp @@ -0,0 +1,70 @@ +/*************************************************************************** + * This file is part of Tecorrec. * + * Copyright 2008 James Hogan * + * * + * Tecorrec is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 2 of the License, or * + * (at your option) any later version. * + * * + * Tecorrec is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with Tecorrec. If not, write to the Free Software Foundation, * + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +/** + * @file tcLandsatData.cpp + * @brief Landsat image data. + */ + +#include "tcLandsatData.h" +#include "tcLandsatMetaData.h" + +#include +#include + +/* + * Constructors + destructor + */ + +/// Load landsat data given the path. +tcLandsatData::tcLandsatData(const QString& path) +: tcPhotographyData() +, m_meta(0) +{ + /// @todo Find name of txt file automatically + const QString metaFilePath = path + "L71195028_02819990725_MTL.txt"; + + QFile metaFile(metaFilePath); + if (metaFile.open(QIODevice::ReadOnly)) + { + m_meta = new tcLandsatMetaData(metaFile); + + tcLandsatMetaData& productMetadata = (*m_meta)("L1_METADATA_FILE")("PRODUCT_METADATA"); + + // Load coordinates. + m_coordinates[0][1] = tcGeo(productMetadata["PRODUCT_UL_CORNER_LON"].toDouble() * M_PI/180.0, + productMetadata["PRODUCT_UL_CORNER_LAT"].toDouble() * M_PI/180.0); + m_coordinates[1][1] = tcGeo(productMetadata["PRODUCT_UR_CORNER_LON"].toDouble() * M_PI/180.0, + productMetadata["PRODUCT_UR_CORNER_LAT"].toDouble() * M_PI/180.0); + m_coordinates[0][0] = tcGeo(productMetadata["PRODUCT_LL_CORNER_LON"].toDouble() * M_PI/180.0, + productMetadata["PRODUCT_LL_CORNER_LAT"].toDouble() * M_PI/180.0); + m_coordinates[1][0] = tcGeo(productMetadata["PRODUCT_LR_CORNER_LON"].toDouble() * M_PI/180.0, + productMetadata["PRODUCT_LR_CORNER_LAT"].toDouble() * M_PI/180.0); + + QString bands = productMetadata["BAND_COMBINATION"].toString(); + + QString band[8]; + band[0] = productMetadata["BAND1_FILE_NAME"].toString(); + } +} + +/// Destructor. +tcLandsatData::~tcLandsatData() +{ +} diff --git a/geo/tcPhotographyData.h b/geo/tcLandsatData.h similarity index 74% copy from geo/tcPhotographyData.h copy to geo/tcLandsatData.h index b535dfe..0518457 100644 --- a/geo/tcPhotographyData.h +++ b/geo/tcLandsatData.h @@ -17,21 +17,21 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ -#ifndef _tcPhotographyData_h_ -#define _tcPhotographyData_h_ +#ifndef _tcLandsatData_h_ +#define _tcLandsatData_h_ /** - * @file tcPhotographyData.h - * @brief Terrain photography data. + * @file tcLandsatData.h + * @brief Landsat image data. */ -#include "tcGeoData.h" +#include "tcPhotographyData.h" -class tcSensor; -class tcGeoVector; +class tcLandsatMetaData; +class QString; -/// Terrain photography data. -class tcPhotographyData : public tcGeoData +/// Landsat image data. +class tcLandsatData : public tcPhotographyData { public: @@ -39,11 +39,11 @@ class tcPhotographyData : public tcGeoData * Constructors + destructor */ - /// Default constructor. - tcPhotographyData(); + /// Load landsat data given the path. + tcLandsatData(const QString& path); /// Destructor. - virtual ~tcPhotographyData(); + virtual ~tcLandsatData(); private: @@ -51,14 +51,8 @@ class tcPhotographyData : public tcGeoData * Variables */ - /// Number of channels. - int m_numChannels; - - /// Sensors which collected the data. - tcSensor* m_sensor; - - /// Direction of the sun in local space. - tcGeoVector* m_sunDirection; + /// Metadata from txt file. + tcLandsatMetaData* m_meta; }; #endif diff --git a/geo/tcLandsatMetaData.cpp b/geo/tcLandsatMetaData.cpp new file mode 100644 index 0000000..24dbfb8 --- /dev/null +++ b/geo/tcLandsatMetaData.cpp @@ -0,0 +1,141 @@ +/*************************************************************************** + * This file is part of Tecorrec. * + * Copyright 2008 James Hogan * + * * + * Tecorrec is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 2 of the License, or * + * (at your option) any later version. * + * * + * Tecorrec is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with Tecorrec. If not, write to the Free Software Foundation, * + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +/** + * @file tcLandsatMetaData.cpp + * @brief Landsat metadata file. + */ + +#include "tcLandsatMetaData.h" + +#include +#include + +#include + +/* + * Constructors + destructor + */ + +/// Load metadata from a file. +tcLandsatMetaData::tcLandsatMetaData(QFile& file) +{ + static QRegExp regexp("^\\s*(\\w+)\\s*=\\s*(\"(.*)\"|(\\S(.*\\S)?))\\s*$"); + static QRegExp end("^\\s*END\\s*$"); + static QRegExp blank("^\\s*$"); + while (!file.atEnd()) + { + QByteArray line = file.readLine(); + if (regexp.exactMatch(line)) + { + QString name = regexp.cap(1); + if ("GROUP" == name) + { + name = regexp.cap(2); + if (m_groups.contains(name)) + { + delete m_groups[name]; + qDebug() << "Landsat meta data has conflicting groups:" << line; + } + tcLandsatMetaData* newMeta = new tcLandsatMetaData(file); + m_groups[name] = newMeta; + } + else if ("END_GROUP" == name) + { + return; + } + else + { + QVariant value; + QString valueStr = regexp.cap(3); + if (valueStr.isEmpty()) + { + valueStr = regexp.cap(4); + bool ok; + double d = valueStr.toDouble(&ok); + if (ok) + { + value = d; + } + else + { + value = valueStr; + } + } + else + { + value = valueStr; + } + m_values[name] = value; + } + } + else if (end.exactMatch(line)) + { + return; + } + else if (blank.exactMatch(line)) + { + } + else + { + qDebug() << "Parsing error reading landsat meta data:" << line; + } + } +} + +/// Destructor. +tcLandsatMetaData::~tcLandsatMetaData() +{ +} + +/* + * Accessors + */ + +/// Get the list of group names. +QStringList tcLandsatMetaData::groupNames() const +{ + return m_groups.keys(); +} + +/// Get the list of value names. +QStringList tcLandsatMetaData::valueNames() const +{ + return m_values.keys(); +} + +/// Access a group. +tcLandsatMetaData& tcLandsatMetaData::operator () (const QString& name) const +{ + Q_ASSERT(m_groups.contains(name)); + return *m_groups[name]; +} + +/// Access a value. +QVariant tcLandsatMetaData::operator [] (const QString& name) const +{ + if (m_values.contains(name)) + { + return m_values[name]; + } + else + { + return QVariant(); + } +} diff --git a/geo/tcGeoData.h b/geo/tcLandsatMetaData.h similarity index 65% copy from geo/tcGeoData.h copy to geo/tcLandsatMetaData.h index 70c42a9..09f24f2 100644 --- a/geo/tcGeoData.h +++ b/geo/tcLandsatMetaData.h @@ -17,52 +17,51 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ -#ifndef _tcGeoData_h_ -#define _tcGeoData_h_ +#ifndef _tcLandsatMetaData_h_ +#define _tcLandsatMetaData_h_ /** - * @file tcGeoData.h - * @brief Data for a section of the globe. + * @file tcLandsatMetaData.h + * @brief Landsat metadata file. */ -#include "tcGeo.h" +#include +#include +#include +#include -#include +class QFile; -class tcObserver; - -/// Data for a section of the globe. -class tcGeoData +/// Landsat metadata file. +class tcLandsatMetaData { public: /* - * Types - */ - - /// Types of data. - enum DataType - { - ElevationData = 0, - PhotographicData = 1 - }; - - /* * Constructors + destructor */ - /// Primary constructor. - tcGeoData(DataType type); + /// Load metadata from a file. + tcLandsatMetaData(QFile& file); /// Destructor. - virtual ~tcGeoData(); + virtual ~tcLandsatMetaData(); /* - * Rendering + * Accessors */ - /// Render schematic drawing. - virtual void renderSchematic(double meanRadius, tcObserver* const observer); + /// Get the list of group names. + QStringList groupNames() const; + + /// Get the list of value names. + QStringList valueNames() const; + + /// Access a group. + tcLandsatMetaData& operator () (const QString& name) const; + + /// Access a value. + QVariant operator [] (const QString& name) const; private: @@ -70,15 +69,11 @@ class tcGeoData * Variables */ - /// Type of data. - DataType m_type; - - /// Time of collection. - QDateTime m_captureTime; - - /// Coordinates of corners of data. - tcGeo m_coordinates[2][2]; + /// Hash of groups. + QHash m_groups; + /// Hash of values. + QHash m_values; }; #endif diff --git a/geo/tcPhotographyData.h b/geo/tcPhotographyData.h index b535dfe..63bfe75 100644 --- a/geo/tcPhotographyData.h +++ b/geo/tcPhotographyData.h @@ -27,6 +27,8 @@ #include "tcGeoData.h" +#include + class tcSensor; class tcGeoVector; -- 2.11.4.GIT