25 mOutputLayer( outputLayer ), mNumberOfPointsAttribute( nPointsAttribute ), mMinDistanceAttribute( minDistAttribute ), mNCreatedPoints( 0 )
30 : mInputLayer(
nullptr )
31 , mNCreatedPoints( 0 )
64 &( mInputLayer->
crs() ) );
76 double minDistance = 0;
80 QStringList() << mNumberOfPointsAttribute << mMinDistanceAttribute, mInputLayer->
fields() ) );
84 if ( !mMinDistanceAttribute.
isEmpty() )
88 addSamplePoints( fet, writer, outputFields, nPoints, minDistance );
110 int maxIterations = nPoints * 200;
116 while ( nIterations < maxIterations && points < nPoints )
122 if ( ptGeom->
within( geom ) && checkMinDistance( randPoint, sIndex, minDistance, pointMapForFeature ) )
125 QgsFeature f( outputFields, mNCreatedPoints );
132 pointMapForFeature.
insert( mNCreatedPoints, randPoint );
146 if ( minDistance <= 0 )
164 if ( neighborPt.
sqrDist( pt ) < ( minDistance * minDistance ) )
Wrapper for iterator of features from vector data provider or vector layer.
A rectangle specified with double values.
int createRandomPoints(QProgressDialog *pd)
Starts calculation of random points.
static bool deleteShapeFile(const QString &theFileName)
Delete a shapefile (and its accompanying shx / dbf / prf)
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest())
Query the provider for features specified in request.
const QgsCoordinateReferenceSystem & crs() const
Returns layer's spatial reference system.
QList< QgsFeatureId > nearestNeighbor(const QgsPoint &point, int neighbors) const
Returns nearest neighbors (their count is specified by second parameter)
Container of fields for a vector layer.
A geometry is the spatial representation of a feature.
bool setAttribute(int field, const QVariant &attr)
Set an attribute's value by field index.
bool addFeature(QgsFeature &feature, QgsFeatureRendererV2 *renderer=nullptr, QGis::UnitType outputUnit=QGis::Meters)
Add feature to the currently opened data source.
const QgsGeometry * constGeometry() const
Gets a const pointer to the geometry object associated with this feature.
A convenience class for writing vector files to disk.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
QgsFields fields() const
Returns the list of fields of this layer.
void setGeometry(const QgsGeometry &geom)
Set this feature's geometry from another QgsGeometry object.
int toInt(bool *ok) const
bool isEmpty() const
test if rectangle is empty.
double width() const
Width of the rectangle.
const_iterator constEnd() const
This class wraps a request for features to a vector layer (or directly its vector data provider)...
void mt_srand(unsigned value)
bool append(const QgsField &field, FieldOrigin origin=OriginProvider, int originIndex=-1)
Append a field. The field must have unique name, otherwise it is rejected (returns false) ...
QGis::GeometryType geometryType() const
Returns point, line or polygon.
Encapsulate a field in an attribute table or data source.
bool within(const QgsGeometry *geometry) const
Test for if geometry is within another (uses GEOS)
A class to represent a point.
static QgsGeometry * fromPoint(const QgsPoint &point)
Creates a new geometry from a QgsPoint object.
QgsFeatureId id() const
Get the feature ID for this feature.
double yMinimum() const
Get the y minimum value (bottom side of rectangle)
bool insertFeature(const QgsFeature &f)
Add feature to index.
WriterError hasError()
Checks whether there were any errors in constructor.
QgsRectangle boundingBox() const
Returns the bounding box of this feature.
double xMinimum() const
Get the x minimum value (left side of rectangle)
double toDouble(bool *ok) const
double sqrDist(double x, double y) const
Returns the squared distance between this point a specified x, y coordinate.
iterator insert(const Key &key, const T &value)
bool nextFeature(QgsFeature &f)
QgsPointSample(QgsVectorLayer *inputLayer, const QString &outputLayer, const QString &nPointsAttribute, const QString &minDistAttribute=QString())
Represents a vector layer which manages a vector based data sets.
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
iterator find(const Key &key)
double height() const
Height of the rectangle.