Skip to content

Commit

Permalink
sipify OSM classes
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustry authored and 3nids committed Jun 1, 2017
1 parent 6c7a12a commit b17b36e
Show file tree
Hide file tree
Showing 6 changed files with 265 additions and 94 deletions.
112 changes: 77 additions & 35 deletions python/analysis/openstreetmap/qgsosmbase.sip
@@ -1,105 +1,147 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/analysis/openstreetmap/qgsosmbase.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/




typedef qint64 QgsOSMId;


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

Type type;
qint64 id;
QgsOSMId id;
};


/**
class QgsOSMElement
{
%Docstring
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
{
%End

%TypeHeaderCode
#include <qgsosmbase.h>
#include "qgsosmbase.h"
%End

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

bool isValid() const;
%Docstring
:rtype: bool
%End

// fetched automatically from DB
QgsOSMElementID elemId() const;
qint64 id() const;
//QString username() const;
//QDateTime timestamp() const;
//int version() const;
%Docstring
:rtype: QgsOSMElementID
%End
QgsOSMId id() const;
%Docstring
:rtype: QgsOSMId
%End

};



/**
class QgsOSMNode : QgsOSMElement
{
%Docstring
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
{
%End

%TypeHeaderCode
#include <qgsosmbase.h>
#include "qgsosmbase.h"
%End
public:
QgsOSMNode();
QgsOSMNode( qint64 id, const QgsPoint &point );
QgsOSMNode( QgsOSMId id, const QgsPoint &point );

QgsPoint point() const;
%Docstring
:rtype: QgsPoint
%End

};


/**
class QgsOSMWay : QgsOSMElement
{
%Docstring
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
{
%End

%TypeHeaderCode
#include <qgsosmbase.h>
#include "qgsosmbase.h"
%End
public:
QgsOSMWay();
QgsOSMWay( qint64 id, const QList<qint64> &nodes );
QgsOSMWay( QgsOSMId id, const QList<QgsOSMId> &nodes );

QList<qint64> nodes() const;
QList<QgsOSMId> nodes() const;
%Docstring
:rtype: list of QgsOSMId
%End

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

};

/**
* This class is a container of tags for a node, way or a relation.
*/


class QgsOSMTags
{
%Docstring
This class is a container of tags for a node, way or a relation.
%End

%TypeHeaderCode
#include <qgsosmbase.h>
#include "qgsosmbase.h"
%End
public:
QgsOSMTags();

int count() const;
%Docstring
:rtype: int
%End
QList<QString> keys() const;
%Docstring
:rtype: list of str
%End
bool contains( const QString &k ) const;
%Docstring
:rtype: bool
%End
void insert( const QString &k, const QString &v );
QString value( const QString &k ) const;
%Docstring
:rtype: str
%End

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/analysis/openstreetmap/qgsosmbase.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
143 changes: 108 additions & 35 deletions python/analysis/openstreetmap/qgsosmdatabase.sip
@@ -1,85 +1,158 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/analysis/openstreetmap/qgsosmdatabase.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/






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
{
%Docstring
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.
%End

%TypeHeaderCode
#include <qgsosmdatabase.h>
#include "qgsosmdatabase.h"
%End
public:
explicit QgsOSMDatabase( const QString &dbFileName = QString() );
~QgsOSMDatabase();


void setFileName( const QString &dbFileName );
%Docstring
Setter for the spatialite database.
%End
QString filename() const;
%Docstring
:rtype: str
%End
bool isOpen() const;
%Docstring
:rtype: bool
%End

bool open();
%Docstring
:rtype: bool
%End
bool close();
%Docstring
:rtype: bool
%End

QString errorString() const;
%Docstring
:rtype: str
%End

// data access

int countNodes() const;
%Docstring
:rtype: int
%End
int countWays() const;
%Docstring
:rtype: int
%End


//! @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;
QgsOSMNode node( QgsOSMId id ) const;
%Docstring
:rtype: QgsOSMNode
%End
QgsOSMWay way( QgsOSMId id ) const;
%Docstring
:rtype: QgsOSMWay
%End

QgsOSMTags tags( bool way, qint64 id ) const;
QgsOSMTags tags( bool way, QgsOSMId id ) const;
%Docstring
:rtype: QgsOSMTags
%End

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

QgsPolyline wayPoints( qint64 id ) const;
QgsPolyline wayPoints( QgsOSMId id ) const;
%Docstring
:rtype: QgsPolyline
%End

// export to spatialite

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

protected:
bool prepareStatements();
%Docstring
:rtype: bool
%End
int runCountStatement( const char *sql ) const;
%Docstring
:rtype: int
%End

/** @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 );
%Docstring
:rtype: bool
%End
bool createSpatialIndex( const QString &tableName );
%Docstring
:rtype: bool
%End

QString quotedIdentifier( QString id );
%Docstring
:rtype: str
%End
QString quotedValue( QString value );
%Docstring
:rtype: str
%End

private:

QgsOSMDatabase( const QgsOSMDatabase &rh );
};








/************************************************************************
* This file has been generated automatically from *
* *
* src/analysis/openstreetmap/qgsosmdatabase.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/

0 comments on commit b17b36e

Please sign in to comment.