Skip to content

Commit

Permalink
indentation update
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed Feb 8, 2012
1 parent 289e5a6 commit 30e2f32
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 56 deletions.
2 changes: 1 addition & 1 deletion src/core/qgsapplication.cpp
Expand Up @@ -73,7 +73,7 @@ QgsApplication::QgsApplication( int & argc, char ** argv, bool GUIenabled, QStri
}
void QgsApplication::init( QString customConfigPath )
{
if( customConfigPath.isEmpty() )
if ( customConfigPath.isEmpty() )
{
customConfigPath = QDir::homePath() + QString( "/.qgis/" );
}
Expand Down
58 changes: 29 additions & 29 deletions src/plugins/heatmap/heatmap.cpp
Expand Up @@ -126,21 +126,21 @@ void Heatmap::createRaster( QgsVectorLayer* theVectorLayer, int theBuffer, float

GDALDataset *emptyDataset;
GDALDriver *myDriver;

myDriver = GetGDALDriverManager()->GetDriverByName( theOutputFormat.toUtf8() );
if( myDriver == NULL )
if ( myDriver == NULL )
{
QMessageBox::information( 0, tr("Error in GDAL Driver!"), tr("Cannot open the driver for the format specified") );
QMessageBox::information( 0, tr( "Error in GDAL Driver!" ), tr( "Cannot open the driver for the format specified" ) );
return;
}

// bounding box info
QgsRectangle myBBox = theVectorLayer->extent();
// fixing a base width of 500 px/cells
xSize = 500;
xResolution = myBBox.width()/xSize;
xResolution = myBBox.width() / xSize;
yResolution = xResolution;
ySize = myBBox.height()/yResolution;
ySize = myBBox.height() / yResolution;
// add extra extend to cover the corner points' heat region
xSize = xSize + ( theBuffer * 2 ) + 10 ;
ySize = ySize + ( theBuffer * 2 ) + 10 ;
Expand All @@ -155,7 +155,7 @@ void Heatmap::createRaster( QgsVectorLayer* theVectorLayer, int theBuffer, float
emptyDataset->SetGeoTransform( geoTransform );

GDALRasterBand *poBand;
poBand = emptyDataset->GetRasterBand(1);
poBand = emptyDataset->GetRasterBand( 1 );
poBand->SetNoDataValue( NO_DATA );

float* line = ( float * ) CPLMalloc( sizeof( float ) * xSize );
Expand All @@ -168,44 +168,44 @@ void Heatmap::createRaster( QgsVectorLayer* theVectorLayer, int theBuffer, float

CPLFree( line );
//close the dataset
GDALClose( (GDALDatasetH) emptyDataset );
GDALClose(( GDALDatasetH ) emptyDataset );

// open the raster in GA_Update mode
GDALDataset *heatmapDS;
heatmapDS = ( GDALDataset * ) GDALOpen( theOutputFilename.toUtf8(), GA_Update );
if( !heatmapDS )
if ( !heatmapDS )
{
QMessageBox::information( 0, tr("Error in Updating Raster!"), tr("Couldnot open the created raster for updation. The Heatmap was not generated.") );
QMessageBox::information( 0, tr( "Error in Updating Raster!" ), tr( "Couldnot open the created raster for updation. The Heatmap was not generated." ) );
return;
}
poBand = heatmapDS->GetRasterBand( 1 );
// Get the data buffer ready
int blockSize = 2 * theBuffer + 1; // block SIDE would have been more appropriate
// Open the vector features
QgsVectorDataProvider* myVectorProvider = theVectorLayer->dataProvider();
if( !myVectorProvider )
if ( !myVectorProvider )
{
QMessageBox::information( 0, tr( "Error in Point Layer!"), tr("Couldnot identify the vector data provider.") );
QMessageBox::information( 0, tr( "Error in Point Layer!" ), tr( "Couldnot identify the vector data provider." ) );
return;
}
QgsAttributeList dummyList;
myVectorProvider->select( dummyList );

int totalFeatures = myVectorProvider->featureCount();
int counter = 0;

QProgressDialog p( "Creating Heatmap ... ", "Abort", 0, totalFeatures );
p.setWindowModality(Qt::WindowModal);
p.setWindowModality( Qt::WindowModal );

QgsFeature myFeature;

while( myVectorProvider->nextFeature( myFeature ) )
while ( myVectorProvider->nextFeature( myFeature ) )
{
counter += 1;
p.setValue( counter );
if( p.wasCanceled() )
if ( p.wasCanceled() )
{
QMessageBox::information( 0, tr("Heatmap Generation Aborted!"), tr("QGIS will now load the partially-computed raster.") );
QMessageBox::information( 0, tr( "Heatmap Generation Aborted!" ), tr( "QGIS will now load the partially-computed raster." ) );
break;
}

Expand All @@ -215,46 +215,46 @@ void Heatmap::createRaster( QgsVectorLayer* theVectorLayer, int theBuffer, float
QgsPoint myPoint;
myPoint = myPointGeometry->asPoint();
// avoiding any empty points or out of extent points
if( ( myPoint.x() < rasterX ) || ( myPoint.y() < rasterY ) )
if (( myPoint.x() < rasterX ) || ( myPoint.y() < rasterY ) )
{
continue;
}
// calculate the pixel position
// calculate the pixel position
unsigned int xPosition, yPosition;
xPosition = (( myPoint.x() - rasterX )/ xResolution ) - theBuffer;
yPosition = (( myPoint.y() - rasterY )/ yResolution ) - theBuffer;
xPosition = (( myPoint.x() - rasterX ) / xResolution ) - theBuffer;
yPosition = (( myPoint.y() - rasterY ) / yResolution ) - theBuffer;

// get the data
float *dataBuffer = ( float * ) CPLMalloc( sizeof( float ) * blockSize * blockSize );
poBand->RasterIO( GF_Read, xPosition, yPosition, blockSize, blockSize, dataBuffer, blockSize, blockSize, GDT_Float32, 0, 0 );

for( int xp = 0; xp <= theBuffer; xp += 1 )
for ( int xp = 0; xp <= theBuffer; xp += 1 )
{
for( int yp = 0; yp <= theBuffer; yp += 1 )
for ( int yp = 0; yp <= theBuffer; yp += 1 )
{
float distance = sqrt( pow( xp, 2 ) + pow( yp, 2 ) );
float pixelValue = 1 - ( (1-theDecay) * distance / theBuffer );
float pixelValue = 1 - (( 1 - theDecay ) * distance / theBuffer );

// clearing anamolies along the axes
if( xp == 0 && yp == 0 )
if ( xp == 0 && yp == 0 )
{
pixelValue /= 4;
}
else if( xp == 0 || yp == 0 )
else if ( xp == 0 || yp == 0 )
{
pixelValue /= 2;
}

if( distance <= theBuffer )
if ( distance <= theBuffer )
{
int pos[4];
pos[0] = ( theBuffer + xp ) * blockSize + ( theBuffer + yp );
pos[1] = ( theBuffer + xp ) * blockSize + ( theBuffer - yp );
pos[2] = ( theBuffer - xp ) * blockSize + ( theBuffer + yp );
pos[3] = ( theBuffer - xp ) * blockSize + ( theBuffer - yp );
for( int p = 0; p < 4; p += 1 )
for ( int p = 0; p < 4; p += 1 )
{
if( dataBuffer[ pos[p] ] == NO_DATA )
if ( dataBuffer[ pos[p] ] == NO_DATA )
{
dataBuffer[ pos[p] ] = 0;
}
Expand All @@ -269,7 +269,7 @@ void Heatmap::createRaster( QgsVectorLayer* theVectorLayer, int theBuffer, float
}

//Finally close the dataset
GDALClose( (GDALDatasetH) heatmapDS );
GDALClose(( GDALDatasetH ) heatmapDS );

// Open the file in QGIS window
mQGisIface->addRasterLayer( theOutputFilename, QFileInfo( theOutputFilename ).baseName() );
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/heatmap/heatmap.h
Expand Up @@ -81,7 +81,7 @@ class Heatmap: public QObject, public QgisPlugin
//! the worker slot to create heatmap
/*
* Signal: createRaster
* Params:
* Params:
* QgsVectorLayer* -> Input point layer
* int -> Buffer distance
* float -> Decay ratio
Expand Down
48 changes: 24 additions & 24 deletions src/plugins/heatmap/heatmapgui.cpp
Expand Up @@ -37,13 +37,13 @@ HeatmapGui::HeatmapGui( QWidget* parent, Qt::WFlags fl )

// Adding point layers to the mInputVectorCombo
QMap<QString, QgsMapLayer*> mapLayers = QgsMapLayerRegistry::instance()->mapLayers();
QMapIterator<QString, QgsMapLayer*> layers(mapLayers);
QMapIterator<QString, QgsMapLayer*> layers( mapLayers );

while( layers.hasNext() )
while ( layers.hasNext() )
{
layers.next();
QgsVectorLayer* vl = qobject_cast<QgsVectorLayer *>(layers.value());
if( ( vl ) && ( vl->geometryType() == QGis::Point ) )
QgsVectorLayer* vl = qobject_cast<QgsVectorLayer *>( layers.value() );
if (( vl ) && ( vl->geometryType() == QGis::Point ) )
{
mInputVectorCombo->addItem( vl->name(), QVariant( vl->id() ) );
}
Expand All @@ -54,11 +54,11 @@ HeatmapGui::HeatmapGui( QWidget* parent, Qt::WFlags fl )
int myIndex = -1;
GDALAllRegister();
int nDrivers = GDALGetDriverCount();
for( int i = 0; i < nDrivers; i +=1 )
for ( int i = 0; i < nDrivers; i += 1 )
{
GDALDriver* nthDriver = GetGDALDriverManager()->GetDriver( i );
char** driverMetadata = nthDriver->GetMetadata();
if( CSLFetchBoolean( driverMetadata, GDAL_DCAP_CREATE, false ) )
if ( CSLFetchBoolean( driverMetadata, GDAL_DCAP_CREATE, false ) )
{
++myIndex;
QString myLongName = nthDriver->GetMetadataItem( GDAL_DMD_LONGNAME );
Expand All @@ -72,7 +72,7 @@ HeatmapGui::HeatmapGui( QWidget* parent, Qt::WFlags fl )
}
}
}
mFormatCombo->setCurrentIndex(myTiffIndex);
mFormatCombo->setCurrentIndex( myTiffIndex );

//finally set right the ok button
enableOrDisableOkButton();
Expand All @@ -97,16 +97,16 @@ void HeatmapGui::on_mButtonBox_accepted()
int myLayerId = mInputVectorCombo->itemData( mInputVectorCombo->currentIndex() ).toInt();

QMap<QString, QgsMapLayer*> mapLayers = QgsMapLayerRegistry::instance()->mapLayers();
QMapIterator<QString, QgsMapLayer*> layers(mapLayers);
while( layers.hasNext() )
QMapIterator<QString, QgsMapLayer*> layers( mapLayers );

while ( layers.hasNext() )
{
layers.next();
QgsVectorLayer* vl = qobject_cast<QgsVectorLayer *>(layers.value());
QgsVectorLayer* vl = qobject_cast<QgsVectorLayer *>( layers.value() );
if ( vl )
{
dummyText = vl->id();
if( dummyText.toInt() == myLayerId )
if ( dummyText.toInt() == myLayerId )
{
inputLayer = vl;
}
Expand All @@ -116,9 +116,9 @@ void HeatmapGui::on_mButtonBox_accepted()
// The buffer distance
dummyText = mBufferLineEdit->text();
bufferDistance = dummyText.toInt();
if( bufferDistance == NULL )
if ( bufferDistance == NULL )
{
QMessageBox::information( 0, tr("Invalid Buffer Value!"), tr("Buffer distance cannot be NULL, kindly enter a valid value.") );
QMessageBox::information( 0, tr( "Invalid Buffer Value!" ), tr( "Buffer distance cannot be NULL, kindly enter a valid value." ) );
return;
}
// The decay ratio
Expand All @@ -128,9 +128,9 @@ void HeatmapGui::on_mButtonBox_accepted()
// The output filename
outputFileName = mOutputRasterLineEdit->text();
QFileInfo myFileInfo( outputFileName );
if( outputFileName.isEmpty() || !myFileInfo.dir().exists() )
if ( outputFileName.isEmpty() || !myFileInfo.dir().exists() )
{
QMessageBox::information( 0, tr("Output filename is invalid!"), tr("Kindly enter a valid output file path and name.") );
QMessageBox::information( 0, tr( "Output filename is invalid!" ), tr( "Kindly enter a valid output file path and name." ) );
return;
}

Expand All @@ -139,16 +139,16 @@ void HeatmapGui::on_mButtonBox_accepted()

// append the file format if the suffix is empty
QString suffix = myFileInfo.suffix();
if( suffix.isEmpty() )
if ( suffix.isEmpty() )
{
QMap<QString, QString>::const_iterator it = mExtensionMap.find( outputFormat );
if( it != mExtensionMap.end() && it.key() == outputFormat )
if ( it != mExtensionMap.end() && it.key() == outputFormat )
{
// making sure that there is really a extension value available
// Some drivers donot seem to have any extension at all
if( it.value() != NULL || it.value() != "" )
if ( it.value() != NULL || it.value() != "" )
{
outputFileName.append(".");
outputFileName.append( "." );
outputFileName.append( it.value() );
}
}
Expand All @@ -174,13 +174,13 @@ void HeatmapGui::on_mBrowseButton_clicked()
QSettings s;
QString lastDir = s.value( "/Heatmap/lastOutputDir", "" ).toString();

QString outputFilename = QFileDialog::getSaveFileName( 0, tr( "Save Heatmap as: "), lastDir );
if( !outputFilename.isEmpty() )
QString outputFilename = QFileDialog::getSaveFileName( 0, tr( "Save Heatmap as: " ), lastDir );
if ( !outputFilename.isEmpty() )
{
mOutputRasterLineEdit->setText( outputFilename );
QFileInfo outputFileInfo( outputFilename );
QDir outputDir = outputFileInfo.absoluteDir();
if( outputDir.exists() )
if ( outputDir.exists() )
{
s.setValue( "/Heatmap/lastOutputDir", outputFileInfo.absolutePath() );
}
Expand All @@ -199,7 +199,7 @@ void HeatmapGui::enableOrDisableOkButton()
bool enabled = true;
QString filename = mOutputRasterLineEdit->text();
QFileInfo theFileInfo( filename );
if( filename.isEmpty() || !theFileInfo.dir().exists() || ( mInputVectorCombo->count() == 0 ) )
if ( filename.isEmpty() || !theFileInfo.dir().exists() || ( mInputVectorCombo->count() == 0 ) )
{
enabled = false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/heatmap/heatmapgui.h
Expand Up @@ -40,7 +40,7 @@ class HeatmapGui : public QDialog, private Ui::HeatmapGuiBase
signals:
/*
* Signal: createRaster
* Params:
* Params:
* QgsVectorLayer* -> Input point layer
* int -> Buffer distance
* float -> Decay ratio
Expand Down

0 comments on commit 30e2f32

Please sign in to comment.