Merged in Arunmozhi's heatmap plugin into QGIS core

This commit is contained in:
Tim Sutton 2012-02-08 11:07:58 +02:00
parent bc43fddd92
commit 03fd3886e9
14 changed files with 1268 additions and 15 deletions

View File

@ -1,10 +1,10 @@
Quantum GIS (QGIS)
Building QGIS from source - step by step
Tuesday December 27, 2011
Monday February 06, 2012
Last Updated: Tuesday December 27, 2011
Last Change : Tuesday December 27, 2011
Last Updated: Monday February 06, 2012
Last Change : Wednesday February 01, 2012
1. Introduction

View File

@ -80,13 +80,13 @@ label{ background-color: #FFFFCC;
<DIV CLASS="header" ID="header">
<H1>Quantum GIS (QGIS)</H1>
<H2>Building QGIS from source - step by step</H2>
<H3>Sunday November 06, 2011</H3>
<H3>Monday February 06, 2012</H3>
</DIV>
<DIV CLASS="body" ID="body">
<P>
Last Updated: Sunday November 06, 2011
Last Change : Sunday November 06, 2011
Last Updated: Monday February 06, 2012
Last Change : Wednesday February 01, 2012
</P>
<DIV CLASS="toc">
@ -1753,7 +1753,7 @@ Once downloaded, open and install the frameworks.
</P>
<P>
William provides an additional installer package for Postgresql (for PostGIS
support). Qgis just needs the libpq client library, so unless you want to
support). QGIS just needs the libpq client library, so unless you want to
setup the full Postgres + PostGIS server, all you need is the client-only
package. It's available here:
</P>
@ -1772,7 +1772,7 @@ Also available is a GRASS application:
<P>
There are some additional dependencies that, at the time of writing, are not
provided as frameworks or installers so we will need to build these from source.
If you are wanting to build Qgis as a 64-bit application, you will need to
If you are wanting to build QGIS as a 64-bit application, you will need to
provide the appropriate build commands to produce 64-bit support in dependencies.
Likewise, for 32-bit support on Snow Leopard, you will need to override the
default system architecture, which is 64-bit, according to instructions for
@ -2001,7 +2001,7 @@ You can take care of both with the PyQwt source from:
<P>
Double-click the tarball to unpack it. The following assumes PyQwt v5.2.0
(comes with Qwt 5.2.1). Normal compilation does both Qwt and PyQwt at the same
time, but Qwt is statically linked into PyQwt, and Qgis can't use it. So, we
time, but Qwt is statically linked into PyQwt, and QGIS can't use it. So, we
need to split the build.
</P>
<P>
@ -2155,7 +2155,7 @@ the GRASS application if installed.
</P>
<P>
Or, to use a Unix-style build of GRASS, use the following cmake invocation
(minimum GRASS version as stated in the Qgis requirements, substitute the GRASS
(minimum GRASS version as stated in the QGIS requirements, substitute the GRASS
path and version as required):
</P>
@ -2194,7 +2194,7 @@ cmake -D CMAKE_INSTALL_PREFIX=~/Applications -D \
</PRE></div>
<P>
The Qgis Mapserver feature requires fastcgi support. This is included in
The QGIS Mapserver feature requires fastcgi support. This is included in
Leopard and Snow Leopard, but was dropped at Lion. To build the Mapserver
component on Leopard and Snow, add the followling line before the last line in
the above configuration:
@ -2210,9 +2210,9 @@ support to the system Apache. Not recommended for the average user.
</P>
<P>
<U>Bundling note:</U> Older Qt versions may have problems with some Qt plugins and
Qgis. The way to handle this is to bundle Qt inside the Qgis application. You
can do this now or wait to see if there are immediate crashes when running Qgis.
It's also a good idea to bundle Qt if you need to copy Qgis to other Macs (where
QGIS. The way to handle this is to bundle Qt inside the QGIS application. You
can do this now or wait to see if there are immediate crashes when running QGIS.
It's also a good idea to bundle Qt if you need to copy QGIS to other Macs (where
you would have to install Xcode just so Qt would install!).
</P>
<P>
@ -2311,5 +2311,5 @@ The following people have contributed to this document:
</DIV>
<!-- html code generated by txt2tags 2.6 (http://txt2tags.org) -->
<!-- cmdline: txt2tags -t html -o INSTALL.html INSTALL.t2t -->
<!-- cmdline: txt2tags -o INSTALL.html -t html INSTALL.t2t -->
</BODY></HTML>

View File

@ -0,0 +1,27 @@
<h1>Heatmap Plugin Help</h1>
<p>Heatmap Plugin creates a heatmap raster for the input point vector layer. The heatmap is generated based on the number of points in a given location. The higher the number of points, the higher will be the corresponding pixel(s) value in the raster.</p>
<h2>The Dialog Parameters</h2>
<h3>Input Point Vector</h3>
<p>The input is always a vector layer of point type. All the point vector layers that are currently loaded in the window are automatically populated in the input layer drop-down list. Click the Dropdown button and select the required layer.</p>
<h3>Output Ratser</h3>
<p>The output raster location and filename can be set by clicking the <label>...</label> button next to the output raster textbox.<br/>
<b>Note:</b>The file format is automatically added depending upon the output format selected, if not explicitly given.</p>
<h3>Output Format</h3>
<p>All the file creation supporting GDAL formats are available in the drop down list. Click and select the required output format for your file.<br/>
<b>Note:</b> GeoTiff and ERDAS Imagine .img formats are recommended. Some formats makes the application crash. Kindly stick to the recommended formats until the crash issue is resolved or Use other formats if you know about its GDAL support completely.</p>
<h3>Heatmap Point Attributes</h3>
<h4>Buffer Radius</h4>
<p>The buffer radius specifies the number of <b>pixels or cells</b> around a point where the heat(influence) of the point will be felt. Smaller values give you clear distinction between points and bigger values gives you nicely merged heatmap regions. This is the spatial parameter of the heat region of a point.<br/>
<b>Note:</b> The value is always a whole number.</p>
<h4>Decay Ratio</h4>
<p>The decay ratio defines amount of heat(influence) that should reach the outermost pixel in the Buffer Radius. It is the direct measure of the outer most value.<br/>
<b>Example:</b> If Buffer Ratio is set as 0 and Radius as 10, then the centre pixel of a point will have value and the pixel away by a distance of 10 units will have the value 0, a pixel which is 5 units away will have a value of 0.5 and so on. Here distance is measure not by pixel count rather using sqrt( xOffset^2 + yOffset^2 ), so you always get a circular heat region.</p>
<h2>Further Details</h2>
<p>Contact the author through aruntheguy at gmail dot com</p>

View File

@ -37,3 +37,5 @@ IF (WITH_GLOBE)
ENDIF (WITH_GLOBE)
# headers installed in qgis_core target
SUBDIRS (heatmap)

View File

@ -0,0 +1,53 @@
########################################################
# Files
SET (heatmap_SRCS
heatmap.cpp
heatmapgui.cpp
)
SET (heatmap_UIS heatmapguibase.ui)
SET (heatmap_MOC_HDRS
heatmap.h
heatmapgui.h
)
SET (heatmap_RCCS heatmap.qrc)
########################################################
# Build
QT4_WRAP_UI (heatmap_UIS_H ${heatmap_UIS})
QT4_WRAP_CPP (heatmap_MOC_SRCS ${heatmap_MOC_HDRS})
QT4_ADD_RESOURCES(heatmap_RCC_SRCS ${heatmap_RCCS})
ADD_LIBRARY (heatmapplugin MODULE ${heatmap_SRCS} ${heatmap_MOC_SRCS} ${heatmap_RCC_SRCS} ${heatmap_UIS_H})
INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_BINARY_DIR}
${GEOS_INCLUDE_DIR}
${GDAL_INCLUDE_DIR}
../../core
../../core/raster
../../gui
../../analysis/raster
..
)
TARGET_LINK_LIBRARIES(heatmapplugin
qgis_core
qgis_gui
)
########################################################
# Install
INSTALL(TARGETS heatmapplugin
RUNTIME DESTINATION ${QGIS_PLUGIN_DIR}
LIBRARY DESTINATION ${QGIS_PLUGIN_DIR})

View File

@ -0,0 +1,97 @@
Welcome to your automatically generated plugin!
-------------------------------------------------------------
This is just a starting point. You now need to modify the code to make it do
something useful....read on for a more information to get yourself started.
Documentation:
-------------------------------------------------------------
You really need to read the QGIS API Documentation now at:
http://qgis.org/api/
In particular look at the following classes:
QGisInterface : http://qgis.org/api/classQgisInterface.html
QgsMapCanvas : http://qgis.org/api/classQgsMapCanvas.html
QgsMapTool : http://qgis.org/api/classQgsMapTool.html
QgisPlugin : http://qgis.org/api/classQgisPlugin.html
QGisInterface is an abstract base class (ABC) that specifies what publicly
available features of QGIS are exposed to third party code and plugins. An
instance of the QgisInterface is passed to the plugin when it loads. Please
consult the QGIS development team if there is functionality required in the
QGisInterface that is not available.
QgsPlugin is an ABC that defines required behaviour your plugin must provide.
See below for more details.
What are all the files in my generated plugin directory for?
-------------------------------------------------------------
CMakeLists.txt
This is the generated CMake file that builds the plugin. You should add you
application specific dependencies and source files to this file.
heatmap.h
heatmap.cpp
This is the class that provides the 'glue' between your custom application
logic and the QGIS application. You will see that a number of methods are
already implemented for you - including some examples of how to add a raster or
vector layer to the main application map canvas. This class is a concrete
implementation of QgisPlugin (which defines required behaviour for a plugin).
In particular, a plugin has a number of static methods and members so that the
QgsPluginManager and plugin loader logic can identify each plugin, create an
appropriate menu entry for it etc. Note there is nothing stopping you creating
multiple toolbar icons and menu entries for a single plugin. By default though
a single menu entry and toolbar button is created and its pre-configured to
call the run() method in this class when selected. This default implementation
provided for you by the plugin builder is well documented, so please refer to
the code for further advice.
heatmapgui.ui
This is a Qt designer 'ui' file. It defines the look of the default plugin
dialog without implementing any application logic. You can modify this form to
suite your needs or completely remove it if your plugin does not need to
display a user form (e.g. for custom MapTools).
heatmapgui.cpp
heatmapgui.h
This is the concrete class where application logic for the above mentioned
dialog should go. The world is your oyster here really....
heatmap.qrc
This is the Qt4 resources file for your plugin. The Makefile generated for your
plugin is all set up to compile the resource file so all you need to do is add
your additional icons etc using the simple xml file format. Note the namespace
used for all your resources e.g. (":/Heatmap/"). It is important to use
this prefix for all your resources. We suggest you include any other images and
run time data in this resurce file too.
heatmap.png
This is the icon that will be used for your plugin menu entry and toolbar icon.
Simply replace this icon with your own icon to make your plugin disctinctive
from the rest.
README
This file contains the documentation you are reading now!
Getting developer help:
-------------------------------------------------------------
For Questions and Comments regarding the plugin builder template and creating
your features in QGIS using the plugin interface please contact us via:
* the QGIS developers mailing list, or
* IRC (#qgis on freenode.net)
QGIS is distributed under the Gnu Public License. If you create a useful plugin
please consider contributing it back to the community.
Have fun and thank you for choosing QGIS.
The QGIS Team
2007

View File

@ -0,0 +1,339 @@
/***************************************************************************
heatmap.cpp
Creates a Heatmap raster for the input point vector
-------------------
begin : January 2012
copyright : [(C) Arunmozhi]
email : [aruntheguy at gmail dot com]
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
// GDAL includes
#include "gdal_priv.h"
#include "cpl_string.h"
#include "cpl_conv.h"
// QGIS Specific includes
#include <qgisinterface.h>
#include <qgisgui.h>
#include "heatmap.h"
#include "heatmapgui.h"
#include "qgsgeometry.h"
#include "qgsvectorlayer.h"
#include "qgsvectordataprovider.h"
// Qt4 Related Includes
#include <QAction>
#include <QToolBar>
#include <QMessageBox>
#include <QFileInfo>
#include <QProgressDialog>
#define NO_DATA -9999
static const QString sName = QObject::tr( "Heatmap" );
static const QString sDescription = QObject::tr( "Creates a Heatmap raster for the input point vector" );
static const QString sCategory = QObject::tr( "Raster" );
static const QString sPluginVersion = QObject::tr( "Version 0.1" );
static const QgisPlugin::PLUGINTYPE sPluginType = QgisPlugin::UI;
static const QString sPluginIcon = ":/heatmap/heatmap.png";
/**
* Constructor for the plugin. The plugin is passed a pointer
* an interface object that provides access to exposed functions in QGIS.
* @param theQGisInterface - Pointer to the QGIS interface object
*/
Heatmap::Heatmap( QgisInterface * theQgisInterface ):
QgisPlugin( sName, sDescription, sCategory, sPluginVersion, sPluginType ),
mQGisIface( theQgisInterface )
{
}
Heatmap::~Heatmap()
{
}
/*
* Initialize the GUI interface for the plugin - this is only called once when the plugin is
* added to the plugin registry in the QGIS application.
*/
void Heatmap::initGui()
{
// Create the action for tool
mQActionPointer = new QAction( QIcon( ":/heatmap/heatmap.png" ), tr( "Heatmap" ), this );
// Set the what's this text
mQActionPointer->setWhatsThis( tr( "Creats a heatmap raster for the input point vector." ) );
// Connect the action to the run
connect( mQActionPointer, SIGNAL( triggered() ), this, SLOT( run() ) );
// Add the icon to the toolbar
mQGisIface->addToolBarIcon( mQActionPointer );
mQGisIface->addPluginToRasterMenu( tr( "&Heatmap" ), mQActionPointer );
}
//method defined in interface
void Heatmap::help()
{
//implement me!
}
// Slot called when the menu item is triggered
// If you created more menu items / toolbar buttons in initiGui, you should
// create a separate handler for each action - this single run() method will
// not be enough
void Heatmap::run()
{
HeatmapGui *myPluginGui = new HeatmapGui( mQGisIface->mainWindow(), QgisGui::ModalDialogFlags );
myPluginGui->setAttribute( Qt::WA_DeleteOnClose );
// Connect the createRaster signal to createRaster Slot
connect( myPluginGui, SIGNAL( createRaster( QgsVectorLayer*, int, float, QString, QString ) ),
this, SLOT( createRaster( QgsVectorLayer*, int, float, QString, QString ) ) );
myPluginGui->show();
}
// Unload the plugin by cleaning up the GUI
void Heatmap::unload()
{
// remove the GUI
mQGisIface->removePluginMenu( "&Heatmap", mQActionPointer );
mQGisIface->removeToolBarIcon( mQActionPointer );
delete mQActionPointer;
}
// The worker
void Heatmap::createRaster( QgsVectorLayer* theVectorLayer, int theBuffer, float theDecay, QString theOutputFilename, QString theOutputFormat )
{
// generic variables
int xSize, ySize;
double xResolution, yResolution;
double rasterX, rasterY;
// Getting the rasterdataset in place
GDALAllRegister();
GDALDataset *emptyDataset;
GDALDriver *myDriver;
myDriver = GetGDALDriverManager()->GetDriverByName( theOutputFormat.toUtf8() );
if( myDriver == NULL )
{
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;
yResolution = xResolution;
ySize = myBBox.height()/yResolution;
// add extra extend to cover the corner points' heat region
xSize = xSize + ( theBuffer * 2 ) + 10 ;
ySize = ySize + ( theBuffer * 2 ) + 10 ;
// Define the new lat,lon for the buffered raster area
rasterX = myBBox.xMinimum() - ( theBuffer + 5 ) * xResolution;
rasterY = myBBox.yMinimum() - ( theBuffer + 5 ) * yResolution;
double geoTransform[6] = { rasterX, xResolution, 0, rasterY, 0, yResolution };
emptyDataset = myDriver->Create( theOutputFilename.toUtf8(), xSize, ySize, 1, GDT_Float32, NULL );
emptyDataset->SetGeoTransform( geoTransform );
GDALRasterBand *poBand;
poBand = emptyDataset->GetRasterBand(1);
poBand->SetNoDataValue( NO_DATA );
float* line = ( float * ) CPLMalloc( sizeof( float ) * xSize );
std::fill_n( line, xSize, NO_DATA );
// Write the empty raster
for ( int i = 0; i < ySize ; i += 1 )
{
poBand->RasterIO( GF_Write, 0, 0, xSize, 1, line, xSize, 1, GDT_Float32, 0, 0 );
}
CPLFree( line );
//close the dataset
GDALClose( (GDALDatasetH) emptyDataset );
// open the raster in GA_Update mode
GDALDataset *heatmapDS;
heatmapDS = ( GDALDataset * ) GDALOpen( theOutputFilename.toUtf8(), GA_Update );
if( !heatmapDS )
{
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 )
{
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);
QgsFeature myFeature;
while( myVectorProvider->nextFeature( myFeature ) )
{
counter += 1;
p.setValue( counter );
if( p.wasCanceled() )
{
QMessageBox::information( 0, tr("Heatmap Generation Aborted!"), tr("QGIS will now load the partially-computed raster.") );
break;
}
QgsGeometry* myPointGeometry;
myPointGeometry = myFeature.geometry();
// convert the geometry to point
QgsPoint myPoint;
myPoint = myPointGeometry->asPoint();
// avoiding any empty points or out of extent points
if( ( myPoint.x() < rasterX ) || ( myPoint.y() < rasterY ) )
{
continue;
}
// calculate the pixel position
unsigned int xPosition, yPosition;
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 yp = 0; yp <= theBuffer; yp += 1 )
{
float distance = sqrt( pow( xp, 2 ) + pow( yp, 2 ) );
float pixelValue = 1 - ( (1-theDecay) * distance / theBuffer );
// clearing anamolies along the axes
if( xp == 0 && yp == 0 )
{
pixelValue /= 4;
}
else if( xp == 0 || yp == 0 )
{
pixelValue /= 2;
}
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 )
{
if( dataBuffer[ pos[p] ] == NO_DATA )
{
dataBuffer[ pos[p] ] = 0;
}
dataBuffer[ pos[p] ] += pixelValue;
}
}
}
}
poBand->RasterIO( GF_Write, xPosition, yPosition, blockSize, blockSize, dataBuffer, blockSize, blockSize, GDT_Float32, 0, 0 );
CPLFree( dataBuffer );
}
//Finally close the dataset
GDALClose( (GDALDatasetH) heatmapDS );
// Open the file in QGIS window
mQGisIface->addRasterLayer( theOutputFilename, QFileInfo( theOutputFilename ).baseName() );
}
//////////////////////////////////////////////////////////////////////////
//
//
// THE FOLLOWING CODE IS AUTOGENERATED BY THE PLUGIN BUILDER SCRIPT
// YOU WOULD NORMALLY NOT NEED TO MODIFY THIS, AND YOUR PLUGIN
// MAY NOT WORK PROPERLY IF YOU MODIFY THIS INCORRECTLY
//
//
//////////////////////////////////////////////////////////////////////////
/**
* Required extern functions needed for every plugin
* These functions can be called prior to creating an instance
* of the plugin class
*/
// Class factory to return a new instance of the plugin class
QGISEXTERN QgisPlugin * classFactory( QgisInterface * theQgisInterfacePointer )
{
return new Heatmap( theQgisInterfacePointer );
}
// Return the name of the plugin - note that we do not user class members as
// the class may not yet be insantiated when this method is called.
QGISEXTERN QString name()
{
return sName;
}
// Return the description
QGISEXTERN QString description()
{
return sDescription;
}
// Return the category
QGISEXTERN QString category()
{
return sCategory;
}
// Return the type (either UI or MapLayer plugin)
QGISEXTERN int type()
{
return sPluginType;
}
// Return the version number for the plugin
QGISEXTERN QString version()
{
return sPluginVersion;
}
QGISEXTERN QString icon()
{
return sPluginIcon;
}
// Delete ourself
QGISEXTERN void unload( QgisPlugin * thePluginPointer )
{
delete thePluginPointer;
}

View File

@ -0,0 +1,105 @@
/***************************************************************************
heatmap.h
-------------------
begin : Jan 21, 2004
copyright : (C) 2004 by Tim Sutton
email : tim@linfiniti.com
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
/***************************************************************************
* QGIS Programming conventions:
*
* mVariableName - a class level member variable
* sVariableName - a static class level member variable
* variableName() - accessor for a class member (no 'get' in front of name)
* setVariableName() - mutator for a class member (prefix with 'set')
*
* Additional useful conventions:
*
* theVariableName - a method parameter (prefix with 'the')
* myVariableName - a locally declared variable within a method ('my' prefix)
*
* DO: Use mixed case variable names - myVariableName
* DON'T: separate variable names using underscores: my_variable_name (NO!)
*
* **************************************************************************/
#ifndef Heatmap_H
#define Heatmap_H
//QT4 includes
#include <QObject>
//QGIS includes
#include "../qgisplugin.h"
#include "qgsvectorlayer.h"
//forward declarations
class QAction;
class QToolBar;
class QgisInterface;
/**
* \class Plugin
* \brief heatmap plugin for QGIS
* \description generates a heatmap raster for the input point vector
*/
class Heatmap: public QObject, public QgisPlugin
{
Q_OBJECT
public:
// MANDATORY PLUGIN METHODS FOLLOW
/**
* Constructor for a plugin. The QgisInterface pointer is passed by
* QGIS when it attempts to instantiate the plugin.
* @param theInterface Pointer to the QgisInterface object.
*/
Heatmap( QgisInterface * theInterface );
//! Destructor
virtual ~Heatmap();
public slots:
//! init the gui
virtual void initGui();
//! Show the dialog box
void run();
//! unload the plugin
void unload();
//! show the help document
void help();
//! the worker slot to create heatmap
/*
* Signal: createRaster
* Params:
* QgsVectorLayer* -> Input point layer
* int -> Buffer distance
* float -> Decay ratio
* QString -> Output filename
* QString -> Output Format Short Name
*/
void createRaster( QgsVectorLayer*, int, float, QString, QString );
private:
// MANDATORY PLUGIN PROPERTY DECLARATIONS .....
int mPluginType;
//! Pointer to the QGIS interface object
QgisInterface *mQGisIface;
//!pointer to the qaction for this plugin
QAction * mQActionPointer;
};
#endif //Heatmap_H

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -0,0 +1,5 @@
<RCC>
<qresource prefix="/heatmap/" >
<file>heatmap.png</file>
</qresource>
</RCC>

View File

@ -0,0 +1,143 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="32px"
height="32px"
id="svg2993"
version="1.1"
inkscape:version="0.48.2 r9819"
sodipodi:docname="New document 3">
<defs
id="defs2995">
<linearGradient
id="linearGradient3779">
<stop
style="stop-color:#ffff00;stop-opacity:1;"
offset="0"
id="stop3781" />
<stop
id="stop3787"
offset="0.5"
style="stop-color:#ffd600;stop-opacity:0.49803922;" />
<stop
style="stop-color:#ff2400;stop-opacity:0.24705882;"
offset="0.75"
id="stop3789" />
<stop
style="stop-color:#ff0000;stop-opacity:0;"
offset="1"
id="stop3783" />
</linearGradient>
<radialGradient
inkscape:collect="always"
xlink:href="#linearGradient3779"
id="radialGradient3785"
cx="9.3768406"
cy="12.397939"
fx="9.3768406"
fy="12.397939"
r="6.6619234"
gradientTransform="matrix(1,0,0,0.96648745,0,0.4154865)"
gradientUnits="userSpaceOnUse" />
<radialGradient
inkscape:collect="always"
xlink:href="#linearGradient3779-4"
id="radialGradient3785-3"
cx="9.3768406"
cy="12.397939"
fx="9.3768406"
fy="12.397939"
r="6.6619234"
gradientTransform="matrix(1,0,0,0.96648745,0,0.4154865)"
gradientUnits="userSpaceOnUse" />
<linearGradient
id="linearGradient3779-4">
<stop
style="stop-color:#ffff00;stop-opacity:1;"
offset="0"
id="stop3781-0" />
<stop
id="stop3787-1"
offset="0.5"
style="stop-color:#ffd600;stop-opacity:0.49803922;" />
<stop
style="stop-color:#ff2400;stop-opacity:0.24705882;"
offset="0.75"
id="stop3789-7" />
<stop
style="stop-color:#ff0000;stop-opacity:0;"
offset="1"
id="stop3783-7" />
</linearGradient>
<radialGradient
r="6.6619234"
fy="12.397939"
fx="9.3768406"
cy="12.397939"
cx="9.3768406"
gradientTransform="matrix(1.7101449,0,0,1.6059679,2.1821045,-0.32384171)"
gradientUnits="userSpaceOnUse"
id="radialGradient3808"
xlink:href="#linearGradient3779-4"
inkscape:collect="always" />
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="15.836083"
inkscape:cx="22.042908"
inkscape:cy="18.689818"
inkscape:current-layer="layer1"
showgrid="true"
inkscape:grid-bbox="true"
inkscape:document-units="px"
inkscape:window-width="1280"
inkscape:window-height="746"
inkscape:window-x="-1"
inkscape:window-y="25"
inkscape:window-maximized="1" />
<metadata
id="metadata2998">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
id="layer1"
inkscape:label="Layer 1"
inkscape:groupmode="layer">
<path
sodipodi:type="arc"
style="fill:url(#radialGradient3785);fill-opacity:1;fill-rule:evenodd;stroke:none"
id="path3001"
sodipodi:cx="9.3768406"
sodipodi:cy="12.397939"
sodipodi:rx="6.1619234"
sodipodi:ry="5.9386654"
d="m 15.538764,12.397939 a 6.1619234,5.9386654 0 1 1 -12.3238468,0 6.1619234,5.9386654 0 1 1 12.3238468,0 z"
transform="translate(0.26790972,-2.589794)" />
<path
style="fill:url(#radialGradient3808);fill-opacity:1;fill-rule:evenodd;stroke:none"
d="M 18.21875 9.71875 C 12.398894 9.71875 7.6875 14.1438 7.6875 19.59375 C 7.6875 25.0437 12.398894 29.46875 18.21875 29.46875 C 24.038606 29.46875 28.75 25.0437 28.75 19.59375 C 28.75 14.1438 24.038606 9.71875 18.21875 9.71875 z "
id="path3001-8" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 4.5 KiB

View File

@ -0,0 +1,207 @@
/***************************************************************************
* Copyright (C) 2003 by Tim Sutton *
* tim@linfiniti.com *
* *
* This is a plugin generated from the QGIS plugin template *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
// qgis includes
#include "qgis.h"
#include "heatmapgui.h"
#include "qgscontexthelp.h"
#include "qgsmaplayer.h"
#include "qgsmaplayerregistry.h"
#include "qgsvectorlayer.h"
// GDAL includes
#include "gdal_priv.h"
#include "cpl_string.h"
#include "cpl_conv.h"
//qt includes
#include <QComboBox>
#include <QFileDialog>
#include <QSettings>
#include <QMessageBox>
//standard includes
HeatmapGui::HeatmapGui( QWidget* parent, Qt::WFlags fl )
: QDialog( parent, fl )
{
setupUi( this );
// Adding point layers to the mInputVectorCombo
QMap<QString, QgsMapLayer*> mapLayers = QgsMapLayerRegistry::instance()->mapLayers();
QMapIterator<QString, QgsMapLayer*> layers(mapLayers);
while( layers.hasNext() )
{
layers.next();
QgsVectorLayer* vl = qobject_cast<QgsVectorLayer *>(layers.value());
if( ( vl ) && ( vl->geometryType() == QGis::Point ) )
{
mInputVectorCombo->addItem( vl->name(), QVariant( vl->id() ) );
}
}
// Adding GDAL drivers with CREATE to the mFormatCombo
int myTiffIndex = -1;
int myIndex = -1;
GDALAllRegister();
int nDrivers = GDALGetDriverCount();
for( int i = 0; i < nDrivers; i +=1 )
{
GDALDriver* nthDriver = GetGDALDriverManager()->GetDriver( i );
char** driverMetadata = nthDriver->GetMetadata();
if( CSLFetchBoolean( driverMetadata, GDAL_DCAP_CREATE, false ) )
{
++myIndex;
QString myLongName = nthDriver->GetMetadataItem( GDAL_DMD_LONGNAME );
// Add LongName text, shortname variant; GetDescription actually gets the shortname
mFormatCombo->addItem( myLongName, QVariant( nthDriver->GetDescription() ) );
// Add the drivers and their extensions to a map for filename correction
mExtensionMap.insert( nthDriver->GetDescription(), nthDriver->GetMetadataItem( GDAL_DMD_EXTENSION ) );
if ( myLongName == "GeoTIFF" )
{
myTiffIndex = myIndex;
}
}
}
mFormatCombo->setCurrentIndex(myTiffIndex);
//finally set right the ok button
enableOrDisableOkButton();
}
HeatmapGui::~HeatmapGui()
{
}
void HeatmapGui::on_mButtonBox_accepted()
{
// Variables to be emitted with the createRaster signal
QgsVectorLayer* inputLayer;
int bufferDistance;
float decayRatio;
QString outputFileName;
QString outputFormat;
QString dummyText;
// The input vector layer
int myLayerId = mInputVectorCombo->itemData( mInputVectorCombo->currentIndex() ).toInt();
QMap<QString, QgsMapLayer*> mapLayers = QgsMapLayerRegistry::instance()->mapLayers();
QMapIterator<QString, QgsMapLayer*> layers(mapLayers);
while( layers.hasNext() )
{
layers.next();
QgsVectorLayer* vl = qobject_cast<QgsVectorLayer *>(layers.value());
if ( vl )
{
dummyText = vl->id();
if( dummyText.toInt() == myLayerId )
{
inputLayer = vl;
}
}
}
// The buffer distance
dummyText = mBufferLineEdit->text();
bufferDistance = dummyText.toInt();
if( bufferDistance == NULL )
{
QMessageBox::information( 0, tr("Invalid Buffer Value!"), tr("Buffer distance cannot be NULL, kindly enter a valid value.") );
return;
}
// The decay ratio
dummyText = mDecayLineEdit->text();
decayRatio = dummyText.toFloat();
// The output filename
outputFileName = mOutputRasterLineEdit->text();
QFileInfo myFileInfo( outputFileName );
if( outputFileName.isEmpty() || !myFileInfo.dir().exists() )
{
QMessageBox::information( 0, tr("Output filename is invalid!"), tr("Kindly enter a valid output file path and name.") );
return;
}
// The output format
outputFormat = mFormatCombo->itemData( mFormatCombo->currentIndex() ).toString();
// append the file format if the suffix is empty
QString suffix = myFileInfo.suffix();
if( suffix.isEmpty() )
{
QMap<QString, QString>::const_iterator it = mExtensionMap.find( 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() != "" )
{
outputFileName.append(".");
outputFileName.append( it.value() );
}
}
}
emit createRaster( inputLayer, bufferDistance, decayRatio, outputFileName, outputFormat );
//and finally
accept();
}
void HeatmapGui::on_mButtonBox_rejected()
{
reject();
}
void HeatmapGui::on_mButtonBox_helpRequested()
{
QgsContextHelp::run( metaObject()->className() );
}
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() )
{
mOutputRasterLineEdit->setText( outputFilename );
QFileInfo outputFileInfo( outputFilename );
QDir outputDir = outputFileInfo.absoluteDir();
if( outputDir.exists() )
{
s.setValue( "/Heatmap/lastOutputDir", outputFileInfo.absolutePath() );
}
}
enableOrDisableOkButton();
}
void HeatmapGui::on_mOutputRasterLineEdit_editingFinished()
{
enableOrDisableOkButton();
}
void HeatmapGui::enableOrDisableOkButton()
{
bool enabled = true;
QString filename = mOutputRasterLineEdit->text();
QFileInfo theFileInfo( filename );
if( filename.isEmpty() || !theFileInfo.dir().exists() || ( mInputVectorCombo->count() == 0 ) )
{
enabled = false;
}
mButtonBox->button( QDialogButtonBox::Ok )->setEnabled( enabled );
}

View File

@ -0,0 +1,54 @@
/***************************************************************************
* Copyright (C) 2003 by Tim Sutton *
* tim@linfiniti.com *
* *
* This is a plugin generated from the QGIS plugin template *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#ifndef HeatmapGUI_H
#define HeatmapGUI_H
#include <QDialog>
#include <ui_heatmapguibase.h>
#include "qgsvectorlayer.h"
/**
@author Tim Sutton
*/
class HeatmapGui : public QDialog, private Ui::HeatmapGuiBase
{
Q_OBJECT
public:
HeatmapGui( QWidget* parent = 0, Qt::WFlags fl = 0 );
~HeatmapGui();
private:
QMap<QString, QString> mExtensionMap;
void enableOrDisableOkButton();
private slots:
void on_mButtonBox_accepted();
void on_mButtonBox_rejected();
void on_mButtonBox_helpRequested();
void on_mBrowseButton_clicked(); // Function to open the file dialog
void on_mOutputRasterLineEdit_editingFinished();
signals:
/*
* Signal: createRaster
* Params:
* QgsVectorLayer* -> Input point layer
* int -> Buffer distance
* float -> Decay ratio
* QString -> Output filename
* QString -> Output Format Short Name
*/
void createRaster( QgsVectorLayer*, int, float, QString, QString );
};
#endif

View File

@ -0,0 +1,221 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>HeatmapGuiBase</class>
<widget class="QDialog" name="HeatmapGuiBase">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>260</height>
</rect>
</property>
<property name="windowTitle">
<string>Heatmap Plugin</string>
</property>
<property name="locale">
<locale language="English" country="UnitedStates"/>
</property>
<widget class="QLabel" name="mInputLabel">
<property name="geometry">
<rect>
<x>10</x>
<y>20</y>
<width>110</width>
<height>21</height>
</rect>
</property>
<property name="text">
<string>Input Point Vector</string>
</property>
</widget>
<widget class="QComboBox" name="mInputVectorCombo">
<property name="geometry">
<rect>
<x>125</x>
<y>20</y>
<width>260</width>
<height>25</height>
</rect>
</property>
</widget>
<widget class="QLabel" name="mOutputLabel">
<property name="geometry">
<rect>
<x>10</x>
<y>65</y>
<width>110</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Output Raster</string>
</property>
</widget>
<widget class="QLineEdit" name="mOutputRasterLineEdit">
<property name="geometry">
<rect>
<x>125</x>
<y>60</y>
<width>230</width>
<height>25</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="mBrowseButton">
<property name="geometry">
<rect>
<x>355</x>
<y>60</y>
<width>30</width>
<height>25</height>
</rect>
</property>
<property name="focusPolicy">
<enum>Qt::ClickFocus</enum>
</property>
<property name="text">
<string>...</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget>
<widget class="QDialogButtonBox" name="mButtonBox">
<property name="geometry">
<rect>
<x>10</x>
<y>225</y>
<width>375</width>
<height>30</height>
</rect>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok</set>
</property>
</widget>
<widget class="QGroupBox" name="mPointAttributeBox">
<property name="geometry">
<rect>
<x>10</x>
<y>140</y>
<width>370</width>
<height>80</height>
</rect>
</property>
<property name="title">
<string>Heatmap Point Attributes</string>
</property>
<widget class="QLabel" name="mBufferLabel">
<property name="geometry">
<rect>
<x>10</x>
<y>27</y>
<width>101</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Buffer Radius</string>
</property>
</widget>
<widget class="QLabel" name="mDecayLabel">
<property name="geometry">
<rect>
<x>10</x>
<y>56</y>
<width>101</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>Decay Ratio</string>
</property>
</widget>
<widget class="QLineEdit" name="mBufferLineEdit">
<property name="geometry">
<rect>
<x>110</x>
<y>20</y>
<width>113</width>
<height>25</height>
</rect>
</property>
<property name="text">
<string>10</string>
</property>
</widget>
<widget class="QLineEdit" name="mDecayLineEdit">
<property name="geometry">
<rect>
<x>110</x>
<y>50</y>
<width>113</width>
<height>25</height>
</rect>
</property>
<property name="text">
<string>0.5</string>
</property>
</widget>
</widget>
<widget class="QLabel" name="mFormatLabel">
<property name="geometry">
<rect>
<x>10</x>
<y>105</y>
<width>110</width>
<height>15</height>
</rect>
</property>
<property name="text">
<string>Output Format</string>
</property>
</widget>
<widget class="QComboBox" name="mFormatCombo">
<property name="geometry">
<rect>
<x>125</x>
<y>100</y>
<width>260</width>
<height>25</height>
</rect>
</property>
</widget>
</widget>
<resources/>
<connections>
<connection>
<sender>mButtonBox</sender>
<signal>accepted()</signal>
<receiver>HeatmapGuiBase</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>195</x>
<y>123</y>
</hint>
<hint type="destinationlabel">
<x>199</x>
<y>79</y>
</hint>
</hints>
</connection>
<connection>
<sender>mButtonBox</sender>
<signal>rejected()</signal>
<receiver>HeatmapGuiBase</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>195</x>
<y>123</y>
</hint>
<hint type="destinationlabel">
<x>199</x>
<y>79</y>
</hint>
</hints>
</connection>
</connections>
</ui>