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

Static Public Member Functions

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

Private Member Functions

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

Private Attributes

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

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 67 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 73 of file GisGeometry.h.

Constructor & Destructor Documentation

◆ GisGeometry() [1/6]

Isis::GisGeometry::GisGeometry ( )

Fundamental constructor of an empty object.

Definition at line 50 of file GisGeometry.cpp.

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 67 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 85 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 102 of file GisGeometry.cpp.

References _FILEINFO_, fromCube(), Isis::GisTopology::geomFromWKB(), Isis::GisTopology::geomFromWKT(), 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 137 of file GisGeometry.cpp.

References Isis::GisTopology::clone(), 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 157 of file GisGeometry.cpp.

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

◆ ~GisGeometry()

Isis::GisGeometry::~GisGeometry ( )
virtual

Destructor.

Definition at line 168 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 376 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 763 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 740 of file GisGeometry.cpp.

References Isis::GisTopology::destroy(), 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 335 of file GisGeometry.cpp.

References Isis::GisTopology::clone(), 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 495 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 653 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 822 of file GisGeometry.cpp.

References Isis::GisTopology::destroy(), 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 521 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 423 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 636 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 574 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 812 of file GisGeometry.cpp.

References Isis::GisTopology::geomFromWKT(), Isis::GisTopology::instance(), and Isis::GisBlob::polygon().

Referenced by 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 718 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 308 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 698 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 599 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 468 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 217 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 355 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 230 of file GisGeometry.cpp.

References isDefined(), and m_geom.

Referenced by Isis::Strategy::applyToIntersectedGeometry(), area(), 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 244 of file GisGeometry.cpp.

References Isis::GisTopology::destroy(), 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 399 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 796 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 779 of file GisGeometry.cpp.

References Isis::GisTopology::instance(), and Isis::GisTopology::preparedGeometry().

Referenced by clone(), 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 181 of file GisGeometry.cpp.

References Isis::GisTopology::clone(), 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 548 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 446 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 322 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 204 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 676 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 261 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 273 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 294 of file GisGeometry.cpp.

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

Referenced by GisGeometry().

Member Data Documentation

◆ m_geom

GEOSGeometry* Isis::GisGeometry::m_geom
private

◆ m_preparedGeom

GEOSPreparedGeometry const* Isis::GisGeometry::m_preparedGeom
private

A prepared geometry from the GEOS library.

Definition at line 137 of file GisGeometry.h.

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

◆ m_type

Type Isis::GisGeometry::m_type
private

Geometry type of GIS source.

Definition at line 135 of file GisGeometry.h.

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


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