Commit acc2d15a authored by Ian Humphrey's avatar Ian Humphrey
Browse files

Added GisBlob, GisGeometry, and GisTopology classes to ISIS for isisminer. Fixes #2398.

git-svn-id: http://subversion.wr.usgs.gov/repos/prog/isis3/trunk@6580 41f8697f-d340-4b68-9986-7bafba869bb8
parent 33f3436e
Loading
Loading
Loading
Loading
+107 −0
Original line number Diff line number Diff line
/**                                                                       
 * @file                                                                  
 * $Revision: 6084 $ 
 * $Date: 2015-03-04 18:17:45 -0700 (Wed, 04 Mar 2015) $ 
 * $Id: GisBlob.h 6084 2015-03-05 01:17:45Z kbecker@GS.DOI.NET $
 *                                                                        
 *   Unless noted otherwise, the portions of Isis written by the USGS are public
 *   domain. See individual third-party library and package descriptions for 
 *   intellectual property information,user agreements, and related information.
 *                                                                        
 *   Although Isis has been used by the USGS, no warranty, expressed or implied,
 *   is made by the USGS as to the accuracy and functioning of such software 
 *   and related material nor shall the fact of distribution constitute any such 
 *   warranty, and no responsibility is assumed by the USGS in connection 
 *   therewith.                                                           
 *                                                                        
 *   For additional information, launch                                   
 *   $ISISROOT/doc//documents/Disclaimers/Disclaimers.html in a browser or see 
 *   the Privacy & Disclaimers page on the Isis website,              
 *   http://isis.astrogeology.usgs.gov, and the USGS privacy and disclaimers on
 *   http://www.usgs.gov/privacy.html.                                    
 */                                                  
#include "GisBlob.h"

// Qt library
#include <QDebug>
#include <QString>

// other ISIS
#include "Blob.h"
#include "Cube.h"

namespace Isis {

  /** 
   * Constructs an Isis polygon-type Blob named "Footprint." 
   */
  GisBlob::GisBlob() : Blob("Footprint", "Polygon"), m_wkt() {
  }


  /** 
   * Constructs an Isis polygon-type Blob named "Footprint" and sets the
   * well-known text string that defines the polygon by reading the 
   * given cube.
   * @param cube 
   */
  GisBlob::GisBlob(Cube &cube) : Blob("Footprint", "Polygon"), m_wkt() {
    cube.read(*this);
    m_wkt = scrub(p_buffer, p_nbytes);
  }   


  /** 
   * Destroys the GisBlob object. 
   */
  GisBlob::~GisBlob() { 
  }


  /** 
   * Accesses the well-known text string that defines the polygon. 
   *  
   * @return QString A well-known text string containing the polygon definition.
   */
  QString GisBlob::polygon() const { 
    return (m_wkt); 
  }


  /** 
   * Sets the polygon using the given well-known text string. 
   *  
   * @param wkt A string containing the well-known text that defines a polygon.
   */
  void GisBlob::setPolygon(const QString &wkt) {
    delete [] p_buffer;
    p_nbytes = wkt.size();
    p_buffer = new char[p_nbytes+1];
    for (int i = 0 ; i < p_nbytes ; i++) {
      p_buffer[i] = wkt[i].toAscii();
    }
    p_buffer[p_nbytes] = 0;
    m_wkt = scrub(p_buffer, p_nbytes);
    return;
  }


  /** 
   * This method will scrub all zeros that prefix the given buffer and convert 
   * it to a string using the number of allocated bytes given.
   *  
   * @param rawbuf A pointer containing the raw buffer to be converted.
   * @param rbytes The number of bytes to be read in. 
   *  
   * @return QString A string converted from the given raw buffer.
   */
  QString GisBlob::scrub(const char *rawbuf, int rbytes) const {
    int i;
    for (i = 0 ; i < rbytes ; i++) {
      if (rawbuf[i] != 0) break;
    }
    int nbytes =  rbytes - i;
    return (QString::fromAscii(&rawbuf[i], nbytes));
  }

} // Namespace Isis
+69 −0
Original line number Diff line number Diff line
#ifndef GisBlob_h
#define GisBlob_h
/**                                                                       
 * @file                                                                  
 * $Revision: 6150 $ 
 * $Date: 2015-04-19 23:40:55 -0700 (Sun, 19 Apr 2015) $ 
 * $Id: GisBlob.h 6150 2015-04-20 06:40:55Z jwbacker@GS.DOI.NET $
 *                                                                        
 *   Unless noted otherwise, the portions of Isis written by the USGS are public
 *   domain. See individual third-party library and package descriptions for 
 *   intellectual property information,user agreements, and related information.
 *                                                                        
 *   Although Isis has been used by the USGS, no warranty, expressed or implied,
 *   is made by the USGS as to the accuracy and functioning of such software 
 *   and related material nor shall the fact of distribution constitute any such 
 *   warranty, and no responsibility is assumed by the USGS in connection 
 *   therewith.                                                           
 *                                                                        
 *   For additional information, launch                                   
 *   $ISISROOT/doc//documents/Disclaimers/Disclaimers.html in a browser or see 
 *   the Privacy &amp; Disclaimers page on the Isis website,              
 *   http://isis.astrogeology.usgs.gov, and the USGS privacy and disclaimers on
 *   http://www.usgs.gov/privacy.html.                                    
 */            
                                      
// parent class
#include "Blob.h"

// Qt library
#include <QString>

namespace Isis {
  class Cube;

  /** 
   * This class creates a polygon-type Isis Blob named "Footprint". It inherits 
   * from the Isis Blob class. This Blob may be read from a given cube or the 
   * polygon maybe set using a wkt polygon string. 
   *  
   * @author 2012-07-15 Kris Becker 
   * @internal 
   *   @history 2012-07-15 Kris Becker - Original version.
   *   @history 2015-03-18 Jeannie Backer - Brought class files closer to ISIS coding standards.
   *   @history 2015-03-31 Jeannie Backer - Updated documentation.
   *   @history 2016-03-02 Ian Humphrey - Updated for coding standards compliance in preparation
   *                           for adding this class to ISIS. Fixes #2398.
   */
  class GisBlob : public Blob {
    public:
      GisBlob();
  
      GisBlob(Cube &cube);
  
      ~GisBlob();
  
      QString polygon() const;
  
      void setPolygon(const QString &wkt);
  
    private:
      QString scrub(const char *rawbuf, int rbytes)  const;
  
      QString m_wkt; //!< Well-known text string containing the polygon defintion for this GIS blob.
  };
} // Namespace Isis

#endif

+9 −0

File added.

Preview size limit exceeded, changes collapsed.

+7 −0
Original line number Diff line number Diff line
ifeq ($(ISISROOT), $(BLANK))
.SILENT:
error:
	echo "Please set ISISROOT";
else
	include $(ISISROOT)/make/isismake.objs
endif
 No newline at end of file
+64 −0
Original line number Diff line number Diff line
#include <QDebug>
#include <QFile>
#include <QIODevice>
#include <QTextStream>

#include "Cube.h"
#include "GisBlob.h"
#include "IException.h"
#include "IString.h"
#include "Preference.h"

using namespace Isis;
using namespace std;

/**
 * Unit test for GisBlob class
 *
 *
 * @author 2016-02-23 Jeannie Backer
 *
 * @internal
 *   @history 2016-02-23 Jeannie Backer - Original version.
 *  
 */
int main() {
  try {
    Preference::Preferences(true);
    qDebug();
    qDebug() << "Testing GisBlob's constructor from cube...";
    QString inputFile = "$messenger/testData/EW0211286081G.lev1.cub";
    Cube cube;
    cube.open(inputFile);
    GisBlob cubeBlob(cube);
    qDebug() << "    Polygon = " << cubeBlob.polygon();

    qDebug();
    qDebug() << "Testing GisBlob's default constructor...";
    GisBlob blob;
    qDebug() << "    Polygon = " << blob.polygon();
    
    qDebug();
    qDebug() << "Adding WKT polygon to GisBlob...";
    /*
    QFile file("unitTest.wkt");
    if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
      throw IException(IException::Io, "Unable to open wkt file, [unitTest.wkt]", _FILEINFO_);
    }
    QString wkt;
    QTextStream stream(&file);
    wkt.append(stream.readAll());
    */
    QString wkt = cubeBlob.polygon();
    blob.setPolygon(wkt);
    qDebug() << "    Polygon = " << blob.polygon();
  }
  catch (IException &e) {
    qDebug();
    qDebug();
    QString msg = "**************** UNIT TEST FAILED! **************** ";
    IException(e, IException::Unknown, msg, _FILEINFO_).print();
  }
}

Loading