gstlearn  1.0.0
CCC
Polygons Class Reference

#include <Polygons.hpp>

Inheritance diagram for Polygons:
AStringable ASerializable

Public Member Functions

 Polygons ()
 
 Polygons (const Polygons &r)
 
Polygonsoperator= (const Polygons &r)
 
virtual ~Polygons ()
 
virtual String toString (const AStringFormat *strfmt=nullptr) const override
 Interface to AStringable. More...
 
int resetFromDb (const Db *db, double dilate=0., bool verbose=false)
 
int resetFromCSV (const String &filename, const CSVformat &csv, int verbose=false, int ncol_max=-1, int nrow_max=-1)
 
int resetFromWKT (const String &filename, const CSVformat &csv, int verbose=false, int ncol_max=-1, int nrow_max=-1)
 
int getPolyElemNumber () const
 
void addPolyElem (const PolyElem &polyelem)
 
const std::vector< PolyElem > & getPolyElems () const
 
const PolyElem getPolyElem (int ipol) const
 
PolyElem getClosedPolyElem (int ipol) const
 
const VectorDouble getX (int ipol) const
 
const VectorDouble getY (int ipol) const
 
void setX (int ipol, const VectorDouble &x)
 
void setY (int ipol, const VectorDouble &y)
 
void getExtension (double *xmin, double *xmax, double *ymin, double *ymax) const
 
double getSurface () const
 
bool inside (const VectorDouble &coor, bool flag_nested=false)
 
Polygons reduceComplexity (double distmin) const
 
- Public Member Functions inherited from AStringable
 AStringable ()
 
 AStringable (const AStringable &r)
 
AStringableoperator= (const AStringable &r)
 
virtual ~AStringable ()
 
virtual void display (const AStringFormat *strfmt=nullptr) const final
 
virtual void display (int level) const final
 
- Public Member Functions inherited from ASerializable
 ASerializable ()
 
 ASerializable (const ASerializable &r)
 
ASerializableoperator= (const ASerializable &r)
 
virtual ~ASerializable ()
 
bool deserialize (std::istream &is, bool verbose=true)
 
bool serialize (std::ostream &os, bool verbose=true) const
 
bool dumpToNF (const String &neutralFilename, bool verbose=false) const
 

Static Public Member Functions

static Polygonscreate ()
 
static PolygonscreateFromNF (const String &neutralFilename, bool verbose=false)
 
static PolygonscreateFromCSV (const String &filename, const CSVformat &csv=CSVformat(), int verbose=false, int ncol_max=-1, int nrow_max=-1)
 
static PolygonscreateFromWKT (const String &filename, const CSVformat &csv=CSVformat(), int verbose=false, int ncol_max=-1, int nrow_max=-1)
 
static PolygonscreateFromDb (const Db *db, double dilate=0., bool verbose=false)
 
- Static Public Member Functions inherited from ASerializable
static String buildFileName (int status, const String &filename, bool ensureDirExist=false)
 
static String getHomeDirectory (const String &sub="")
 
static String getWorkingDirectory ()
 
static String getTestData (const String &subdir, const String &filename)
 
static String getFileIdentity (const String &filename, bool verbose=false)
 
static void setContainerName (bool useDefault, const String &containerName="", bool verbose=false)
 
static void unsetContainerName ()
 
static void setPrefixName (const String &prefixName)
 
static void unsetPrefixName ()
 
static const StringgetContainerName ()
 
static const StringgetPrefixName ()
 
static bool createDirectory (const String &dir)
 
static String getExecDirectory ()
 
static String getDirectory (const String &path)
 

Protected Member Functions

virtual bool _deserialize (std::istream &is, bool verbose=false) override
 Interface for ASerializable. More...
 
virtual bool _serialize (std::ostream &os, bool verbose=false) const override
 
String _getNFName () const override
 
- Protected Member Functions inherited from ASerializable
bool _fileOpenWrite (const String &filename, std::ofstream &os, bool verbose=false) const
 
bool _fileOpenRead (const String &filename, std::ifstream &is, bool verbose=false) const
 

Private Member Functions

PolyElem _extractFromTab (int ideb, int ifin, int ncol, const VectorDouble &tab)
 
PolyElem _extractFromWKT (const CSVformat &csv, String &polye)
 
bool _isValidPolyElemIndex (int ipol) const
 
VectorInt _getHullIndices (const VectorDouble &x, const VectorDouble &y) const
 
void _getExtend (double ext, VectorDouble &x, VectorDouble &y, int nsect=16)
 
int _buildHull (const Db *db, double dilate, bool verbose)
 
void _polygonHullPrint (const VectorInt &index, const VectorDouble &x, const VectorDouble &y) const
 

Private Attributes

std::vector< PolyElem_polyelems
 

Additional Inherited Members

- Static Protected Member Functions inherited from ASerializable
static bool _commentWrite (std::ostream &os, const String &comment)
 
template<typename T >
static bool _recordWrite (std::ostream &os, const String &title, const T &val)
 
template<typename T >
static bool _recordWriteVec (std::ostream &os, const String &title, const VectorT< T > &vec)
 
template<typename T >
static bool _recordRead (std::istream &is, const String &title, T &val)
 
template<typename T >
static bool _recordReadVec (std::istream &is, const String &title, VectorT< T > &vec, int nvalues)
 
static bool _onlyBlanks (char *string)
 
static bool _tableRead (std::istream &is, const String &string, int ntab, double *tab)
 
static bool _tableWrite (std::ostream &os, const String &string, int ntab, const VectorDouble &tab)
 

Constructor & Destructor Documentation

◆ Polygons() [1/2]

Polygons::Polygons ( )

◆ Polygons() [2/2]

Polygons::Polygons ( const Polygons r)

◆ ~Polygons()

Polygons::~Polygons ( )
virtual

Member Function Documentation

◆ _buildHull()

int Polygons::_buildHull ( const Db db,
double  dilate,
bool  verbose 
)
private

Create a polygon from the convex hull of active samples

Returns
Error returned code
Parameters
[in]dbdescriptor of the Db serving for convex hull calculation
[in]dilateRadius of the dilation
[in]verboseVerbose flag

◆ _deserialize()

bool Polygons::_deserialize ( std::istream &  is,
bool  verbose = false 
)
overrideprotectedvirtual

Interface for ASerializable.

Implements ASerializable.

◆ _extractFromTab()

PolyElem Polygons::_extractFromTab ( int  ideb,
int  ifin,
int  ncol,
const VectorDouble tab 
)
private

◆ _extractFromWKT()

PolyElem Polygons::_extractFromWKT ( const CSVformat csv,
String polye 
)
private

◆ _getExtend()

void Polygons::_getExtend ( double  ext,
VectorDouble x,
VectorDouble y,
int  nsect = 16 
)
private

Create a set of fictitious samples obtained by dilating the initial ones

Parameters
extDilation distance
xVector of X-coordinates or initial samples
yVector of Y-coordinates of initial samples
nsectNumber of discretization points for dilation

◆ _getHullIndices()

VectorInt Polygons::_getHullIndices ( const VectorDouble x,
const VectorDouble y 
) const
private

Create a polygon from the convex hull of active samples

Returns
Error returned code
Parameters
[in]xVector of X coordinates
[in]yVector of Y coordinates

◆ _getNFName()

String Polygons::_getNFName ( ) const
inlineoverrideprotectedvirtual

Implements ASerializable.

◆ _isValidPolyElemIndex()

bool Polygons::_isValidPolyElemIndex ( int  ipol) const
private

◆ _polygonHullPrint()

void Polygons::_polygonHullPrint ( const VectorInt index,
const VectorDouble x,
const VectorDouble y 
) const
private

◆ _serialize()

bool Polygons::_serialize ( std::ostream &  os,
bool  verbose = false 
) const
overrideprotectedvirtual

Implements ASerializable.

◆ addPolyElem()

void Polygons::addPolyElem ( const PolyElem polyelem)

Add the PolyElem to the list of polygons. This is performed only if the current PolyElem contains at least 3 vertices.

Parameters
polyelem

◆ create()

Polygons * Polygons::create ( )
static

◆ createFromCSV()

Polygons * Polygons::createFromCSV ( const String filename,
const CSVformat csv = CSVformat(),
int  verbose = false,
int  ncol_max = -1,
int  nrow_max = -1 
)
static

◆ createFromDb()

Polygons * Polygons::createFromDb ( const Db db,
double  dilate = 0.,
bool  verbose = false 
)
static

◆ createFromNF()

Polygons * Polygons::createFromNF ( const String neutralFilename,
bool  verbose = false 
)
static

Create a Polygon by loading the contents of a Neutral File

Parameters
neutralFilenameName of the Neutral File
verboseVerbose flag
Returns

◆ createFromWKT()

Polygons * Polygons::createFromWKT ( const String filename,
const CSVformat csv = CSVformat(),
int  verbose = false,
int  ncol_max = -1,
int  nrow_max = -1 
)
static

◆ getClosedPolyElem()

PolyElem Polygons::getClosedPolyElem ( int  ipol) const

◆ getExtension()

void Polygons::getExtension ( double *  xmin,
double *  xmax,
double *  ymin,
double *  ymax 
) const

◆ getPolyElem()

const PolyElem Polygons::getPolyElem ( int  ipol) const

◆ getPolyElemNumber()

int Polygons::getPolyElemNumber ( ) const
inline

◆ getPolyElems()

const std::vector<PolyElem>& Polygons::getPolyElems ( ) const
inline

◆ getSurface()

double Polygons::getSurface ( ) const

◆ getX()

const VectorDouble Polygons::getX ( int  ipol) const

◆ getY()

const VectorDouble Polygons::getY ( int  ipol) const

◆ inside()

bool Polygons::inside ( const VectorDouble coor,
bool  flag_nested = false 
)

Check if one point belongs to a Polygons

Returns
1 if the point belongs to the Polygons; 0 otherwise
Parameters
[in]coorVector of coordinates
[in]flag_nestedOption for nested polyelems (see details)
Remarks
When coor is dimensioned to 3, the third dimension test is performed
If flag_nested=TRUE, a sample is masked off if the number of
polyelems to which it belongs is odd
If flag_nested=FALSE, a sample is masked off as soon as it
belongs to one PolyElem

◆ operator=()

Polygons & Polygons::operator= ( const Polygons r)

◆ reduceComplexity()

Polygons Polygons::reduceComplexity ( double  distmin) const

◆ resetFromCSV()

int Polygons::resetFromCSV ( const String filename,
const CSVformat csv,
int  verbose = false,
int  ncol_max = -1,
int  nrow_max = -1 
)

Reset the Polygon from a CSV file

Parameters
filenameFilename
csvCSV characteristics
verboseVerbose flag
ncol_maxMaximum number of columns
nrow_maxMaximum number of rows
Returns

◆ resetFromDb()

int Polygons::resetFromDb ( const Db db,
double  dilate = 0.,
bool  verbose = false 
)

◆ resetFromWKT()

int Polygons::resetFromWKT ( const String filename,
const CSVformat csv,
int  verbose = false,
int  ncol_max = -1,
int  nrow_max = -1 
)

Reset the Polygon from a CSV file using WKT format (first column) exported by QGIS

Parameters
filenameFilename
csvCSV characteristics
verboseVerbose flag
ncol_maxMaximum number of columns
nrow_maxMaximum number of rows
Returns

◆ setX()

void Polygons::setX ( int  ipol,
const VectorDouble x 
)

◆ setY()

void Polygons::setY ( int  ipol,
const VectorDouble y 
)

◆ toString()

String Polygons::toString ( const AStringFormat strfmt = nullptr) const
overridevirtual

Interface to AStringable.

Reimplemented from AStringable.

Member Data Documentation

◆ _polyelems

std::vector<PolyElem> Polygons::_polyelems
private

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