Git Product home page Git Product logo

cartogram3's Introduction

QGIS3 cartogram3 plugin

This plugin creates continous cartograms (a.k.a. anamorphic maps) from polygon layers.

It is a port of the cartogram plugin by Morten Wulff and Carson Farmer to QGIS 3, Python 3 and PyQt5. It also features a few improvements, such as parallel processing (using multiprocessing), the option to select multiple variables to batch-produce cartograms, and the possibility to use a maximum total error threshold as a stop condition in addition to the number of iterations. Since version 3.1.0 (December 2021), the plugin also provides a Processing Toolbox algorithm that can be used on its own or, e.g., in model builder models.

Like its predecessors, this plugin implements the algorithm proposed by:

Dougenik, J. A, N. R. Chrisman, and D. R. Niemeyer. 1985. "An algorithm to construct continuous cartograms." Professional Geographer 37:75-81

Usage

  • If you have not done it, install the plugin from QGIS’ plugin manager.

  • Open a polygon dataset with an absolute count1 of a certain variable, such as human population. If you do not have an own dataset immediately available, add the supplied sample data set from the plugin’s menu.
    In this example we use a choropleth map of the population of Austria’s NUTS2 regions. Austria is an excellent example, as the only major city of the country and its metropolitan area are home to roughly a third of the country’s inhabitants. As you can see, the map is styled with graduated symbols representing the respective region’s population density. We also added labels showing the population density.
    Choropleth map of the population of Austria by NUTS2 regions

  • Fire up the cartogram3 plugin. Select which layer you want to compute a cartogram of, and choose one or more attributes for batch processing (Pro tip: at austromorph we use this feature to create animation frames). Then, define stop conditions: since the algorithm is iterative, the results get gradually better with every repetition. The more iterations, the better; but also: the more iterations, the longer the computation time. We recommend an absolute minimum of 10 iterations. If the requested quality is met earlier, i.e. the average areal error of the cartogram is smaller than the set value, the computation stops earlier.
    cartogram3 user interface

  • Depending on the detail of your dataset and on your computer’s power, it takes from seconds to hours until you receive your results. The progress is shown in the QGIS message bar, also you can always click the cancel button to stop the computation early. The algorithm iterates over every point × every polygon, and thus scales extremely poorly. Consider simplifying your input dataset beforehand.
    Cartogram of the population of Austria by NUTS2 regions

[1] Why an absolute count of a variable? Quote from the worldmapper.org FAQ:

Q. Why don't you have a map of population density or births per thousand? A. The maps are best understood as pie charts where the segment of the pie is reshaped to look like a country. Then the area of that country is adjusted according to the proportion of the world total of a variable that is found there. Just as a pie chart would. As such, we can only map counts or totals. We cannot map rates because they are not additive, that is to say that they do not add up to a meaningful total. To return to the pie chart analogy, you would not draw a pie chart of population density but one of total population.

License

QGIS3 cartogram3

Copyright (C) 2017 Christoph Fink

QGIS Cartogram – a plugin for creating cartograms from polygon layers

Copyright (C) 2015 Morten Wulff
Copyright (C) 2013 Carson Farmer

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 3 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.

Sample data

The supplied sample dataset is combined from two data sources:

cartogram3's People

Contributors

christophfink avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

cartogram3's Issues

Handling Null Values

The plugin requires all fields be assigned a value (i.e., cannot handle null values). This requires the user to either manually enter 0 or to use a layout with the areas with null values being omitted. It'd be great to have an option to treat nulls as 0 or to leave the areas with null values unchanged in area.

Plugin crash in Qgis 3.22

Hello, I have a problem with the Cartogram plugin in QGIS 3.16.12 , 12 and 13.
It seems that the grass plugin is the problem.
In a test with QGIS 3.16.8 with Grass 7.8.5 cortogram works.
Does the method of calling GRASS change between these versions?

I also tried to start cartogram from the github master, it does not work.

Sincerely Alexandre Granié

Plugin does not work on Python < 3.8

Hi,
I heard and seen a lot of good things about the cartogram3 plugin, thank you for that. Unfortunately it wasn't possible for me to install it on various machines. I tried it on different PCs, all Win10.
When I try to install the plugin (doesn't matter which version of the plugin, or QQIS version, I tried 5 different ones, 3.24 down to 3.1). The error message is always the same:

Konnte Erweiterung 'cartogram3' nicht laden aufgrund eines Fehlers beim Aufruf der classFactory() Methode

SyntaxError: invalid syntax
Traceback (most recent call last):
File "C:/PROGRA1/QGIS31.16/apps/qgis-ltr/./python\qgis\utils.py", line 334, in startPlugin
plugins[packageName] = package.classFactory(iface)
File "C:/Users/USER/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\cartogram3_init
.py", line 34, in classFactory
from .cartogram3 import Cartogram
File "C:/PROGRA1/QGIS31.16/apps/qgis-ltr/./python\qgis\utils.py", line 793, in _import
mod = _builtin_import(name, globals, locals, fromlist, level)
File "C:/Users/USER/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\cartogram3\cartogram3.py", line 9, in
from .lib import CartogramUserInterfaceMixIn, CartogramWorkOrchestratorMixIn
File "C:/PROGRA1/QGIS31.16/apps/qgis-ltr/./python\qgis\utils.py", line 793, in _import
mod = builtin_import(name, globals, locals, fromlist, level)
File "C:/Users/USER/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\cartogram3\lib_init
.py", line 5, in
from .cartogramprocessingprovider import CartogramProcessingProvider
File "C:/PROGRA1/QGIS31.16/apps/qgis-ltr/./python\qgis\utils.py", line 793, in _import
mod = _builtin_import(name, globals, locals, fromlist, level)
File "C:/Users/USER/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\cartogram3\lib\cartogramprocessingprovider.py", line 12, in
from .cartogramprocessingalgorithm import CartogramProcessingAlgorithm
File "C:/PROGRA1/QGIS31.16/apps/qgis-ltr/./python\qgis\utils.py", line 793, in _import
mod = _builtin_import(name, globals, locals, fromlist, level)
File "C:/Users/USER/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\cartogram3\lib\cartogramprocessingalgorithm.py", line 24, in
from .cartogramfeatures import CartogramFeatures
File "C:/PROGRA1/QGIS31.16/apps/qgis-ltr/./python\qgis\utils.py", line 793, in _import
mod = _builtin_import(name, globals, locals, fromlist, level)
File "C:/Users/USER/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\cartogram3\lib\cartogramfeatures.py", line 31
def _cache(user_function, /):
^
SyntaxError: invalid syntax

Python-Version: 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)]
QGIS-Version: 3.16.6-Hannover Hannover, bfd36fddc9

Python-Pfad:
C:/PROGRA1/QGIS31.16/apps/qgis-ltr/./python
C:/Users/USER/AppData/Roaming/QGIS/QGIS3\profiles\default/python
C:/Users/USER/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins
C:/PROGRA1/QGIS31.16/apps/qgis-ltr/./python/plugins
C:\PROGRA1\QGIS31.16\apps\Python37
C:\PROGRA1\QGIS31.16\apps\Python37\Scripts
C:\Program Files\QGIS 3.16\bin\python37.zip
C:\PROGRA1\QGIS31.16\apps\Python37\DLLs
C:\PROGRA1\QGIS31.16\apps\Python37\lib
C:\Program Files\QGIS 3.16\bin
C:\Users\USER\AppData\Roaming\Python\Python37\site-packages
C:\PROGRA1\QGIS31.16\apps\Python37\lib\site-packages
C:\PROGRA1\QGIS31.16\apps\Python37\lib\site-packages\win32
C:\PROGRA1\QGIS31.16\apps\Python37\lib\site-packages\win32\lib
C:\PROGRA1\QGIS31.16\apps\Python37\lib\site-packages\Pythonwin
C:/Users/USER/AppData/Roaming/QGIS/QGIS3\profiles\default/python
C:\Users\USER\AppData\Roaming\QGIS\QGIS3\profiles\default\python\plugins\mmqgis/forms

On one machine the installation works, but when I start a process it just doesn't do anything. (the task is at 0% processor usage) and there is no change or process, that also happens when I start it from the toolbox.

Am I missing something here? It seems I am the only or first one to have this trouble, I didn't find a similar thread anywhere.

Anyways I would be very glad if you could help me, maybe (hopefully) it's something obvious and I am just an idiot.
Thanks in advance.
KaR

Memory management on Windows

It seems (rel. issue #16) that we can run out of memory on Windows despite deleting/unsetting unused objects for Python garbage collection to kick in.
What can we do to avoid running out of ram?

Cartogram computation never moves beyond 1%

Hi

Thanks also for the work. I am on Catalina using 3.22 and although Cartogram no longer seems to crash QGIS loading other layers (or at least vector ones), when I try to compute a cartogram it seems to enter into a perpetual loop. I get the progress bar and then nothing happens. The test layer is small - 300K with 151 features. Most are convex so the calculations should be straightforward. I’m not sure if others have been having this issue.

Best Regards,

David Walker

Mailing, mailing over the EM waves.

Originally posted by @djwalkr in #22 (comment)

QgsGeometry.set() is deprecated

2019-05-22T21:52:45 WARNING warning:/home/christoph/.local/share/QGIS/QGIS3/profiles/default/python/plugins/cartogram3/cartogram_worker.py:298: DeprecationWarning: QgsGeometry.set() is deprecated
features[featureId].set(abstractGeometry)

         traceback: File "/home/christoph/.local/share/QGIS/QGIS3/profiles/default/python/plugins/cartogram3/cartogram_worker.py", line 135, in run
          self.transformFeatures()
          File "/home/christoph/.local/share/QGIS/QGIS3/profiles/default/python/plugins/cartogram3/cartogram_worker.py", line 298, in transformFeatures
          features[featureId].set(abstractGeometry)

AttributeError: type object 'QgsMessageBar' has no attribute 'INFO'

Fresh install of QGIS3, and tried to run Cartogram 3, but throwing error:

Traceback (most recent call last): File "C:/Users/skipp/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\cartogram3\cartogram3.py", line 346, in run QgsMessageBar.INFO AttributeError: type object 'QgsMessageBar' has no attribute 'INFO'

Using the Austria example dataset...

move ALL blocking functions into Worker

At the moment we create a memory layer in the main thread. This potentially blocks the ui for a noticable.
we can also move this into the worker, and iterate over all fieldNames there
also, split up the main threads workerFinished into layerFinished and workerFinished

Update translations

Update translations for:

  • German
  • Spanish
  • Danish (who contributed this?)

Maybe add new translations for:

  • French
  • Finnish
  • ...

improve performance

The current solution of sending WKT strings into the worker’s queues performs almost as bad as the original one-threaded implementation.
We don’t use QgsGeometry, because its asPolygon() and asMultiPolygon() segfault on some platforms (http://hub.qgis.org/issues/16198) – without a chance of catching an exception.

A QgsFeature’s QgsGeometry can return its QgsAbstractGeometry, which in turn allows to directly access its vertices. That’s exactly what we want!

http://qgis.org/api/classQgsGeometry.html
http://qgis.org/api/classQgsAbstractGeometry.html

TypeError: QgsMapLayer.exportNamedStyle(): argument 2 has unexpected type 'str'

bug report submitted via e-mail:

When trying to use cartogram I get following message (my data and demo dat)
Any idea to resolve this ?

2018-11-19T13:13:40 WARNING Traceback (most recent call last):
File "C:[…]/python/plugins\cartogram3\cartogram3.py", line 317, in run
self.inputLayer.exportNamedStyle(self.inputLayerStyle, "")
TypeError: QgsMapLayer.exportNamedStyle(): argument 2 has unexpected type 'str'

Crashing

I tried installing cartogram3 on QGIS 3.20.0-Odense on MacOS 11.4. If I try to activate it QGIS crashes unceremoniously

Add sample data

It would be nice if users can quickly load a sample data set to try out the plugin (the QGIS2 plugins had this feature)
A nice place would be to add a button to the "you need at least one polygon layer" error message.

TypeError: QgsMapLayer.exportNamedStyle(): not enough arguments

Hi,

When I compute cartogram3 (the version you put on the "TypeError: QgsMapLayer.exportNamedStyle(): argument 2 has unexpected type 'str'" thread) on the austrian data and my own data, I have this error message.

2018-11-26T14:10:47 WARNING Traceback (most recent call last):
File "C:/Users/ndevienne/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\cartogram3\cartogram3.py", line 317, in run
self.inputLayer.exportNamedStyle(self.inputLayerStyle)
TypeError: QgsMapLayer.exportNamedStyle(): not enough arguments

I tried to understand the code, but I don't read Python ^^

Could you help me ?

implement Opti-DNC

In this article Dougenik et al.’s algorithm is improved and optimised:

First, it provides a mathematical condition
for topology preservation. Second, new transformation equations that meet this condition are deduced from
mathematics, which simultaneously optimize the global elasticity coefficient, a key parameter that greatly
impacts the convergence rate of the rubber-sheet algorithm and the topological integrity of its generated
cartograms. Last, the new algorithm simplifies the way of generating transforming forces in DCN and
improves its efficiency of geometric transformation.

Just hangs in 0% with this dataset

Is something wrong with the data? Too big?

Cartogram either hangs in 0% or crashes immediately QGIS (tested with 3.13 and 3.14 on mac). With the bundled sample data on same QGIS cartogram works fine.

image

Archive.zip

Bug on MacOS

Hi there,

I installed the plugin through the QGIS plugin downloader and it keeps crashing, opening 10 new QGIS windows and actually not running the cartogram algorithm.
I tried downloading directly the latest version using the source code zip, but I get this error:

Couldn't load plugin '__MACOSX/cartogram3-3.1.2' 
ModuleNotFoundError: No module named '__MACOSX/cartogram3-3' 

Wondering if it's just a MacOS issue as I have not found anyone else complaining about this online.

I teach GIS and have been using this plugin last year, was hoping I could keep teaching it to the current and next cohorts!

Thanks

Save iteration progress after crash?

QGIS will usually crash for me when I try to do a cartogram with lots of features and a large number of iterations (right now, for instance, I'm trying to do 100 iterations on 2850 features). I'm presuming it has something to do with memory or cpu or something. (I'm using cartogram 3.0 from the plugin manager on QGIS 3.0.3 on Windows 10.)

My main request though is, for instance, if it crashes during, say, iteration 30 of 100, can I get a dump of iteration 29? Because it might be good enough, but I don't want to run the whole thing again just to have it crash again on iteration 23 for instance.

Fix invalid polygons in input data set

Some input data sets, including some versions of the Natural Earth adm0 layers, seem to contain invalid polygons, and it is still surprisingly easy to produce invalid geometries, e.g., when reprojecting data sets.

Let’s apply a zero-width buffer to any input data set in order to fix the most common problems. This is not very costly in terms of computation, and helps avoid frustration down the road.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.