Isis 3 Programmer Reference
Isis::GisGeometry Class Reference

Encapsulation class provides support for GEOS-C API. More...

#include <GisGeometry.h>

Collaboration diagram for Isis::GisGeometry:
Collaboration graph

Public Types

enum  Type {
  None , WKT , WKB , IsisCube ,
  GeosGis
}
 Source type of the geometry. More...
 

Public Member Functions

 GisGeometry ()
 Fundamental constructor of an empty object.
 
 GisGeometry (const double xlongitude, const double ylatitude)
 Construct a point geometry.
 
 GisGeometry (Cube &cube)
 Create a geometry from a cube file.
 
 GisGeometry (const QString &gisSource, const Type t)
 Create a geometry from a character WKT/WKB source.
 
 GisGeometry (const GisGeometry &geom)
 Create a geometry from another geometry by cloning.
 
 GisGeometry (GEOSGeometry *geom)
 Create a GISGeometry directly from a GEOS-C GEOSGeometry.
 
GisGeometryoperator= (GisGeometry const &geom)
 Assignment operator for GISGeomtries.
 
virtual ~GisGeometry ()
 Destructor.
 
void setGeometry (GEOSGeometry *geom)
 Set the geometry directly taking ownership.
 
bool isDefined () const
 Determines if the current geometry is valid.
 
bool isValid () const
 Determines validity of the geometry contained in this object.
 
QString isValidReason () const
 Returns a string describing reason for invalid geometry.
 
bool isEmpty () const
 Tests for a defined but empty geometry.
 
Type type () const
 Returns the type (origin) of the geometry.
 
const GEOSGeometry * geometry () const
 Returns the GEOSGeometry object to extend functionality.
 
const GEOSPreparedGeometry * preparedGeometry () const
 Returns special GEOS prepared geometry if it exists.
 
GisGeometryclone () const
 Clones the contents of this geometry to a new instance.
 
double area () const
 Computes the area of a geometry.
 
double length () const
 Computes the length of a geometry.
 
double distance (const GisGeometry &target) const
 Computes the distance between two geometries.
 
int points () const
 Get number of points in geometry.
 
bool intersects (const GisGeometry &target) const
 Computes a new geometry from the intersection of the two geomtries.
 
bool contains (const GisGeometry &target) const
 Test if the target geometry is contained within this geometry.
 
bool disjoint (const GisGeometry &target) const
 Tests for disjoint geometries.
 
bool overlaps (const GisGeometry &target) const
 Test for overlapping geometries.
 
bool equals (const GisGeometry &target) const
 Test if target and this geometry are equal.
 
double intersectRatio (const GisGeometry &geom) const
 Computes intersect ratio between two geometries.
 
GisGeometryenvelope () const
 Computes the envelope or bounding box of this geometry.
 
GisGeometryconvexHull () const
 Computes the convex hull of the geometry.
 
GisGeometrysimplify (const double &tolerance) const
 Simplify complex or overdetermined geoemtry.
 
GisGeometryintersection (const GisGeometry &geom) const
 Computes the intersection of two geometries.
 
GisGeometryg_union (const GisGeometry &geom) const
 Computes the union of two geometries.
 
GisGeometrycentroid () const
 Computes the centroid of the geometry and returns it as a new geometry.
 
bool centroid (double &xlongitude, double &ylatitude) const
 Computes the centroid of a spatial geometry.
 

Static Public Member Functions

static Type type (const QString &gtype)
 Returns enum representation of the geometry origin from string type.
 
static QString typeToString (const Type &type)
 Returns the type of the Geometry as a QString.
 

Private Member Functions

GEOSGeometry * makePoint (const double x, const double y) const
 Create a point geometry.
 
GEOSGeometry * fromCube (Cube &cube) const
 Reads Polygon from ISIS Cube and returns geometry from contents.
 
GEOSPreparedGeometry const * makePrepared (const GEOSGeometry *geom) const
 Creates a prepared geometry of current geometry.
 
void destroy ()
 Destroys the GEOS elements of this geometry object.
 

Private Attributes

Type m_type
 Geometry type of GIS source.
 
GEOSGeometry * m_geom
 Pointer to GEOS-C opaque structure.
 
GEOSPreparedGeometry const * m_preparedGeom
 A prepared geometry from the GEOS library.
 

Detailed Description

Encapsulation class provides support for GEOS-C API.

The Geometry Engine, Open Source (GEOS) software package, developed in C++ from a port of the Java Toplogy Suite (JTS) provides a simplied, generic C API using an opaque C pointer. This layer is to provide stable API from which to develop and maintain applications that are relatively immune from changes to the underlying C++ implementation.

This class provides much of the basic elements to support simplified development of C++ applications with similiar goals - to provide immmunity from developmental changes to code using the GEOS-C API in a C++ development environment.

The GEOS home page is http://trac.osgeo.org/geos/. The documentation for the GEOS-C package can be found at http://geos.osgeo.org/doxygen/c_iface.html.

Author
2012-07-15 Kris Becker
History

2012-07-15 Kris Becker - Original version.

2015-03-18 Jeannie Backer - Brought class files closer to ISIS coding standards.

2016-03-02 Ian Humphrey - Updated for coding standards compliance. Added to jwbacker's original unit test to prepare for adding this class to ISIS. Fixes #2398.

2016-03-04 Kris Becker - Completed the documentation and implmented the equals() method.

Definition at line 50 of file GisGeometry.h.

Member Enumeration Documentation

◆ Type

Source type of the geometry.

Enumerator
None 

No geometry. A geometry object cannot be created with this geometry type.

WKT 

The GEOS library WKT reader is used to create the geometry.

WKB 

The GEOS library WKB reader is used to create the geometry.

IsisCube 

An ISIS Cube is used to create the geometry.

GeosGis 

GEOS GIS. A geometry object cannot be created with this geometry type.

Definition at line 56 of file GisGeometry.h.

Constructor & Destructor Documentation

◆ GisGeometry() [1/6]

Isis::GisGeometry::GisGeometry ( )

Fundamental constructor of an empty object.

Definition at line 33 of file GisGeometry.cpp.

References Isis::GisTopology::instance().

Referenced by centroid(), clone(), convexHull(), envelope(), g_union(), intersection(), and simplify().

◆ GisGeometry() [2/6]

Isis::GisGeometry::GisGeometry ( const double xlongitude,
const double ylatitude )

Construct a point geometry.

This constructor will create a point geometry. Note this can either be used to create a geometric geometry with a longitude/latitude or a grid geometry in any system with an X/Y value. It is up to the caller to maintain the coordinate system.

Parameters
xlongitudeX or longitude coordinate
ylatitudeY or latitude coordinate

Definition at line 50 of file GisGeometry.cpp.

References Isis::GisTopology::instance(), m_geom, m_preparedGeom, makePoint(), and makePrepared().

◆ GisGeometry() [3/6]

Isis::GisGeometry::GisGeometry ( Cube & cube)

Create a geometry from a cube file.

This constructor will read the contents of the Polygon blob of an ISIS cube file and create a geometry from its contents.

Parameters
cubeCube object to create the geomtery from

Definition at line 68 of file GisGeometry.cpp.

References fromCube(), Isis::GisTopology::instance(), m_geom, m_preparedGeom, and makePrepared().

◆ GisGeometry() [4/6]

Isis::GisGeometry::GisGeometry ( const QString & gisSource,
const Type t )

Create a geometry from a character WKT/WKB source.

Parameters
gisSourceString containing the text representation of a GIS geometry. This can be either a WKT or WKB formatted string
tType of GisGeometry - WKT or WKB

Definition at line 85 of file GisGeometry.cpp.

References fromCube(), Isis::GisTopology::instance(), IsisCube, m_geom, m_preparedGeom, m_type, makePrepared(), Isis::Cube::open(), Isis::IException::Programmer, typeToString(), WKB, and WKT.

◆ GisGeometry() [5/6]

Isis::GisGeometry::GisGeometry ( const GisGeometry & geom)

Create a geometry from another geometry by cloning.

This contructor uses the GISTopology clone method to generate a new geometry.

Parameters
geomGISGeometry to create new geometry from

Definition at line 120 of file GisGeometry.cpp.

References Isis::GisTopology::instance(), isDefined(), m_geom, m_preparedGeom, and makePrepared().

◆ GisGeometry() [6/6]

Isis::GisGeometry::GisGeometry ( GEOSGeometry * geom)

Create a GISGeometry directly from a GEOS-C GEOSGeometry.

This constructor will create a new GISGeometry object that takes ownership from the caller and is managed for the life of this new object.

Parameters
geomGEOSGeometry instance to use

Definition at line 140 of file GisGeometry.cpp.

References Isis::GisTopology::instance(), m_geom, m_preparedGeom, and makePrepared().

◆ ~GisGeometry()

Isis::GisGeometry::~GisGeometry ( )
virtual

Destructor.

Definition at line 151 of file GisGeometry.cpp.

References destroy().

Member Function Documentation

◆ area()

double Isis::GisGeometry::area ( ) const

Computes the area of a geometry.

This method will compute the area of a geometry. Note the area is in the units of the coordinates. For example, if the coordinates of the geometry are in latitude/longitude, then the units are in degrees. Callers must maintain the units of the coordinates.

Point geometries will have 0 area.

Returns
double Area of the geometry in units of data coordinates of the geometry

Definition at line 359 of file GisGeometry.cpp.

References isValid(), and m_geom.

Referenced by intersectRatio().

◆ centroid() [1/2]

GisGeometry * Isis::GisGeometry::centroid ( ) const

Computes the centroid of the geometry and returns it as a new geometry.

Returns
GisGeometry Pointer to point geometry of centroid of this geometry

Definition at line 746 of file GisGeometry.cpp.

References GisGeometry(), isValid(), and m_geom.

◆ centroid() [2/2]

bool Isis::GisGeometry::centroid ( double & xlongitude,
double & ylatitude ) const

Computes the centroid of a spatial geometry.

This method will compute the coordinate centroid of a spatial geometry.

Parameters
xlongitudeX/longitude coordinate of centroid
ylatitudeY/latitude coordinate of centroid
Returns
bool True if successful, false if failed

Definition at line 723 of file GisGeometry.cpp.

References Isis::GisTopology::instance(), isValid(), m_geom, and Isis::Null.

◆ clone()

GisGeometry * Isis::GisGeometry::clone ( ) const

Clones the contents of this geometry to a new instance.

This method will clone the contents of this geometry and return a new instance to the caller.

Returns
GisGeometry Geometry to clone

Definition at line 318 of file GisGeometry.cpp.

References GisGeometry(), Isis::GisTopology::instance(), isDefined(), m_geom, m_type, and makePrepared().

◆ contains()

bool Isis::GisGeometry::contains ( const GisGeometry & target) const

Test if the target geometry is contained within this geometry.

Parameters
targetOther geometry to test
Returns
bool True if target is contained with this geometry, false otherwise

Definition at line 478 of file GisGeometry.cpp.

References geometry(), isValid(), m_geom, and m_preparedGeom.

◆ convexHull()

GisGeometry * Isis::GisGeometry::convexHull ( ) const

Computes the convex hull of the geometry.

Returns
GisGeometry Pointer to new geometry that represents the convex hull of this geometry. A null geometry, not NULL pointer is returned if problems occur.

Definition at line 636 of file GisGeometry.cpp.

References GisGeometry(), isValid(), and m_geom.

◆ destroy()

void Isis::GisGeometry::destroy ( )
private

Destroys the GEOS elements of this geometry object.

Definition at line 806 of file GisGeometry.cpp.

References Isis::GisTopology::instance(), m_geom, and m_preparedGeom.

Referenced by operator=(), setGeometry(), and ~GisGeometry().

◆ disjoint()

bool Isis::GisGeometry::disjoint ( const GisGeometry & target) const

Tests for disjoint geometries.

Parameters
targetOther geometry to test
Returns
bool True if geometries are disjoint, false otherwise

Definition at line 504 of file GisGeometry.cpp.

References geometry(), isValid(), m_geom, and m_preparedGeom.

◆ distance()

double Isis::GisGeometry::distance ( const GisGeometry & target) const

Computes the distance between two geometries.

This method computes the distance between two geometries. Refer to the GEOS documentation as to the details of this computation.

Parameters
targetTarget geometry to compute distance to
Returns
double Distance in units of geometry coordinates

Definition at line 406 of file GisGeometry.cpp.

References geometry(), isValid(), m_geom, and Isis::Null.

◆ envelope()

GisGeometry * Isis::GisGeometry::envelope ( ) const

Computes the envelope or bounding box of this geometry.

This method computes the envelope or bounding box of the geometry in this object. A new geometry is computed and a pointer is returned to the caller. The caller assumes ownership of this geometry.

A null geometry will be returned if an error is occured or the current geometry is invalid.

Returns
GisGeometry Pointer to envelope/bounding box. A null geometry, not NULL pointer, is returned in problems occur.

Definition at line 619 of file GisGeometry.cpp.

References GisGeometry(), isValid(), and m_geom.

◆ equals()

bool Isis::GisGeometry::equals ( const GisGeometry & target) const

Test if target and this geometry are equal.

Parameters
targetGeometry to test for equality
Returns
bool True if geometries are equal, false if not

Definition at line 557 of file GisGeometry.cpp.

References geometry(), isValid(), and m_geom.

◆ fromCube()

GEOSGeometry * Isis::GisGeometry::fromCube ( Cube & cube) const
private

Reads Polygon from ISIS Cube and returns geometry from contents.

Parameters
cubeISIS Cube contaning a Polygon geometry object
Returns
GEOSGeometry Pointer to GEOS-C type geometry from Polygon BLOB

Definition at line 795 of file GisGeometry.cpp.

References Isis::GisTopology::instance(), and Isis::Cube::readFootprint().

Referenced by GisGeometry(), and GisGeometry().

◆ g_union()

GisGeometry * Isis::GisGeometry::g_union ( const GisGeometry & target) const

Computes the union of two geometries.

Parameters
targetOther geometry to union with this geometry
Returns
GisGeometry Result of unioning the two geometries

Definition at line 701 of file GisGeometry.cpp.

References geometry(), GisGeometry(), isValid(), and m_geom.

◆ geometry()

const GEOSGeometry * Isis::GisGeometry::geometry ( ) const

Returns the GEOSGeometry object to extend functionality.

Returns
GEOSGeometry Pointer to GEOSGeometry structure

Definition at line 291 of file GisGeometry.cpp.

References m_geom.

Referenced by Isis::Strategy::applyToIntersectedGeometry(), contains(), disjoint(), distance(), equals(), g_union(), intersection(), intersects(), and overlaps().

◆ intersection()

GisGeometry * Isis::GisGeometry::intersection ( const GisGeometry & target) const

Computes the intersection of two geometries.

The area of common interesction of the target geometry and this geometry are computed and returned to the caller.

Parameters
targetOther geometry to compute intersection
Returns
GisGeometry Intersection geometry

Definition at line 681 of file GisGeometry.cpp.

References geometry(), GisGeometry(), isValid(), and m_geom.

Referenced by intersectRatio().

◆ intersectRatio()

double Isis::GisGeometry::intersectRatio ( const GisGeometry & target) const

Computes intersect ratio between two geometries.

This method computes the intersection of two geometries and the returns the ratio of the area of intersection with this geometry. Units must be the same for both geometries or result will not be valid.

Parameters
targetGeometry to compute intersect ratio for
Returns
double Area of common intersection of two geometries in units of the two geometries.

Definition at line 582 of file GisGeometry.cpp.

References area(), intersection(), and isValid().

◆ intersects()

bool Isis::GisGeometry::intersects ( const GisGeometry & target) const

Computes a new geometry from the intersection of the two geomtries.

This method will compute the union of two geometries and return a new geometry that represents the combination of them.

Parameters
targetOther geometry to combine by union opertor
Returns
bool True if operation is successful, false otherwise

Definition at line 451 of file GisGeometry.cpp.

References geometry(), isValid(), m_geom, and m_preparedGeom.

Referenced by Isis::Strategy::applyToIntersectedGeometry().

◆ isDefined()

bool Isis::GisGeometry::isDefined ( ) const

Determines if the current geometry is valid.

Returns
bool True if contents are valid, otherwise false

Definition at line 200 of file GisGeometry.cpp.

References m_geom.

Referenced by clone(), GisGeometry(), isValid(), isValidReason(), and operator=().

◆ isEmpty()

bool Isis::GisGeometry::isEmpty ( ) const

Tests for a defined but empty geometry.

Returns
bool True if empty, false if has content

Definition at line 338 of file GisGeometry.cpp.

References isValid(), and m_geom.

◆ isValid()

bool Isis::GisGeometry::isValid ( ) const

Determines validity of the geometry contained in this object.

First determines if it contains a geometry and then validates with the GEOS toolkit.

Returns
bool True if valid, false if invalid or non-existant

Definition at line 213 of file GisGeometry.cpp.

References isDefined(), and m_geom.

Referenced by Isis::Strategy::applyToIntersectedGeometry(), area(), centroid(), centroid(), contains(), convexHull(), disjoint(), distance(), envelope(), equals(), g_union(), intersection(), intersectRatio(), intersects(), isEmpty(), length(), overlaps(), points(), and simplify().

◆ isValidReason()

QString Isis::GisGeometry::isValidReason ( ) const

Returns a string describing reason for invalid geometry.

Returns
QString Description of the reason the geometry is invalid

Definition at line 227 of file GisGeometry.cpp.

References Isis::GisTopology::instance(), isDefined(), and m_geom.

◆ length()

double Isis::GisGeometry::length ( ) const

Computes the length of a geometry.

This method will compute the length of a geometry. This is suitable for Linestring and spatial geometries.

Returns
double Length of the geometry in units of the coordinates

Definition at line 382 of file GisGeometry.cpp.

References isValid(), and m_geom.

◆ makePoint()

GEOSGeometry * Isis::GisGeometry::makePoint ( const double x,
const double y ) const
private

Create a point geometry.

Parameters
yY or latitude coordinate
Returns
GEOSGeometry Pointer to point geometry. Caller assumes ownership

Definition at line 779 of file GisGeometry.cpp.

Referenced by GisGeometry().

◆ makePrepared()

GEOSPreparedGeometry const * Isis::GisGeometry::makePrepared ( const GEOSGeometry * geom) const
private

Creates a prepared geometry of current geometry.

Parameters
geom
Returns
GEOSPreparedGeometry

Definition at line 762 of file GisGeometry.cpp.

References Isis::GisTopology::instance().

Referenced by clone(), GisGeometry(), GisGeometry(), GisGeometry(), GisGeometry(), GisGeometry(), operator=(), and setGeometry().

◆ operator=()

GisGeometry & Isis::GisGeometry::operator= ( GisGeometry const & geom)

Assignment operator for GISGeomtries.

This assignment operator essentially clones the right side geomemtry

Parameters
geomGeometry to assign to current object
Returns
GisGeometry New geometry

Definition at line 164 of file GisGeometry.cpp.

References destroy(), Isis::GisTopology::instance(), isDefined(), m_geom, m_preparedGeom, m_type, and makePrepared().

◆ overlaps()

bool Isis::GisGeometry::overlaps ( const GisGeometry & target) const

Test for overlapping geometries.

Parameters
targetGeometry to test for overlap with this geometry
Returns
bool True if target geometry overlaps with this geometry, false otherwise

Definition at line 531 of file GisGeometry.cpp.

References geometry(), isValid(), m_geom, and m_preparedGeom.

◆ points()

int Isis::GisGeometry::points ( ) const

Get number of points in geometry.

Returns
int Number of points contained in the geometry

Definition at line 429 of file GisGeometry.cpp.

References isValid(), and m_geom.

Referenced by Isis::Strategy::importGeometry().

◆ preparedGeometry()

const GEOSPreparedGeometry * Isis::GisGeometry::preparedGeometry ( ) const

Returns special GEOS prepared geometry if it exists.

This method will return a pointer to the prepared version of the GEOSGeometry data. Caller should test for a NULL pointer as it may be disabled or non-existant.

Returns
GEOSPreparedGeometry Pointer to prepared geometry

Definition at line 305 of file GisGeometry.cpp.

References m_preparedGeom.

◆ setGeometry()

void Isis::GisGeometry::setGeometry ( GEOSGeometry * geom)

Set the geometry directly taking ownership.

This method will replace the current geoemetry with the geom parameter contents. The existing contents of this object is destroyed before taking ownership of the geom paramter object.

Parameters
geomGEOSGeometry to incoporate into this object

Definition at line 187 of file GisGeometry.cpp.

References destroy(), m_geom, m_preparedGeom, and makePrepared().

◆ simplify()

GisGeometry * Isis::GisGeometry::simplify ( const double & tolerance) const

Simplify complex or overdetermined geoemtry.

This method will simplify a geometry with a Douglas -Peucker algorithm using a tolerance specifying the maximum distance from the original (multi)polygon. The use of this algorithm is designed to prevent oversimplification

Parameters
toleranceMaximum distance from the original geometry expressed in the coordinate system of the geometry.
Returns
GisGeometry* Simplified geometry

Definition at line 659 of file GisGeometry.cpp.

References GisGeometry(), isValid(), and m_geom.

Referenced by Isis::Strategy::importGeometry().

◆ type() [1/2]

GisGeometry::Type Isis::GisGeometry::type ( ) const

Returns the type (origin) of the geometry.

Returns
GisGeometry::Type Enum type of geometry origin

Definition at line 244 of file GisGeometry.cpp.

References m_type.

Referenced by Isis::Strategy::importGeometry(), and typeToString().

◆ type() [2/2]

GisGeometry::Type Isis::GisGeometry::type ( const QString & gstrType)
static

Returns enum representation of the geometry origin from string type.

See also
type(QString)
Parameters
gstrTypeCharacter representation of geometry origin
Returns
GisGeometry::Type Enum type of origin

Definition at line 256 of file GisGeometry.cpp.

References GeosGis, IsisCube, None, WKB, and WKT.

◆ typeToString()

QString Isis::GisGeometry::typeToString ( const Type & type)
static

Returns the type of the Geometry as a QString.

See also
type(QString)
Parameters
gstrTypeEnum type of origin
Returns
GisGeometry::Type Character representation of geometry or origin

Definition at line 277 of file GisGeometry.cpp.

References GeosGis, IsisCube, type(), WKB, and WKT.

Referenced by GisGeometry().

Member Data Documentation

◆ m_geom

◆ m_preparedGeom

GEOSPreparedGeometry const* Isis::GisGeometry::m_preparedGeom
private

A prepared geometry from the GEOS library.

Definition at line 120 of file GisGeometry.h.

Referenced by contains(), destroy(), disjoint(), GisGeometry(), GisGeometry(), GisGeometry(), GisGeometry(), GisGeometry(), intersects(), operator=(), overlaps(), preparedGeometry(), and setGeometry().

◆ m_type

Type Isis::GisGeometry::m_type
private

Geometry type of GIS source.

Definition at line 118 of file GisGeometry.h.

Referenced by clone(), GisGeometry(), operator=(), and type().


The documentation for this class was generated from the following files: