11 mOutputLayer( outputLayer ), mNumberOfPointsAttribute( nPointsAttribute ), mMinDistanceAttribute( minDistAttribute ), mNCreatedPoints( 0 )
17 , mNCreatedPoints( 0 )
41 if ( QFile::exists( mOutputLayer ) )
54 &( mInputLayer->
crs() ) );
63 mt_srand( QTime::currentTime().msec() );
66 double minDistance = 0;
70 QStringList() << mNumberOfPointsAttribute << mMinDistanceAttribute, mInputLayer->
pendingFields() ) );
73 nPoints = fet.
attribute( mNumberOfPointsAttribute ).toInt();
74 if ( !mMinDistanceAttribute.isEmpty() )
76 minDistance = fet.
attribute( mMinDistanceAttribute ).toDouble();
78 addSamplePoints( fet, writer, nPoints, minDistance );
99 QMap< QgsFeatureId, QgsPoint > pointMapForFeature;
102 int maxIterations = nPoints * 200;
108 while ( nIterations < maxIterations && points < nPoints )
114 if ( ptGeom->
within( geom ) && checkMinDistance( randPoint, sIndex, minDistance, pointMapForFeature ) )
124 pointMapForFeature.insert( mNCreatedPoints, randPoint );
136 bool QgsPointSample::checkMinDistance(
QgsPoint& pt,
QgsSpatialIndex&
index,
double minDistance, QMap< QgsFeatureId, QgsPoint >& pointMap )
138 if ( minDistance <= 0 )
144 if ( neighborList.isEmpty() )
149 QMap< QgsFeatureId, QgsPoint >::const_iterator it = pointMap.find( neighborList[0] );
150 if ( it == pointMap.constEnd() )
156 if ( neighborPt.
sqrDist( pt ) < ( minDistance * minDistance ) )
QgsFeatureId id() const
Get the feature id for this feature.
Wrapper for iterator of features from vector data provider or vector layer.
A rectangle specified with double values.
bool isEmpty() const
test if rectangle is empty.
int createRandomPoints(QProgressDialog *pd)
Starts calculation of random points.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest())
Query the provider for features specified in request.
QgsGeometry * geometry() const
Get the geometry object associated with this feature.
static bool deleteShapeFile(QString theFileName)
Delete a shapefile (and its accompanying shx / dbf / prf)
Container of fields for a vector layer.
bool setAttribute(int field, const QVariant &attr)
Set an attribute by id.
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...
double sqrDist(double x, double y) const
Returns the squared distance between this point and x,y.
void setGeometry(const QgsGeometry &geom)
Set this feature's geometry from another QgsGeometry object (deep copy)
QgsPointSample(QgsVectorLayer *inputLayer, const QString &outputLayer, QString nPointsAttribute, QString minDistAttribute=QString())
double yMinimum() const
Get the y minimum value (bottom side of rectangle)
This class wraps a request for features to a vector layer (or directly its vector data provider)...
QList< QgsFeatureId > nearestNeighbor(QgsPoint point, int neighbors) const
returns nearest neighbors (their count is specified by second parameter)
void mt_srand(unsigned value)
bool addFeature(QgsFeature &feature, QgsFeatureRendererV2 *renderer=0, QGis::UnitType outputUnit=QGis::Meters)
add feature to the currently opened shapefile
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.
A class to represent a point.
static QgsGeometry * fromPoint(const QgsPoint &point)
construct geometry from a point
QgsRectangle boundingBox()
Returns the bounding box of this feature.
bool insertFeature(const QgsFeature &f)
add feature to index
WriterError hasError()
checks whether there were any errors in constructor
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
bool within(const QgsGeometry *geometry) const
Test for if geometry is within another (uses GEOS)
const QgsCoordinateReferenceSystem & crs() const
Returns layer's spatial reference system.
const QgsFields & pendingFields() const
returns field list in the to-be-committed state
bool nextFeature(QgsFeature &f)
double width() const
Width of the rectangle.
Represents a vector layer which manages a vector based data sets.
double xMinimum() const
Get the x minimum value (left side of rectangle)
double height() const
Height of the rectangle.