Skip to content

Commit

Permalink
Boost coverage of SIP bindings
Browse files Browse the repository at this point in the history
Now all classes and members are either exposed to bindings or marked
as "not available in Python bindings" in the docs.

Drop test thresholds to 0. Now it should be much easier to determine
what missing members have been added which are causing test
failures.
  • Loading branch information
nyalldawson committed Jan 5, 2016
1 parent 2341c2b commit 881074b
Show file tree
Hide file tree
Showing 165 changed files with 1,542 additions and 171 deletions.
3 changes: 3 additions & 0 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,12 @@ INCLUDE_DIRECTORIES(
../src/analysis/raster
../src/analysis/network
../src/analysis/interpolation
../src/analysis/openstreetmap
${CMAKE_BINARY_DIR}/src/analysis/vector
${CMAKE_BINARY_DIR}/src/analysis/network
${CMAKE_BINARY_DIR}/src/analysis/raster
${CMAKE_BINARY_DIR}/src/analysis/interpolation
${CMAKE_BINARY_DIR}/src/analysis/openstreetmap
)

# analysis module
Expand All @@ -215,6 +217,7 @@ FILE(GLOB sip_files_analysis
analysis/raster/*.sip
analysis/vector/*.sip
analysis/interpolation/*.sip
analysis/openstreetmap/*.sip
)
SET(SIP_EXTRA_FILES_DEPEND ${sip_files_core} ${sip_files_analysis})
SET(SIP_EXTRA_OPTIONS ${PYQT_SIP_FLAGS} -o -a ${CMAKE_BINARY_DIR}/python/qgis.analysis.api)
Expand Down
5 changes: 5 additions & 0 deletions python/analysis/analysis.sip
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
%Include interpolation/qgsidwinterpolator.sip
%Include interpolation/qgstininterpolator.sip

%Include openstreetmap/qgsosmbase.sip
%Include openstreetmap/qgsosmdatabase.sip
%Include openstreetmap/qgsosmdownload.sip
%Include openstreetmap/qgsosmimport.sip

%Include raster/qgsalignraster.sip
%Include raster/qgsderivativefilter.sip
%Include raster/qgsaspectfilter.sip
Expand Down
105 changes: 105 additions & 0 deletions python/analysis/openstreetmap/qgsosmbase.sip
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
typedef qint64 QgsOSMId;

struct QgsOSMElementID
{
%TypeHeaderCode
#include <qgsosmbase.h>
%End
enum Type { Invalid, Node, Way, Relation };

Type type;
qint64 id;
};


/**
Elements (also data primitives) are the basic components in OpenStreetMap from which everything else
is defined. These consist of Nodes (which define a point in space), Ways (which define a linear features
and areas), and Relations - with an optional role - which are sometimes used to define the relation
between other elements. All of the above can have one of more associated tags.
*/
class QgsOSMElement
{

%TypeHeaderCode
#include <qgsosmbase.h>
%End

public:
QgsOSMElement();
QgsOSMElement( QgsOSMElementID::Type t, qint64 id );

bool isValid() const;

// fetched automatically from DB
QgsOSMElementID elemID() const;
qint64 id() const;
//QString username() const;
//QDateTime timestamp() const;
//int version() const;

};



/**
A node is one of the core elements in the OpenStreetMap data model. It consists of a single geospatial
point using a latitude and longitude. A third optional dimension, altitude, can be recorded; key:ele
and a node can also be defined at a particular layer=* or level=*. Nodes can be used to define standalone
point features or be used to define the path of a way.
*/
class QgsOSMNode : QgsOSMElement
{
%TypeHeaderCode
#include <qgsosmbase.h>
%End
public:
QgsOSMNode();
QgsOSMNode( qint64 id, const QgsPoint& point );

QgsPoint point() const;

};


/**
A way is an ordered list of nodes which normally also has at least one tag or is included within
a Relation. A way can have between 2 and 2,000 nodes, although it's possible that faulty ways with zero
or a single node exist. A way can be open or closed. A closed way is one whose last node on the way
is also the first on that way. A closed way may be interpreted either as a closed polyline, or an area,
or both.
*/
class QgsOSMWay : QgsOSMElement
{
%TypeHeaderCode
#include <qgsosmbase.h>
%End
public:
QgsOSMWay();
QgsOSMWay( qint64 id, const QList<qint64>& nodes );

QList<qint64> nodes() const;

// fetched on-demand
//QList<OSMElementID> relations() const;

};

/**
* This class is a container of tags for a node, way or a relation.
*/
class QgsOSMTags
{
%TypeHeaderCode
#include <qgsosmbase.h>
%End
public:
QgsOSMTags();

int count() const;
QList<QString> keys() const;
bool contains( const QString& k ) const;
void insert( const QString& k, const QString& v );
QString value( const QString& k ) const;

};
82 changes: 82 additions & 0 deletions python/analysis/openstreetmap/qgsosmdatabase.sip
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
typedef QPair<QString, int> QgsOSMTagCountPair;

/**
* Class that encapsulates access to OpenStreetMap data stored in a database
* previously imported from XML file.
*
* Internal database structure consists of the following tables:
* - nodes
* - nodes_tags
* - ways
* - ways_tags
* - ways_nodes
*
* The topology representation can be translated to simple features representation
* using exportSpatiaLite() method into SpatiaLite layers (tables). These can be
* easily used in QGIS like any other layers.
*/
class QgsOSMDatabase
{
%TypeHeaderCode
#include <qgsosmdatabase.h>
%End
public:
explicit QgsOSMDatabase( const QString& dbFileName = QString() );
~QgsOSMDatabase();

void setFileName( const QString& dbFileName );
QString filename() const;
bool isOpen() const;

bool open();
bool close();

QString errorString() const;

// data access

int countNodes() const;
int countWays() const;

//! @note not available in Python bindings
//QgsOSMNodeIterator listNodes() const;
//! @note not available in Python bindings
//QgsOSMWayIterator listWays() const;

QgsOSMNode node( qint64 id ) const;
QgsOSMWay way( qint64 id ) const;
//OSMRelation relation( OSMId id ) const;

QgsOSMTags tags( bool way, qint64 id ) const;

//! @note available in Python bindings
//QList<QPair<QString, int>> usedTags( bool ways ) const;

QgsPolyline wayPoints( qint64 id ) const;

// export to spatialite

enum ExportType { Point, Polyline, Polygon };
bool exportSpatiaLite( ExportType type, const QString& tableName,
const QStringList& tagKeys = QStringList(),
const QStringList& noNullTagKeys = QStringList() );

protected:
bool prepareStatements();
int runCountStatement( const char* sql ) const;

/** @note not available in Python bindings
*/
//void deleteStatement( sqlite3_stmt*& stmt );

void exportSpatiaLiteNodes( const QString& tableName, const QStringList& tagKeys, const QStringList& notNullTagKeys = QStringList() );
void exportSpatiaLiteWays( bool closed, const QString& tableName, const QStringList& tagKeys, const QStringList& notNullTagKeys = QStringList() );
bool createSpatialTable( const QString& tableName, const QString& geometryType, const QStringList& tagKeys );
bool createSpatialIndex( const QString& tableName );

QString quotedIdentifier( QString id );
QString quotedValue( QString value );

};


65 changes: 65 additions & 0 deletions python/analysis/openstreetmap/qgsosmdownload.sip
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* @brief OSMDownload is a utility class for downloading OpenStreetMap via Overpass API.
*
* To use this class, it is necessary to set query, output file name and start the request.
* The interface is asynchronous, the caller has to wait for finished() signal that is
* emitted whe the request has finished (successfully or with an error).
*
* To check whether the the request has been successful, check hasError() and use errorString()
* to retreive error message. An error may happen either directly in start() method
* or during the network communication.
*
* By default OSMDownload uses remote service at location returned by defaultServiceUrl() method.
*/
class QgsOSMDownload : QObject
{
%TypeHeaderCode
#include <qgsosmdownload.h>
%End
public:

//! Return URL of the service that is used by default
static QString defaultServiceUrl();

//! Create query (in Overpass Query Language) that fetches everything in given rectangle
static QString queryFromRect( const QgsRectangle& rect );

QgsOSMDownload();
~QgsOSMDownload();

void setServiceUrl( const QString& serviceUrl );
QString serviceUrl() const;

void setQuery( const QString& query );
QString query() const;

void setOutputFileName( const QString& outputFileName );
QString outputFileName() const;

bool hasError() const;
QString errorString() const;

/**
* @brief Starts network request for data. The prerequisite is that the query string and output
* file name have been set.
*
* Only one request may be pending at one point - if you need more requests at once, use several instances.
*
* @return true if the network request has been issued, false otherwise (and sets error string)
*/
bool start();

/**
* @brief Aborts current pending request
* @return true if there is a pending request and has been aborted, false otherwise
*/
bool abort();

//! Returns true if the request has already finished
bool isFinished() const;

signals:
void finished(); //!< emitted when the network reply has finished (with success or with an error)
void downloadProgress( qint64, qint64 ); //!< normally the total length is not known (until we reach end)

};
53 changes: 53 additions & 0 deletions python/analysis/openstreetmap/qgsosmimport.sip
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@

/**
* @brief The QgsOSMXmlImport class imports OpenStreetMap XML format to our topological representation
* in a SQLite database (see QgsOSMDatabase for details).
*
* How to use the classs:
* 1. set input XML file name and output DB file name (in constructor or with respective functions)
* 2. run import()
* 3. check errorString() if the import failed
*/
class QgsOSMXmlImport : public QObject
{
%TypeHeaderCode
#include <qgsosmimport.h>
%End
public:
explicit QgsOSMXmlImport( const QString& xmlFileName = QString(), const QString& dbFileName = QString() );

void setInputXmlFileName( const QString& xmlFileName );
QString inputXmlFileName() const;

void setOutputDbFileName( const QString& dbFileName );
QString outputDbFileName() const;

/**
* Run import. This will parse the XML file and store the data in a SQLite database.
* @return true on success, false when import failed (see errorString() for the error)
*/
bool import();

bool hasError() const;
QString errorString() const;

signals:
void progress( int percent );

protected:

bool createDatabase();
bool closeDatabase();

//! @note not available in Python bindings
//void deleteStatement( sqlite3_stmt*& stmt );

bool createIndexes();

void readRoot( QXmlStreamReader& xml );
void readNode( QXmlStreamReader& xml );
void readWay( QXmlStreamReader& xml );
void readTag( bool way, qint64 id, QXmlStreamReader& xml );

};

2 changes: 2 additions & 0 deletions python/analysis/raster/qgsrastermatrix.sip
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,6 @@ class QgsRasterMatrix
bool tangens();
bool atangens();
bool changeSign();
bool log();
bool log10();
};
6 changes: 6 additions & 0 deletions python/core/auth/qgsauthmanager.sip
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ class QgsAuthManager : QObject

const QList<QSslCertificate> getCertIdentities();

/** Get list of certificate identity ids from database */
QStringList getCertIdentityIds() const;

bool existsCertIdentity( const QString& id );

bool removeCertIdentity( const QString& id );
Expand Down Expand Up @@ -217,6 +220,9 @@ class QgsAuthManager : QObject

void masterPasswordVerified( bool verified ) const;

/** Emmitted when a user has indicated they may want to erase the authentication db. */
void authDatabaseEraseRequested() const;

void authDatabaseChanged() const;

public slots:
Expand Down
Loading

1 comment on commit 881074b

@NathanW2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow nice work.

Please sign in to comment.