4

I am using QGIS 2.16 and trying to compute distances between two points using the MMQGIS plug-in (Hub -distance). This worked like a charm, but recently I have been getting a Python Error whenever I change the measurement unit from "layer unit" to any of the other. The error message is:

"   Traceback (most recent call last):
              File "/Users/henry/.qgis2/python/plugins/mmqgis/mmqgis_dialogs.py",   line 1727, in run
                nameattributename, units, addlines, savename, evenly_distributed, 1)
              File "/Users/henry/.qgis2/python/plugins/mmqgis/mmqgis_library.py", line 4169, in mmqgis_hub_distance
                hubdist = mmqgis_distance(source[0], hub[0])
              File "/Users/henry/.qgis2/python/plugins/mmqgis/mmqgis_library.py", line 544, in mmqgis_distance
                start_lon = start.x() * math.pi / 180
            NameError: global name 'math' is not defined"

Does anybody know how to resolve this issue?

  • 1
    It looks like the math module is not installed properly. This is something that is installed by default when python is installed. I suggest reinstalling QGIS or python. – Fezter Oct 24 '16 at 22:07
5

If you want to fix it by yourself: Go to Plugin-Directory mmqgis and open the file mmqgis_library.py there you'll find the lines:

# Used instead of "import math" so math functions can be used without "math." prefix
from math import *

So, everywhere in the file, you have to delete math. in any occurence, eg. math.cos becomes just cos. Anyway, the author should be informed!!

  • Thanks a lot! It works like a charm again now. I also informed the author. – heste Oct 28 '16 at 9:25
4

This is almost certainly a bug in the plugin. It might be related to this SE post.

I suggest you send a bug report to the developer of the plugin.

First, though, make sure you're using an updated version of the plugin. Michael Minn is the developer: http://michaelminn.com/linux/mmqgis/

  • Thanks Alex! I did use the updated version of the plugin, changing the code resolved the issue though. – heste Oct 28 '16 at 9:27
  • Worth reporting, @heste, so that it can be fixed for others =). Ah, I see you have. Nicely done! – Alex Leith Oct 29 '16 at 7:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.