From b66b3ec46df9e2f0f9e3c1ad8e09cf2b37e2d15e Mon Sep 17 00:00:00 2001
From: Arunmozhi
Date: Sat, 28 Jan 2012 13:36:21 +0530
Subject: [PATCH 1/8] added the heatmap skeleton files
---
src/plugins/CMakeLists.txt | 2 +
src/plugins/heatmap/CMakeLists.txt | 49 ++++++++
src/plugins/heatmap/README | 97 +++++++++++++++
src/plugins/heatmap/heatmap.cpp | 172 ++++++++++++++++++++++++++
src/plugins/heatmap/heatmap.h | 105 ++++++++++++++++
src/plugins/heatmap/heatmap.png | Bin 0 -> 1090 bytes
src/plugins/heatmap/heatmap.qrc | 5 +
src/plugins/heatmap/heatmapgui.cpp | 99 +++++++++++++++
src/plugins/heatmap/heatmapgui.h | 38 ++++++
src/plugins/heatmap/heatmapguibase.ui | 76 ++++++++++++
10 files changed, 643 insertions(+)
create mode 100644 src/plugins/heatmap/CMakeLists.txt
create mode 100644 src/plugins/heatmap/README
create mode 100644 src/plugins/heatmap/heatmap.cpp
create mode 100644 src/plugins/heatmap/heatmap.h
create mode 100644 src/plugins/heatmap/heatmap.png
create mode 100644 src/plugins/heatmap/heatmap.qrc
create mode 100644 src/plugins/heatmap/heatmapgui.cpp
create mode 100644 src/plugins/heatmap/heatmapgui.h
create mode 100644 src/plugins/heatmap/heatmapguibase.ui
diff --git a/src/plugins/CMakeLists.txt b/src/plugins/CMakeLists.txt
index 96f9ffd88678..3f8762fb26cd 100644
--- a/src/plugins/CMakeLists.txt
+++ b/src/plugins/CMakeLists.txt
@@ -37,3 +37,5 @@ IF (WITH_GLOBE)
ENDIF (WITH_GLOBE)
# headers installed in qgis_core target
+
+SUBDIRS (heatmap)
diff --git a/src/plugins/heatmap/CMakeLists.txt b/src/plugins/heatmap/CMakeLists.txt
new file mode 100644
index 000000000000..9dbc9918438d
--- /dev/null
+++ b/src/plugins/heatmap/CMakeLists.txt
@@ -0,0 +1,49 @@
+
+########################################################
+# 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}
+ ../../core ../../core/raster ../../core/renderer ../../core/symbology
+ ../../gui
+ ..
+)
+
+TARGET_LINK_LIBRARIES(heatmapplugin
+ qgis_core
+ qgis_gui
+)
+
+
+########################################################
+# Install
+
+INSTALL(TARGETS heatmapplugin
+ RUNTIME DESTINATION ${QGIS_PLUGIN_DIR}
+ LIBRARY DESTINATION ${QGIS_PLUGIN_DIR})
+
diff --git a/src/plugins/heatmap/README b/src/plugins/heatmap/README
new file mode 100644
index 000000000000..1c03ea3ea8c8
--- /dev/null
+++ b/src/plugins/heatmap/README
@@ -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
diff --git a/src/plugins/heatmap/heatmap.cpp b/src/plugins/heatmap/heatmap.cpp
new file mode 100644
index 000000000000..a2c044099ee1
--- /dev/null
+++ b/src/plugins/heatmap/heatmap.cpp
@@ -0,0 +1,172 @@
+/***************************************************************************
+ heatmap.cpp
+ Creates a Heatmap raster for the input point vector
+ -------------------
+ begin : [PluginDate]
+ copyright : [(C) Your Name and Date]
+ email : [Your Email]
+
+ ***************************************************************************
+ * *
+ * 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 Specific includes
+//
+
+#include
+#include
+
+#include "heatmap.h"
+#include "heatmapgui.h"
+
+//
+// Qt4 Related Includes
+//
+
+#include
+#include
+
+
+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";
+
+//////////////////////////////////////////////////////////////////////
+//
+// THE FOLLOWING METHODS ARE MANDATORY FOR ALL PLUGINS
+//
+//////////////////////////////////////////////////////////////////////
+
+/**
+ * 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( "Replace this with a short description of what the plugin does" ) );
+ // Connect the action to the run
+ connect( mQActionPointer, SIGNAL( triggered() ), this, SLOT( run() ) );
+ // Add the icon to the toolbar
+ mQGisIface->addToolBarIcon( mQActionPointer );
+ mQGisIface->addPluginToMenu( 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 );
+
+ 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 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;
+}
diff --git a/src/plugins/heatmap/heatmap.h b/src/plugins/heatmap/heatmap.h
new file mode 100644
index 000000000000..33797a3692e5
--- /dev/null
+++ b/src/plugins/heatmap/heatmap.h
@@ -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
+
+//QGIS includes
+#include "../qgisplugin.h"
+
+//forward declarations
+class QAction;
+class QToolBar;
+
+class QgisInterface;
+
+/**
+* \class Plugin
+* \brief [name] plugin for QGIS
+* [description]
+*/
+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();
+
+ private:
+
+ ////////////////////////////////////////////////////////////////////
+ //
+ // MANDATORY PLUGIN PROPERTY DECLARATIONS .....
+ //
+ ////////////////////////////////////////////////////////////////////
+
+ int mPluginType;
+ //! Pointer to the QGIS interface object
+ QgisInterface *mQGisIface;
+ //!pointer to the qaction for this plugin
+ QAction * mQActionPointer;
+ ////////////////////////////////////////////////////////////////////
+ //
+ // ADD YOUR OWN PROPERTY DECLARATIONS AFTER THIS POINT.....
+ //
+ ////////////////////////////////////////////////////////////////////
+};
+
+#endif //Heatmap_H
diff --git a/src/plugins/heatmap/heatmap.png b/src/plugins/heatmap/heatmap.png
new file mode 100644
index 0000000000000000000000000000000000000000..66c4e7f5d52848901f2fa4ec8bfb739e6127d00e
GIT binary patch
literal 1090
zcmV-I1ikx-P)YVd1VoXKYtk*
z1cbR6)+{+OKQ(C+!|Zu}cwG(h5<@i#+2m?ny0
zFq#o=xBx?JsvCodIDdag$RY!51_J~T++a}wp$`%wd<>zHT400F4MWBtIZjSihVVFN
z0SQUr{n!i#2q3t@fB*gKkBHG?;NoII7{Y{UAhLzPB+B6BZ!7@R-j8lDKmdVL1t4PZu~YBq!!r8Z!c4IslIhR%mM79fC742BsV4>bJD`FH<6eE$Fc@5lQ
+
+ heatmap.png
+
+
diff --git a/src/plugins/heatmap/heatmapgui.cpp b/src/plugins/heatmap/heatmapgui.cpp
new file mode 100644
index 000000000000..ba94ceeb153e
--- /dev/null
+++ b/src/plugins/heatmap/heatmapgui.cpp
@@ -0,0 +1,99 @@
+/***************************************************************************
+ * 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. *
+ ***************************************************************************/
+#include "heatmapgui.h"
+#include "qgscontexthelp.h"
+
+//qt includes
+
+//standard includes
+
+HeatmapGui::HeatmapGui( QWidget* parent, Qt::WFlags fl )
+ : QDialog( parent, fl )
+{
+ setupUi( this );
+
+ // Below is an example of how to make the translators job
+ // much easier. Please follow this general guideline for LARGE
+ // pieces of text. One-liners can be added in the .ui file
+
+ // Note: Format does not relate to translation.
+ QString format( "
" );
+
+ // Note: Translatable strings below
+ QString text = format
+ .arg( tr( "Welcome to your automatically generated plugin!" ) )
+ .arg( tr( "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." ) )
+ .arg( tr( "Documentation:" ) )
+ .arg( tr( "You really need to read the QGIS API Documentation now at:" ) )
+ .arg( tr( "In particular look at the following classes:" ) )
+ .arg( table )
+ .arg( "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." )
+ .arg( tr( "QgsPlugin is an ABC that defines required behaviour your plugin must provide. See below for more details." ) )
+ .arg( tr( "What are all the files in my generated plugin directory for?" ) )
+ .arg( tr( "This is the generated CMake file that builds the plugin. You should add you application specific dependencies and source files to this file." ) )
+ .arg( tr( "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 instance of the QgisPlugin interface 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." ) )
+ .arg( tr( "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)." ) )
+ .arg( tr( "This is the concrete class where application logic for the above mentioned dialog should go. The world is your oyster here really...." ) )
+ .arg( tr( "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. (':/Homann/'). 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." ) )
+ .arg( tr( "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." ) )
+ .arg( tr( "This file contains the documentation you are reading now!" ) )
+ .arg( tr( "Getting developer help:" ) )
+ .arg( tr( "For Questions and Comments regarding the plugin builder template and creating your features in QGIS using the plugin interface please contact us via:" ) )
+ .arg( tr( "
the QGIS developers mailing list, or
IRC (#qgis on freenode.net)
" ) )
+ .arg( tr( "QGIS is distributed under the Gnu Public License. If you create a useful plugin please consider contributing it back to the community." ) )
+ .arg( tr( "Have fun and thank you for choosing QGIS." ) );
+
+ textBrowser->setHtml( text );
+}
+
+HeatmapGui::~HeatmapGui()
+{
+}
+
+void HeatmapGui::on_buttonBox_accepted()
+{
+ //close the dialog
+ accept();
+}
+
+void HeatmapGui::on_buttonBox_rejected()
+{
+ reject();
+}
+
+void HeatmapGui::on_buttonBox_helpRequested()
+{
+ QgsContextHelp::run( context_id );
+}
+
diff --git a/src/plugins/heatmap/heatmapgui.h b/src/plugins/heatmap/heatmapgui.h
new file mode 100644
index 000000000000..491363ab6bb3
--- /dev/null
+++ b/src/plugins/heatmap/heatmapgui.h
@@ -0,0 +1,38 @@
+/***************************************************************************
+ * 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
+#include
+
+/**
+@author Tim Sutton
+*/
+class HeatmapGui : public QDialog, private Ui::HeatmapGuiBase
+{
+ Q_OBJECT
+ public:
+ HeatmapGui( QWidget* parent = 0, Qt::WFlags fl = 0 );
+ ~HeatmapGui();
+
+ private:
+ static const int context_id = 0;
+
+ private slots:
+ void on_buttonBox_accepted();
+ void on_buttonBox_rejected();
+ void on_buttonBox_helpRequested();
+
+};
+
+#endif
diff --git a/src/plugins/heatmap/heatmapguibase.ui b/src/plugins/heatmap/heatmapguibase.ui
new file mode 100644
index 000000000000..6762337a0f2a
--- /dev/null
+++ b/src/plugins/heatmap/heatmapguibase.ui
@@ -0,0 +1,76 @@
+
+ HeatmapGuiBase
+
+
+
+ 0
+ 0
+ 584
+ 435
+
+
+
+ QGIS Plugin Template
+
+
+
+
+
+
+ 9
+
+
+ 6
+
+
+
+
+
+ 5
+ 1
+ 0
+ 0
+
+
+
+
+ Sans Serif
+ 24
+ 75
+ false
+ true
+ false
+ false
+
+
+
+ Plugin Template
+
+
+ Qt::AlignCenter
+
+
+
+
+
+
+ true
+
+
+
+
+
+
+ Qt::Horizontal
+
+
+ QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::NoButton|QDialogButtonBox::Ok|QDialogButtonBox::SaveAll
+
+
+
+
+
+
+
+
+
From 45df6d18020c44f0f44724c8c2ea659c5af4726e Mon Sep 17 00:00:00 2001
From: Arunmozhi
Date: Sun, 29 Jan 2012 17:31:37 +0530
Subject: [PATCH 2/8] the GUI files done
---
src/plugins/heatmap/CMakeLists.txt | 8 +-
src/plugins/heatmap/heatmap.cpp | 10 +-
src/plugins/heatmap/heatmap.png | Bin 1090 -> 1271 bytes
src/plugins/heatmap/heatmap.svg | 143 ++++++++++++++
src/plugins/heatmap/heatmapgui.cpp | 195 ++++++++++++------
src/plugins/heatmap/heatmapgui.h | 23 ++-
src/plugins/heatmap/heatmapguibase.ui | 275 ++++++++++++++++++++------
7 files changed, 519 insertions(+), 135 deletions(-)
create mode 100644 src/plugins/heatmap/heatmap.svg
diff --git a/src/plugins/heatmap/CMakeLists.txt b/src/plugins/heatmap/CMakeLists.txt
index 9dbc9918438d..94386389f7d6 100644
--- a/src/plugins/heatmap/CMakeLists.txt
+++ b/src/plugins/heatmap/CMakeLists.txt
@@ -25,12 +25,16 @@ 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})
+ADD_LIBRARY (heatmapplugin MODULE ${heatmap_SRCS} ${heatmap_MOC_SRCS} ${heatmap_RCC_SRCS} ${heatmap_UIS_H})
INCLUDE_DIRECTORIES(
${CMAKE_CURRENT_BINARY_DIR}
- ../../core ../../core/raster ../../core/renderer ../../core/symbology
+ ${GEOS_INCLUDE_DIR}
+ ${GDAL_INCLUDE_DIR}
+ ../../core
+ ../../core/raster
../../gui
+ ../../analysis/raster
..
)
diff --git a/src/plugins/heatmap/heatmap.cpp b/src/plugins/heatmap/heatmap.cpp
index a2c044099ee1..4e802a0d5caa 100644
--- a/src/plugins/heatmap/heatmap.cpp
+++ b/src/plugins/heatmap/heatmap.cpp
@@ -2,9 +2,9 @@
heatmap.cpp
Creates a Heatmap raster for the input point vector
-------------------
- begin : [PluginDate]
- copyright : [(C) Your Name and Date]
- email : [Your Email]
+ begin : January 2012
+ copyright : [(C) Arunmozhi]
+ email : [aruntheguy at gmail dot com]
***************************************************************************
* *
@@ -72,12 +72,12 @@ 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( "Replace this with a short description of what the plugin does" ) );
+ 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->addPluginToMenu( tr( "&Heatmap" ), mQActionPointer );
+ mQGisIface->addPluginToRasterMenu( tr( "&Heatmap" ), mQActionPointer );
}
//method defined in interface
diff --git a/src/plugins/heatmap/heatmap.png b/src/plugins/heatmap/heatmap.png
index 66c4e7f5d52848901f2fa4ec8bfb739e6127d00e..37cc5a36226a413c8ff78af7c041ac201352a6bc 100644
GIT binary patch
literal 1271
zcmV>M`I})u2fR1OI_#FIrpAZ9b$~$
z=1Sgb^#23UdgYxE5(77Mj3hczm6fq0FT}XIEQ?!wtU})j?^u4sjgDxzLnpreWunE
z+_B|`OkYciLgP&7xurvMZC!mELU<;|#Z@xEq30O*ox}@;pEx#>d#LYIi3du3wV!MJ
zz^+|weJw#yXq;MkX5o>k``S*l>`H|2_@a_r+=xO*?AX_HOKwBg$jr7Nb64~Wl@E2@
zvteIHkO_jQHc@zD?tzKF8~fC$1IH!~op|D0z>8b)%bGnE!l9vo%)9z#eq_V141H|N
zhc@Mg5zby1@3gP&hS$I7F5*vcHJsr1n-PM!ZklB>kk{M~~A=Ow4
z+6bb`Jxfo_?dy1?tulB<00U-o?+7hjGxZJk3mX4OL)Ieq=GZM7art4p>G-hgT
zTXLH+U73ZJUHR1kq@qM?ePt4DsUT(jO{ycaDb-bIB&KKyT7pztDwoJ5qQpw}%>b7H
z8bn0ZxkjQe~nxUw>XXRT?Wzlq!`Y-|7XIZ^FvVO5xDbfu%3Z?U@R4FL!>WGL=X)
zO0}t#vD(yAGhbRbvQ#NF3Y2dKI5U%5I5YRi)V8*P%mHg#a^zKMsX
z9-AvI%uLVEh06gk7KY)4LdOHS?pJNMc28koswG4c|2FeaXPz6I8awjrqPM530b-0ocxG!o
z^Z&MYVd1VoXKYtk*
z1cbR6)+{+OKQ(C+!|Zu}cwG(h5<@i#+2m?ny0
zFq#o=xBx?JsvCodIDdag$RY!51_J~T++a}wp$`%wd<>zHT400F4MWBtIZjSihVVFN
z0SQUr{n!i#2q3t@fB*gKkBHG?;NoII7{Y{UAhLzPB+B6BZ!7@R-j8lDKmdVL1t4PZu~YBq!!r8Z!c4IslIhR%mM79fC742BsV4>bJD`FH<6eE$Fc@5lQ
+
+
+
diff --git a/src/plugins/heatmap/heatmapgui.cpp b/src/plugins/heatmap/heatmapgui.cpp
index ba94ceeb153e..cfc9ca6d0f7a 100644
--- a/src/plugins/heatmap/heatmapgui.cpp
+++ b/src/plugins/heatmap/heatmapgui.cpp
@@ -9,10 +9,24 @@
* 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
+#include
+#include
+#include
//standard includes
@@ -21,79 +35,142 @@ HeatmapGui::HeatmapGui( QWidget* parent, Qt::WFlags fl )
{
setupUi( this );
- // Below is an example of how to make the translators job
- // much easier. Please follow this general guideline for LARGE
- // pieces of text. One-liners can be added in the .ui file
-
- // Note: Format does not relate to translation.
- QString format( "
" );
-
- // Note: Translatable strings below
- QString text = format
- .arg( tr( "Welcome to your automatically generated plugin!" ) )
- .arg( tr( "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." ) )
- .arg( tr( "Documentation:" ) )
- .arg( tr( "You really need to read the QGIS API Documentation now at:" ) )
- .arg( tr( "In particular look at the following classes:" ) )
- .arg( table )
- .arg( "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." )
- .arg( tr( "QgsPlugin is an ABC that defines required behaviour your plugin must provide. See below for more details." ) )
- .arg( tr( "What are all the files in my generated plugin directory for?" ) )
- .arg( tr( "This is the generated CMake file that builds the plugin. You should add you application specific dependencies and source files to this file." ) )
- .arg( tr( "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 instance of the QgisPlugin interface 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." ) )
- .arg( tr( "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)." ) )
- .arg( tr( "This is the concrete class where application logic for the above mentioned dialog should go. The world is your oyster here really...." ) )
- .arg( tr( "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. (':/Homann/'). 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." ) )
- .arg( tr( "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." ) )
- .arg( tr( "This file contains the documentation you are reading now!" ) )
- .arg( tr( "Getting developer help:" ) )
- .arg( tr( "For Questions and Comments regarding the plugin builder template and creating your features in QGIS using the plugin interface please contact us via:" ) )
- .arg( tr( "
the QGIS developers mailing list, or
IRC (#qgis on freenode.net)
" ) )
- .arg( tr( "QGIS is distributed under the Gnu Public License. If you create a useful plugin please consider contributing it back to the community." ) )
- .arg( tr( "Have fun and thank you for choosing QGIS." ) );
-
- textBrowser->setHtml( text );
+ // Adding point layers to the mInputVectorCombo
+ QMap mapLayers = QgsMapLayerRegistry::instance()->mapLayers();
+ QMapIterator layers(mapLayers);
+
+ while( layers.hasNext() )
+ {
+ layers.next();
+ QgsVectorLayer* vl = qobject_cast(layers.value());
+ if( vl->geometryType() == QGis::Point )
+ {
+ mInputVectorCombo->addItem( vl->name(), QVariant( vl->id() ) );
+ }
+ }
+
+ // Adding GDAL drivers with CREATE to the mFormatCombo
+ 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 ) )
+ {
+ // Add LongName text, shortname variant; GetDescription actually gets the shortname
+ mFormatCombo->addItem( nthDriver->GetMetadataItem( GDAL_DMD_LONGNAME ), QVariant( nthDriver->GetDescription() ) );
+ // Add the drivers and their extensions to a map for filename correction
+ mExtensionMap.insert( nthDriver->GetDescription(), nthDriver->GetMetadataItem( GDAL_DMD_EXTENSION ) );
+ }
+ }
+
+ //finally set right the ok button
+ enableOrDisableOkButton();
}
HeatmapGui::~HeatmapGui()
{
}
-void HeatmapGui::on_buttonBox_accepted()
+void HeatmapGui::on_mButtonBox_accepted()
{
- //close the dialog
+ // 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 mapLayers = QgsMapLayerRegistry::instance()->mapLayers();
+ QMapIterator layers(mapLayers);
+
+ while( layers.hasNext() )
+ {
+ layers.next();
+ QgsVectorLayer* vl = qobject_cast(layers.value());
+ dummyText = vl->id();
+ if( dummyText.toInt() == myLayerId )
+ {
+ inputLayer = vl;
+ }
+ }
+
+ // The buffer distance
+ dummyText = mBufferLineEdit->text();
+ bufferDistance = dummyText.toInt();
+ // 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.") );
+ }
+ QString suffix = myFileInfo.suffix();
+ if( suffix.isEmpty() )
+ {
+ outputFormat = mFormatCombo->itemData( mFormatCombo->currentIndex() ).toString();
+ QMap::const_iterator it = mExtensionMap.find( outputFormat );
+ if( it != mExtensionMap.end() && it.key() == outputFormat )
+ {
+ outputFileName.append(".");
+ outputFileName.append( it.value() );
+ }
+ }
+
+ // emit
+ emit createRaster( inputLayer, bufferDistance, decayRatio, outputFileName, outputFormat );
+ //and finally
accept();
}
-void HeatmapGui::on_buttonBox_rejected()
+void HeatmapGui::on_mButtonBox_rejected()
{
reject();
}
-void HeatmapGui::on_buttonBox_helpRequested()
+void HeatmapGui::on_mButtonBox_helpRequested()
+{
+ QgsContextHelp::run( metaObject()->className() );
+}
+
+void HeatmapGui::on_mBrowseButton_clicked()
{
- QgsContextHelp::run( context_id );
+ 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::enableOrDisableOkButton()
+{
+ bool enabled = true;
+ QString filename = mOutputRasterLineEdit->text();
+ QFileInfo theFileInfo( filename );
+ if( filename.isEmpty() || !theFileInfo.dir().exists() )
+ {
+ enabled = false;
+ }
+ mButtonBox->button( QDialogButtonBox::Ok )->setEnabled( enabled );
+}
diff --git a/src/plugins/heatmap/heatmapgui.h b/src/plugins/heatmap/heatmapgui.h
index 491363ab6bb3..39335ef48a63 100644
--- a/src/plugins/heatmap/heatmapgui.h
+++ b/src/plugins/heatmap/heatmapgui.h
@@ -15,6 +15,7 @@
#include
#include
+#include "qgsvectorlayer.h"
/**
@author Tim Sutton
*/
@@ -26,12 +27,26 @@ class HeatmapGui : public QDialog, private Ui::HeatmapGuiBase
~HeatmapGui();
private:
- static const int context_id = 0;
+ QMap mExtensionMap;
+ void enableOrDisableOkButton();
private slots:
- void on_buttonBox_accepted();
- void on_buttonBox_rejected();
- void on_buttonBox_helpRequested();
+ void on_mButtonBox_accepted();
+ void on_mButtonBox_rejected();
+ void on_mButtonBox_helpRequested();
+ void on_mBrowseButton_clicked(); // Function to open the file dialog
+
+ 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 );
};
diff --git a/src/plugins/heatmap/heatmapguibase.ui b/src/plugins/heatmap/heatmapguibase.ui
index 6762337a0f2a..3e72ee69e0fb 100644
--- a/src/plugins/heatmap/heatmapguibase.ui
+++ b/src/plugins/heatmap/heatmapguibase.ui
@@ -1,76 +1,221 @@
-
+
+HeatmapGuiBase
-
-
+
+ 00
- 584
- 435
+ 400
+ 260
-
- QGIS Plugin Template
+
+ Heatmap Plugin
-
-
+
+
-
-
- 9
-
-
- 6
-
-
-
-
-
- 5
- 1
- 0
- 0
-
-
-
-
- Sans Serif
- 24
- 75
- false
- true
- false
- false
-
-
-
- Plugin Template
-
-
- Qt::AlignCenter
-
-
-
-
-
-
- true
-
-
-
-
-
-
- Qt::Horizontal
-
-
- QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::NoButton|QDialogButtonBox::Ok|QDialogButtonBox::SaveAll
-
-
-
-
+
+
+
+ 10
+ 20
+ 110
+ 21
+
+
+
+ Input Point Vector
+
+
+
+
+
+ 125
+ 20
+ 260
+ 25
+
+
+
+
+
+
+ 10
+ 65
+ 110
+ 16
+
+
+
+ Output Raster
+
+
+
+
+
+ 125
+ 60
+ 230
+ 25
+
+
+
+
+
+
+ 355
+ 60
+ 30
+ 25
+
+
+
+ Qt::ClickFocus
+
+
+ ...
+
+
+ false
+
+
+
+
+
+ 10
+ 225
+ 375
+ 30
+
+
+
+ QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok
+
+
+
+
+
+ 10
+ 140
+ 370
+ 80
+
+
+
+ Heatmap Point Attributes
+
+
+
+
+ 10
+ 27
+ 101
+ 16
+
+
+
+ Buffer Radius
+
+
+
+
+
+ 10
+ 56
+ 101
+ 16
+
+
+
+ Decay Ratio
+
+
+
+
+
+ 110
+ 20
+ 113
+ 25
+
+
+
+ 10
+
+
+
+
+
+ 110
+ 50
+ 113
+ 25
+
+
+
+ 0.5
+
+
+
+
+
+
+ 10
+ 105
+ 110
+ 15
+
+
+
+ Output Format
+
+
+
+
+
+ 125
+ 100
+ 260
+ 25
+
+
+
-
-
+
+
+ mButtonBox
+ accepted()
+ HeatmapGuiBase
+ accept()
+
+
+ 195
+ 123
+
+
+ 199
+ 79
+
+
+
+
+ mButtonBox
+ rejected()
+ HeatmapGuiBase
+ reject()
+
+
+ 195
+ 123
+
+
+ 199
+ 79
+
+
+
+
From 9f7382c3e433097075661c064ba961962fd50c62 Mon Sep 17 00:00:00 2001
From: Arunmozhi
Date: Fri, 3 Feb 2012 19:27:51 +0530
Subject: [PATCH 3/8] [useless] saving code in midway
---
src/plugins/heatmap/heatmap.cpp | 88 ++++++++++++++++++++++++++++-----
src/plugins/heatmap/heatmap.h | 30 +++++------
2 files changed, 92 insertions(+), 26 deletions(-)
diff --git a/src/plugins/heatmap/heatmap.cpp b/src/plugins/heatmap/heatmap.cpp
index 4e802a0d5caa..fb630d3bb37a 100644
--- a/src/plugins/heatmap/heatmap.cpp
+++ b/src/plugins/heatmap/heatmap.cpp
@@ -15,22 +15,26 @@
* *
***************************************************************************/
-//
-// QGIS Specific includes
-//
+// GDAL includes
+#include "gdal_priv.h"
+#include "cpl_string.h"
+#include "cpl_conv.h"
+// QGIS Specific includes
#include
#include
#include "heatmap.h"
#include "heatmapgui.h"
-//
-// Qt4 Related Includes
-//
+#include "qgsgeometry.h"
+#include "qgsvectorlayer.h"
+#include "qgsvectordataprovider.h"
+// Qt4 Related Includes
#include
#include
+#include
static const QString sName = QObject::tr( "Heatmap" );
@@ -40,12 +44,6 @@ static const QString sPluginVersion = QObject::tr( "Version 0.1" );
static const QgisPlugin::PLUGINTYPE sPluginType = QgisPlugin::UI;
static const QString sPluginIcon = ":/heatmap/heatmap.png";
-//////////////////////////////////////////////////////////////////////
-//
-// THE FOLLOWING METHODS ARE MANDATORY FOR ALL PLUGINS
-//
-//////////////////////////////////////////////////////////////////////
-
/**
* Constructor for the plugin. The plugin is passed a pointer
* an interface object that provides access to exposed functions in QGIS.
@@ -95,6 +93,10 @@ 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();
}
@@ -107,6 +109,68 @@ void Heatmap::unload()
delete mQActionPointer;
}
+// The worker
+void Heatmap::createRaster( QgsVectorLayer* theVectorLayer, int theBuffer, float theDecay, QString theOutputFilename, QString theOutputFormat )
+{
+ // TODO
+ // 1. Get ready the raster writer driver
+ // -> Write out a empty raster file
+ // 2. read a point from the vector layer
+ // 3. create a square grid for the buffer value and compute the grid
+ // 4. Read the corresponding grid from the file
+ // 5. Merge the old grid and new grid
+ // 6. repeast 2 to 5 untill all points are over
+ // 7. Close all the datasets and load the raster to the window
+
+ // generic variables
+ int xSize, ySize;
+ double xResolution, yResolution;
+
+ // Getting the rasterdataset in place
+ GDALAllRegister();
+
+ GDALDataset *heatmapDataset;
+ GDALDriver *poDriver;
+
+ poDriver = GetGDALDriverManager()->GetDriverByName( theOutputFormat );
+ if( poDriver == NULL )
+ {
+ QMessageBox::information( 0, tr("Error in Driver!"), tr("Cannot open the driver for the format specified") );
+ return;
+ }
+
+ // bounding box info
+ QgsRectangle myBBox = theVectorLayer->extent();
+ xSize = 500;
+ xResolution = myBBox.width()/xSize;
+ yResolution = xResolution;
+ ySize = myBBox.height()/yResolution;
+
+ double geoTransform[6] = { myBBox.xMinimum(), xResolution, 0, myBBox.yMinimum(), 0, yResolution };
+
+ heatmapDataset = poDriver->Create( theOutputFilename, xSize, ySize, 1, GDT_Float32, NULL );
+
+ heatmapDataset->SetGeoTransform( geoTransform );
+
+ GDALRasterBand *poBand;
+ poBand = heatmapDataset->GetRasterBand(1);
+
+ //
+ //Write the heatmapDataset->RasterIO function here
+ //
+
+ //Finally close the dataset
+ GDALClose( (GDALDatasetH) heatmapDataset );
+
+ // Openning 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;
+ }
+
+}
//////////////////////////////////////////////////////////////////////////
//
diff --git a/src/plugins/heatmap/heatmap.h b/src/plugins/heatmap/heatmap.h
index 33797a3692e5..822874debfe1 100644
--- a/src/plugins/heatmap/heatmap.h
+++ b/src/plugins/heatmap/heatmap.h
@@ -40,6 +40,7 @@
//QGIS includes
#include "../qgisplugin.h"
+#include "qgsvectorlayer.h"
//forward declarations
class QAction;
@@ -49,19 +50,15 @@ class QgisInterface;
/**
* \class Plugin
-* \brief [name] plugin for QGIS
-* [description]
+* \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
@@ -81,25 +78,30 @@ class Heatmap: public QObject, public QgisPlugin
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;
- ////////////////////////////////////////////////////////////////////
- //
+
// ADD YOUR OWN PROPERTY DECLARATIONS AFTER THIS POINT.....
- //
- ////////////////////////////////////////////////////////////////////
+ QList mRasterPoints;
};
#endif //Heatmap_H
From 2c2a84abda02d945dccaa126a374e961ea718357 Mon Sep 17 00:00:00 2001
From: Arunmozhi
Date: Sun, 5 Feb 2012 16:39:51 +0530
Subject: [PATCH 4/8] heatmap gets generated, working logic in place
---
src/plugins/heatmap/heatmap.cpp | 138 +++++++++++++++++++++++------
src/plugins/heatmap/heatmap.h | 2 -
src/plugins/heatmap/heatmapgui.cpp | 19 ++--
3 files changed, 127 insertions(+), 32 deletions(-)
diff --git a/src/plugins/heatmap/heatmap.cpp b/src/plugins/heatmap/heatmap.cpp
index fb630d3bb37a..030455b6cc17 100644
--- a/src/plugins/heatmap/heatmap.cpp
+++ b/src/plugins/heatmap/heatmap.cpp
@@ -35,6 +35,9 @@
#include
#include
#include
+#include
+
+#define NO_DATA -9999
static const QString sName = QObject::tr( "Heatmap" );
@@ -112,64 +115,149 @@ void Heatmap::unload()
// The worker
void Heatmap::createRaster( QgsVectorLayer* theVectorLayer, int theBuffer, float theDecay, QString theOutputFilename, QString theOutputFormat )
{
- // TODO
- // 1. Get ready the raster writer driver
- // -> Write out a empty raster file
- // 2. read a point from the vector layer
- // 3. create a square grid for the buffer value and compute the grid
- // 4. Read the corresponding grid from the file
- // 5. Merge the old grid and new grid
- // 6. repeast 2 to 5 untill all points are over
- // 7. Close all the datasets and load the raster to the window
-
// generic variables
int xSize, ySize;
double xResolution, yResolution;
+ double rasterX, rasterY;
// Getting the rasterdataset in place
GDALAllRegister();
- GDALDataset *heatmapDataset;
- GDALDriver *poDriver;
+ GDALDataset *emptyDataset;
+ GDALDriver *myDriver;
- poDriver = GetGDALDriverManager()->GetDriverByName( theOutputFormat );
- if( poDriver == NULL )
+ myDriver = GetGDALDriverManager()->GetDriverByName( theOutputFormat.toUtf8() );
+ if( myDriver == NULL )
{
- QMessageBox::information( 0, tr("Error in 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;
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] = { myBBox.xMinimum(), xResolution, 0, myBBox.yMinimum(), 0, yResolution };
+ double geoTransform[6] = { rasterX, xResolution, 0, rasterY, 0, yResolution };
- heatmapDataset = poDriver->Create( theOutputFilename, xSize, ySize, 1, GDT_Float32, NULL );
+ emptyDataset = myDriver->Create( theOutputFilename.toUtf8(), xSize, ySize, 1, GDT_Float32, NULL );
- heatmapDataset->SetGeoTransform( geoTransform );
+ emptyDataset->SetGeoTransform( geoTransform );
GDALRasterBand *poBand;
- poBand = heatmapDataset->GetRasterBand(1);
+ poBand = emptyDataset->GetRasterBand(1);
+ poBand->SetNoDataValue( NO_DATA );
- //
- //Write the heatmapDataset->RasterIO function here
- //
+ 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 );
+ }
- //Finally close the dataset
- GDALClose( (GDALDatasetH) heatmapDataset );
+ CPLFree( line );
+ //close the dataset
+ GDALClose( (GDALDatasetH) emptyDataset );
- // Openning the vector features
+ // 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 );
+
+ QgsFeature myFeature;
+
+ while( myVectorProvider->nextFeature( myFeature ) )
+ {
+ 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() );
}
//////////////////////////////////////////////////////////////////////////
diff --git a/src/plugins/heatmap/heatmap.h b/src/plugins/heatmap/heatmap.h
index 822874debfe1..bf0707d086cd 100644
--- a/src/plugins/heatmap/heatmap.h
+++ b/src/plugins/heatmap/heatmap.h
@@ -100,8 +100,6 @@ class Heatmap: public QObject, public QgisPlugin
//!pointer to the qaction for this plugin
QAction * mQActionPointer;
- // ADD YOUR OWN PROPERTY DECLARATIONS AFTER THIS POINT.....
- QList mRasterPoints;
};
#endif //Heatmap_H
diff --git a/src/plugins/heatmap/heatmapgui.cpp b/src/plugins/heatmap/heatmapgui.cpp
index cfc9ca6d0f7a..45c62eac8f83 100644
--- a/src/plugins/heatmap/heatmapgui.cpp
+++ b/src/plugins/heatmap/heatmapgui.cpp
@@ -43,7 +43,7 @@ HeatmapGui::HeatmapGui( QWidget* parent, Qt::WFlags fl )
{
layers.next();
QgsVectorLayer* vl = qobject_cast(layers.value());
- if( vl->geometryType() == QGis::Point )
+ if( ( vl ) && ( vl->geometryType() == QGis::Point ) )
{
mInputVectorCombo->addItem( vl->name(), QVariant( vl->id() ) );
}
@@ -94,10 +94,13 @@ void HeatmapGui::on_mButtonBox_accepted()
{
layers.next();
QgsVectorLayer* vl = qobject_cast(layers.value());
- dummyText = vl->id();
- if( dummyText.toInt() == myLayerId )
+ if ( vl )
{
+ dummyText = vl->id();
+ if( dummyText.toInt() == myLayerId )
+ {
inputLayer = vl;
+ }
}
}
@@ -116,14 +119,20 @@ void HeatmapGui::on_mButtonBox_accepted()
QMessageBox::information( 0, tr("Output filename is invalid!"), tr("Kindly enter a valid output file path and name.") );
}
QString suffix = myFileInfo.suffix();
+ // append the file format if the suffix is empty
if( suffix.isEmpty() )
{
outputFormat = mFormatCombo->itemData( mFormatCombo->currentIndex() ).toString();
QMap::const_iterator it = mExtensionMap.find( outputFormat );
if( it != mExtensionMap.end() && it.key() == outputFormat )
{
- outputFileName.append(".");
- outputFileName.append( it.value() );
+ // 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() );
+ }
}
}
From 16e52831ccb0e551048e710d683a84cc93bed76f Mon Sep 17 00:00:00 2001
From: Arunmozhi
Date: Sun, 5 Feb 2012 17:39:17 +0530
Subject: [PATCH 5/8] added context help text for en_US
---
resources/context_help/HeatmapGui-en_US | 27 +++++++++++++++++++++++++
1 file changed, 27 insertions(+)
create mode 100644 resources/context_help/HeatmapGui-en_US
diff --git a/resources/context_help/HeatmapGui-en_US b/resources/context_help/HeatmapGui-en_US
new file mode 100644
index 000000000000..dc785fe90ba3
--- /dev/null
+++ b/resources/context_help/HeatmapGui-en_US
@@ -0,0 +1,27 @@
+
Heatmap Plugin Help
+
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.
+
+
The Dialog Parameters
+
+
Input Point Vector
+
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 your layer.
+
+
Output Ratser
+
The output raster location and filename can be set by clicking the button next to the output raster textbox.
+Note:The file format extension need not be given. It is automatically added depending upon the output format you select.
+
+
Output Format
+
All the file creation supporting GDAL formats are available in the drop down list. Click and select the required output format for your file.
+Note: 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.
+
+
Heatmap Point Attributes
+
Buffer Radius
+
The buffer radius specifies the number of pixels or cells 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.
+Note: The value is always a whole number.
+
Decay Ratio
+
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.
+Example: 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.
+
+
Further Details
+
Contact the author through aruntheguy at gmail dot com
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 your layer.
+
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.
Output Ratser
The output raster location and filename can be set by clicking the button next to the output raster textbox.
-Note:The file format extension need not be given. It is automatically added depending upon the output format you select.
+Note:The file format is automatically added depending upon the output format selected, if not explicitly given.
Output Format
All the file creation supporting GDAL formats are available in the drop down list. Click and select the required output format for your file.
diff --git a/src/plugins/heatmap/heatmapgui.cpp b/src/plugins/heatmap/heatmapgui.cpp
index 45c62eac8f83..7b94e805c5f8 100644
--- a/src/plugins/heatmap/heatmapgui.cpp
+++ b/src/plugins/heatmap/heatmapgui.cpp
@@ -99,7 +99,7 @@ void HeatmapGui::on_mButtonBox_accepted()
dummyText = vl->id();
if( dummyText.toInt() == myLayerId )
{
- inputLayer = vl;
+ inputLayer = vl;
}
}
}
@@ -118,11 +118,14 @@ void HeatmapGui::on_mButtonBox_accepted()
{
QMessageBox::information( 0, tr("Output filename is invalid!"), tr("Kindly enter a valid output file path and name.") );
}
- QString suffix = myFileInfo.suffix();
+
+ // 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() )
{
- outputFormat = mFormatCombo->itemData( mFormatCombo->currentIndex() ).toString();
QMap::const_iterator it = mExtensionMap.find( outputFormat );
if( it != mExtensionMap.end() && it.key() == outputFormat )
{
@@ -136,7 +139,6 @@ void HeatmapGui::on_mButtonBox_accepted()
}
}
- // emit
emit createRaster( inputLayer, bufferDistance, decayRatio, outputFileName, outputFormat );
//and finally
accept();
From 412a146491de90c90ec181f6236b8cc26bb82642 Mon Sep 17 00:00:00 2001
From: Arunmozhi
Date: Mon, 6 Feb 2012 22:52:37 +0530
Subject: [PATCH 7/8] fixed o/p file err msg bug, i/p no layer bug, & added
progress dialog
---
src/plugins/heatmap/heatmap.cpp | 15 +++++++++++++++
src/plugins/heatmap/heatmapgui.cpp | 3 ++-
2 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/src/plugins/heatmap/heatmap.cpp b/src/plugins/heatmap/heatmap.cpp
index 030455b6cc17..124cdae20181 100644
--- a/src/plugins/heatmap/heatmap.cpp
+++ b/src/plugins/heatmap/heatmap.cpp
@@ -36,6 +36,7 @@
#include
#include
#include
+#include
#define NO_DATA -9999
@@ -189,11 +190,25 @@ void Heatmap::createRaster( QgsVectorLayer* theVectorLayer, int theBuffer, float
}
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
diff --git a/src/plugins/heatmap/heatmapgui.cpp b/src/plugins/heatmap/heatmapgui.cpp
index 7b94e805c5f8..19c595a09aa3 100644
--- a/src/plugins/heatmap/heatmapgui.cpp
+++ b/src/plugins/heatmap/heatmapgui.cpp
@@ -117,6 +117,7 @@ void HeatmapGui::on_mButtonBox_accepted()
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
@@ -179,7 +180,7 @@ void HeatmapGui::enableOrDisableOkButton()
bool enabled = true;
QString filename = mOutputRasterLineEdit->text();
QFileInfo theFileInfo( filename );
- if( filename.isEmpty() || !theFileInfo.dir().exists() )
+ if( filename.isEmpty() || !theFileInfo.dir().exists() || ( mInputVectorCombo->count() == 0 ) )
{
enabled = false;
}
From a22f1e37576a3e0eb284eee8e5d55be4548f3ea3 Mon Sep 17 00:00:00 2001
From: Arunmozhi
Date: Mon, 6 Feb 2012 23:12:15 +0530
Subject: [PATCH 8/8] fixed NULL buffer value bug
---
src/plugins/heatmap/heatmapgui.cpp | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/src/plugins/heatmap/heatmapgui.cpp b/src/plugins/heatmap/heatmapgui.cpp
index 19c595a09aa3..18d3d7429bfe 100644
--- a/src/plugins/heatmap/heatmapgui.cpp
+++ b/src/plugins/heatmap/heatmapgui.cpp
@@ -107,6 +107,11 @@ void HeatmapGui::on_mButtonBox_accepted()
// 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();