forked from carsonfarmer/cartogram
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCartogram.py
92 lines (84 loc) · 4.16 KB
/
Cartogram.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#-----------------------------------------------------------
#
# Cartogram Creator
#
# A QGIS plugin for creating cartograms based on polygon
# shapefile. Uses algorithm proposed in:
# Dougenik, J. A, N. R. Chrisman, and D. R. Niemeyer. 1985.
# "An algorithm to construct continuous cartograms."
# Professional Geographer 37:75-81
#
# This plugin uses python code adapted from Eric Wolfs pyCartogram.py
# See plugin about dialog for more information.
#
# EMAIL: carson.farmer (at) gmail.com
# WEB : www.carsonfarmer.com
#
#-----------------------------------------------------------
#
# licensed under the terms of GNU GPL 2
#
# 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.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
#---------------------------------------------------------------------
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
from qgis.gui import *
import doCartogram
import resources
import os
class CartogramPlugin:
def __init__(self, iface):
# Save a reference to the QGIS iface
self.iface = iface
def initGui(self):
# Create projection action
self.action = QAction(QIcon(":/cartogram.png"), "Cartogram Creator", self.iface.mainWindow())
self.action.setWhatsThis("Tool for creating rubber-sheet cartogram")
QObject.connect(self.action, SIGNAL("activated()"), self.run)
# Create about button
self.helpaction = QAction(QIcon(":/cartogramhelp.png"), "About", self.iface.mainWindow())
self.helpaction.setWhatsThis("Help for Cartogram Creator")
QObject.connect(self.helpaction, SIGNAL("activated()"), self.helprun)
# Add to the main toolbar
self.iface.addToolBarIcon(self.action)
self.iface.addPluginToMenu("&Cartogram Creator", self.action)
self.iface.addPluginToMenu("&Cartogram Creator", self.helpaction)
def unload(self):
# Remove the plugin
self.iface.removePluginMenu("&Cartogram Creator", self.action)
self.iface.removePluginMenu("&Cartogram Creator", self.helpaction)
self.iface.removeToolBarIcon(self.action)
def helprun(self):
# print "Help pressed..."
infoString = QString("Written by Carson Farmer\[email protected]\n")
infoString = infoString.append("www.geog.uvic.ca/spar/carson\n")
infoString = infoString.append("Code adapted from Eric Wolfs pyCartogram.py\n\n"
+ "This tool creates a new shapefile based on "
+ "the input shapefile with each polygon vertex shifted. "
+ "Should be called iteratively to get the results desired.\n")
infoString = infoString.append("Based on a translation of Andy Agenda's ESRI ArcScript"
+ "for contiguous cartograms:\nhttp://arcscripts.esri.com/details.asp?dbid=10509\n")
infoString = infoString.append("He based the routine on Charles B. Jackel's script in:\n"
+"'Using ArcView to Create Contiguous and Noncontiguous Area Cartograms,'"
+"Cartography and Geographic Information Systems, vol. 24, no. 2, 1997, pp. 101-109\n")
infoString = infoString.append("Charles B. Jackel based his script on the method proposed in:\n"
+ "Dougenik, J. A, N. R. Chrisman, and D. R. Niemeyer. 1985. 'An algorithm "
+ "to construct continuous cartograms.' Professional Geographer 37:75-81")
QMessageBox.information(self.iface.mainWindow(),"About Cartogram Creator",infoString)
def run(self):
d = doCartogram.Dialog(self.iface)
d.exec_()