@@ -126,21 +126,21 @@ void Heatmap::createRaster( QgsVectorLayer* theVectorLayer, int theBuffer, float
126126
127127 GDALDataset *emptyDataset;
128128 GDALDriver *myDriver;
129-
129+
130130 myDriver = GetGDALDriverManager ()->GetDriverByName ( theOutputFormat.toUtf8 () );
131- if ( myDriver == NULL )
131+ if ( myDriver == NULL )
132132 {
133- QMessageBox::information ( 0 , tr (" Error in GDAL Driver!" ), tr (" Cannot open the driver for the format specified" ) );
133+ QMessageBox::information ( 0 , tr ( " Error in GDAL Driver!" ), tr ( " Cannot open the driver for the format specified" ) );
134134 return ;
135135 }
136136
137137 // bounding box info
138138 QgsRectangle myBBox = theVectorLayer->extent ();
139139 // fixing a base width of 500 px/cells
140140 xSize = 500 ;
141- xResolution = myBBox.width ()/ xSize;
141+ xResolution = myBBox.width () / xSize;
142142 yResolution = xResolution;
143- ySize = myBBox.height ()/ yResolution;
143+ ySize = myBBox.height () / yResolution;
144144 // add extra extend to cover the corner points' heat region
145145 xSize = xSize + ( theBuffer * 2 ) + 10 ;
146146 ySize = ySize + ( theBuffer * 2 ) + 10 ;
@@ -155,7 +155,7 @@ void Heatmap::createRaster( QgsVectorLayer* theVectorLayer, int theBuffer, float
155155 emptyDataset->SetGeoTransform ( geoTransform );
156156
157157 GDALRasterBand *poBand;
158- poBand = emptyDataset->GetRasterBand (1 );
158+ poBand = emptyDataset->GetRasterBand ( 1 );
159159 poBand->SetNoDataValue ( NO_DATA );
160160
161161 float * line = ( float * ) CPLMalloc ( sizeof ( float ) * xSize );
@@ -168,44 +168,44 @@ void Heatmap::createRaster( QgsVectorLayer* theVectorLayer, int theBuffer, float
168168
169169 CPLFree ( line );
170170 // close the dataset
171- GDALClose ( ( GDALDatasetH) emptyDataset );
171+ GDALClose (( GDALDatasetH ) emptyDataset );
172172
173173 // open the raster in GA_Update mode
174174 GDALDataset *heatmapDS;
175175 heatmapDS = ( GDALDataset * ) GDALOpen ( theOutputFilename.toUtf8 (), GA_Update );
176- if ( !heatmapDS )
176+ if ( !heatmapDS )
177177 {
178- QMessageBox::information ( 0 , tr (" Error in Updating Raster!" ), tr (" Couldnot open the created raster for updation. The Heatmap was not generated." ) );
178+ QMessageBox::information ( 0 , tr ( " Error in Updating Raster!" ), tr ( " Couldnot open the created raster for updation. The Heatmap was not generated." ) );
179179 return ;
180180 }
181181 poBand = heatmapDS->GetRasterBand ( 1 );
182182 // Get the data buffer ready
183183 int blockSize = 2 * theBuffer + 1 ; // block SIDE would have been more appropriate
184184 // Open the vector features
185185 QgsVectorDataProvider* myVectorProvider = theVectorLayer->dataProvider ();
186- if ( !myVectorProvider )
186+ if ( !myVectorProvider )
187187 {
188- QMessageBox::information ( 0 , tr ( " Error in Point Layer!" ), tr (" Couldnot identify the vector data provider." ) );
188+ QMessageBox::information ( 0 , tr ( " Error in Point Layer!" ), tr ( " Couldnot identify the vector data provider." ) );
189189 return ;
190190 }
191191 QgsAttributeList dummyList;
192192 myVectorProvider->select ( dummyList );
193-
193+
194194 int totalFeatures = myVectorProvider->featureCount ();
195195 int counter = 0 ;
196196
197197 QProgressDialog p ( " Creating Heatmap ... " , " Abort" , 0 , totalFeatures );
198- p.setWindowModality (Qt::WindowModal);
198+ p.setWindowModality ( Qt::WindowModal );
199199
200200 QgsFeature myFeature;
201201
202- while ( myVectorProvider->nextFeature ( myFeature ) )
202+ while ( myVectorProvider->nextFeature ( myFeature ) )
203203 {
204204 counter += 1 ;
205205 p.setValue ( counter );
206- if ( p.wasCanceled () )
206+ if ( p.wasCanceled () )
207207 {
208- QMessageBox::information ( 0 , tr (" Heatmap Generation Aborted!" ), tr (" QGIS will now load the partially-computed raster." ) );
208+ QMessageBox::information ( 0 , tr ( " Heatmap Generation Aborted!" ), tr ( " QGIS will now load the partially-computed raster." ) );
209209 break ;
210210 }
211211
@@ -215,46 +215,46 @@ void Heatmap::createRaster( QgsVectorLayer* theVectorLayer, int theBuffer, float
215215 QgsPoint myPoint;
216216 myPoint = myPointGeometry->asPoint ();
217217 // avoiding any empty points or out of extent points
218- if ( ( myPoint.x () < rasterX ) || ( myPoint.y () < rasterY ) )
218+ if ( ( myPoint.x () < rasterX ) || ( myPoint.y () < rasterY ) )
219219 {
220220 continue ;
221221 }
222- // calculate the pixel position
222+ // calculate the pixel position
223223 unsigned int xPosition, yPosition;
224- xPosition = (( myPoint.x () - rasterX )/ xResolution ) - theBuffer;
225- yPosition = (( myPoint.y () - rasterY )/ yResolution ) - theBuffer;
224+ xPosition = (( myPoint.x () - rasterX ) / xResolution ) - theBuffer;
225+ yPosition = (( myPoint.y () - rasterY ) / yResolution ) - theBuffer;
226226
227227 // get the data
228228 float *dataBuffer = ( float * ) CPLMalloc ( sizeof ( float ) * blockSize * blockSize );
229229 poBand->RasterIO ( GF_Read, xPosition, yPosition, blockSize, blockSize, dataBuffer, blockSize, blockSize, GDT_Float32, 0 , 0 );
230230
231- for ( int xp = 0 ; xp <= theBuffer; xp += 1 )
231+ for ( int xp = 0 ; xp <= theBuffer; xp += 1 )
232232 {
233- for ( int yp = 0 ; yp <= theBuffer; yp += 1 )
233+ for ( int yp = 0 ; yp <= theBuffer; yp += 1 )
234234 {
235235 float distance = sqrt ( pow ( xp, 2 ) + pow ( yp, 2 ) );
236- float pixelValue = 1 - ( ( 1 - theDecay) * distance / theBuffer );
236+ float pixelValue = 1 - (( 1 - theDecay ) * distance / theBuffer );
237237
238238 // clearing anamolies along the axes
239- if ( xp == 0 && yp == 0 )
239+ if ( xp == 0 && yp == 0 )
240240 {
241241 pixelValue /= 4 ;
242242 }
243- else if ( xp == 0 || yp == 0 )
243+ else if ( xp == 0 || yp == 0 )
244244 {
245245 pixelValue /= 2 ;
246246 }
247247
248- if ( distance <= theBuffer )
248+ if ( distance <= theBuffer )
249249 {
250250 int pos[4 ];
251251 pos[0 ] = ( theBuffer + xp ) * blockSize + ( theBuffer + yp );
252252 pos[1 ] = ( theBuffer + xp ) * blockSize + ( theBuffer - yp );
253253 pos[2 ] = ( theBuffer - xp ) * blockSize + ( theBuffer + yp );
254254 pos[3 ] = ( theBuffer - xp ) * blockSize + ( theBuffer - yp );
255- for ( int p = 0 ; p < 4 ; p += 1 )
255+ for ( int p = 0 ; p < 4 ; p += 1 )
256256 {
257- if ( dataBuffer[ pos[p] ] == NO_DATA )
257+ if ( dataBuffer[ pos[p] ] == NO_DATA )
258258 {
259259 dataBuffer[ pos[p] ] = 0 ;
260260 }
@@ -269,7 +269,7 @@ void Heatmap::createRaster( QgsVectorLayer* theVectorLayer, int theBuffer, float
269269 }
270270
271271 // Finally close the dataset
272- GDALClose ( ( GDALDatasetH) heatmapDS );
272+ GDALClose (( GDALDatasetH ) heatmapDS );
273273
274274 // Open the file in QGIS window
275275 mQGisIface ->addRasterLayer ( theOutputFilename, QFileInfo ( theOutputFilename ).baseName () );
0 commit comments