Skip to content
Permalink
Browse files

expose mesh spatial index similarly to vector spatial index to API. f…

…ix travis issues and documentation
  • Loading branch information
PeterPetrik committed Jan 24, 2019
1 parent 9d4d1c9 commit 27c670e78d114176fb34bd5bd99e1c72e1b45a57
@@ -0,0 +1,90 @@
/************************************************************************
* This file has been generated automatically from *
* *
* src/core/mesh/qgsmeshspatialindex.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/






class QgsMeshSpatialIndex
{
%Docstring

A spatial index for QgsMeshFace objects.

QgsMeshSpatialIndex objects are implicitly shared and can be inexpensively copied.

.. note::

While the underlying libspatialindex is not thread safe on some platforms, the QgsMeshSpatialIndex
class implements its own locks and accordingly, a single QgsMeshSpatialIndex object can safely
be used across multiple threads

.. seealso:: :py:class:`QgsSpatialIndex`


.. versionadded:: 3.6
%End

%TypeHeaderCode
#include "qgsmeshspatialindex.h"
%End
public:

QgsMeshSpatialIndex();
%Docstring
Constructor for :py:class:`QgsSpatialIndex`. Creates an empty R-tree index.
%End

explicit QgsMeshSpatialIndex( const QgsMesh &triangularMesh, QgsFeedback *feedback = 0 );
%Docstring
Constructor - creates R-tree and bulk loads faces from the specified mesh

The optional ``feedback`` object can be used to allow cancelation of bulk face loading. Ownership
of ``feedback`` is not transferred, and callers must take care that the lifetime of feedback exceeds
that of the spatial index construction.
%End

QgsMeshSpatialIndex( const QgsMeshSpatialIndex &other );
%Docstring
Copy constructor
%End

~QgsMeshSpatialIndex();


QList<int> intersects( const QgsRectangle &rectangle ) const;
%Docstring
Returns a list of face ids with a bounding box which intersects the specified ``rectangle``.

.. note::

The intersection test is performed based on the face bounding boxes only, so it is necessary
to manually test the returned faces for exact geometry intersection when required.
%End

QList<int> nearestNeighbor( const QgsPointXY &point, int neighbors ) const;
%Docstring
Returns nearest neighbors to a ``point``. The number of neighbours returned is specified
by the ``neighbours`` argument.

.. note::

The nearest neighbour test is performed based on the face bounding boxes only,
so this method is not guaranteed to return the actual closest neighbours.
%End

};

/************************************************************************
* This file has been generated automatically from *
* *
* src/core/mesh/qgsmeshspatialindex.h *
* *
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
************************************************************************/
@@ -29,6 +29,8 @@ QgsSpatialIndex objects are implicitly shared and can be inexpensively copied.
be used across multiple threads.

.. seealso:: :py:class:`QgsSpatialIndexKDBush`

.. seealso:: :py:class:`QgsMeshSpatialIndex`
%End

%TypeHeaderCode
@@ -157,7 +159,6 @@ Gets reference count - just for debugging!

};


/************************************************************************
* This file has been generated automatically from *
* *
@@ -239,6 +239,7 @@
%Include auto_generated/raster/qgshillshaderenderer.sip
%Include auto_generated/mesh/qgsmeshlayerinterpolator.sip
%Include auto_generated/mesh/qgsmeshrenderersettings.sip
%Include auto_generated/mesh/qgsmeshspatialindex.sip
%Include auto_generated/scalebar/qgsdoubleboxscalebarrenderer.sip
%Include auto_generated/scalebar/qgsnumericscalebarrenderer.sip
%Include auto_generated/scalebar/qgsscalebarsettings.sip
@@ -13,8 +13,6 @@
* *
***************************************************************************/

///@cond PRIVATE

#include "qgsmeshspatialindex.h"

#include "qgsmeshdataprovider.h"
@@ -195,7 +193,7 @@ class QgsMeshFaceIteratorDataStream : public IDataStream

/**
* \ingroup core
* \class QgsSpatialIndexData
* \class QgsSpatialIndexData
* \brief Data of spatial index that may be implicitly shared
* \note not available in Python bindings
*/
@@ -208,10 +206,10 @@ class QgsMeshSpatialIndexData : public QSharedData
}

/**
* Constructor for QgsSpatialIndexData which bulk loads features from the specified feature iterator
* Constructor for QgsSpatialIndexData which bulk loads faces from the specified mesh
* \a fi.
*
* The optional \a feedback object can be used to allow cancelation of bulk feature loading. Ownership
* The optional \a feedback object can be used to allow cancelation of bulk face loading. Ownership
* of \a feedback is not transferred, and callers must take care that the lifetime of feedback exceeds
* that of the spatial index construction.
*/
@@ -342,5 +340,3 @@ QList<int> QgsMeshSpatialIndex::nearestNeighbor( const QgsPointXY &point, int ne

return list;
}

///@endcond
@@ -16,12 +16,8 @@
#ifndef QGSMESHSPATIALINDEX_H
#define QGSMESHSPATIALINDEX_H

///@cond PRIVATE

#include "qgis_sip.h"

#define SIP_NO_FILE

class QgsRectangle;
class QgsPointXY;
class QgsFeedback;
@@ -45,13 +41,12 @@ class QgsMeshSpatialIndexData;
* class implements its own locks and accordingly, a single QgsMeshSpatialIndex object can safely
* be used across multiple threads
*
* \see QgsSpatialIndex
* \see QgsSpatialIndex, which is for vector features
*
* \since QGIS 3.6
*/
class CORE_NO_EXPORT QgsMeshSpatialIndex
class CORE_EXPORT QgsMeshSpatialIndex
{

public:

/**
@@ -60,9 +55,9 @@ class CORE_NO_EXPORT QgsMeshSpatialIndex
QgsMeshSpatialIndex();

/**
* Constructor - creates R-tree and bulk loads it with features from the iterator.
* Constructor - creates R-tree and bulk loads faces from the specified mesh
*
* The optional \a feedback object can be used to allow cancelation of bulk feature loading. Ownership
* The optional \a feedback object can be used to allow cancelation of bulk face loading. Ownership
* of \a feedback is not transferred, and callers must take care that the lifetime of feedback exceeds
* that of the spatial index construction.
*/
@@ -80,25 +75,22 @@ class CORE_NO_EXPORT QgsMeshSpatialIndex
/**
* Returns a list of face ids with a bounding box which intersects the specified \a rectangle.
*
* \note The intersection test is performed based on the feature bounding boxes only, so for non-point
* geometry features it is necessary to manually test the returned features for exact geometry intersection
* when required.
* \note The intersection test is performed based on the face bounding boxes only, so it is necessary
* to manually test the returned faces for exact geometry intersection when required.
*/
QList<int> intersects( const QgsRectangle &rectangle ) const;

/**
* Returns nearest neighbors to a \a point. The number of neighbours returned is specified
* by the \a neighbours argument.
*
* \note The nearest neighbour test is performed based on the feature bounding boxes only, so for non-point
* geometry features this method is not guaranteed to return the actual closest neighbours.
* \note The nearest neighbour test is performed based on the face bounding boxes only,
* so this method is not guaranteed to return the actual closest neighbours.
*/
QList<int> nearestNeighbor( const QgsPointXY &point, int neighbors ) const;

private:
QSharedDataPointer<QgsMeshSpatialIndexData> d;
};

///@endcond

#endif //QGSMESHSPATIALINDEX_H
@@ -22,47 +22,10 @@
#include "qgstriangularmesh.h"
#include "qgsrendercontext.h"
#include "qgscoordinatetransform.h"
#include "qgsfeatureid.h"
#include "qgsgeometry.h"
#include "qgsrectangle.h"
#include "qgsfeatureiterator.h"
#include "qgslogger.h"

///@cond PRIVATE

QgsMeshFeatureIterator::QgsMeshFeatureIterator( QgsMesh *mesh )
: QgsAbstractFeatureIterator( QgsFeatureRequest() )
, mMesh( mesh )
{}

QgsMeshFeatureIterator::~QgsMeshFeatureIterator() = default;

bool QgsMeshFeatureIterator::rewind()
{
it = 0;
return true;
}
bool QgsMeshFeatureIterator::close()
{
mMesh = nullptr;
return true;
}

bool QgsMeshFeatureIterator::fetchFeature( QgsFeature &f )
{
if ( !mMesh || mMesh->faces.size() <= it )
return false;

const QgsMeshFace &face = mMesh->faces.at( it ) ;
QgsGeometry geom = QgsMeshUtils::toGeometry( face, mMesh->vertices );
f.setGeometry( geom );
f.setId( it );
++it;
return true;
}


///@endcond
#include "qgsmeshspatialindex.h"

static void ENP_centroid_step( const QPolygonF &pX, double &cx, double &cy, double &signedArea, int i, int i1 )
{
@@ -108,6 +71,7 @@ static void ENP_centroid( const QPolygonF &pX, double &cx, double &cy )
cy /= ( 6.0 * signedArea );
}


void QgsTriangularMesh::triangulate( const QgsMeshFace &face, int nativeIndex )
{
int vertexCount = face.size();
@@ -128,6 +92,9 @@ void QgsTriangularMesh::triangulate( const QgsMeshFace &face, int nativeIndex )
mTrianglesToNativeFaces.push_back( nativeIndex );
}

QgsTriangularMesh::~QgsTriangularMesh() = default;
QgsTriangularMesh::QgsTriangularMesh() = default;

void QgsTriangularMesh::update( QgsMesh *nativeMesh, QgsRenderContext *context )
{
Q_ASSERT( nativeMesh );
@@ -26,44 +26,12 @@
#include "qgis_core.h"
#include "qgsmeshdataprovider.h"
#include "qgsgeometry.h"
#include "qgsfeatureid.h"
#include "qgsmeshspatialindex.h"
#include "qgsfeatureiterator.h"

class QgsRenderContext;
class QgsCoordinateTransform;
class QgsRectangle;

///@cond PRIVATE

/**
* Delivers mesh faces as features
*/
class CORE_NO_EXPORT QgsMeshFeatureIterator : public QgsAbstractFeatureIterator
{
public:

/**
* This constructor creates a feature iterator, that delivers all features
*
* \param mesh The mesh to use
*/
QgsMeshFeatureIterator( QgsMesh *mesh );
~QgsMeshFeatureIterator() override;

bool rewind() override;
bool close() override;

protected:
bool fetchFeature( QgsFeature &f ) override;

private:
QgsMesh *mMesh = nullptr;
int it = 0;
};

///@endcond

/**
* \ingroup core
*
@@ -79,9 +47,9 @@ class CORE_EXPORT QgsTriangularMesh
{
public:
//! Ctor
QgsTriangularMesh() = default;
QgsTriangularMesh();
//! Dtor
~QgsTriangularMesh() = default;
~QgsTriangularMesh();

/**
* Constructs triangular mesh from layer's native mesh and context. Populates spatial index.
@@ -63,6 +63,7 @@ class QgsFeatureSource;
* be used across multiple threads.
*
* \see QgsSpatialIndexKDBush, which is an optimised non-mutable index for point geometries only.
* \see QgsMeshSpatialIndex, which is for mesh faces
*/
class CORE_EXPORT QgsSpatialIndex : public QgsFeatureSink
{
@@ -214,5 +215,4 @@ class CORE_EXPORT QgsSpatialIndex : public QgsFeatureSink

};

#endif

#endif //QGSSPATIALINDEX_H

0 comments on commit 27c670e

Please sign in to comment.
You can’t perform that action at this time.