11 mOutputLayer( outputLayer ), mNumberOfPointsAttribute( nPointsAttribute ), mMinDistanceAttribute( minDistAttribute ), mNCreatedPoints( 0 )
15 QgsPointSample::QgsPointSample()
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 ) )
118 f.setAttribute(
"id", mNCreatedPoints + 1 );
119 f.setAttribute(
"station_id", points + 1 );
120 f.setAttribute(
"stratum_id", inputFeature.
id() );
121 f.setGeometry( ptGeom );
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 ) )