2

I need a help on trying to use the Hot Spot Analysis Plugin on QGIS Noosa. I am not able to install the module "moran".

  • intall using something like this gis.stackexchange.com/a/269766/49538 – Fran Raga Apr 9 at 7:42
  • What kind of error do you encounter when you try to use the plugin? – Kadir Şahbaz Apr 9 at 21:16
  • Hi Kadir, this is the error I found: This is the error I found :Couldn't load plugin 'HotspotAnalysis' due to an error when calling its classFactory() method ModuleNotFoundError: No module named 'moran'. – user140183 Apr 10 at 7:54
  • 1
    Please add the error message to your question. – Kadir Şahbaz Apr 10 at 9:20
  • Did you follow the instructions to install Pysal, as mentioned in the plugin description: "The plugin requires Pysal (see repository for installation instruction)" ? – csk Apr 11 at 19:01
2

The module moran is a part of pysal package. So you can't install it using pip or something.

Developers of pysal changed the folder structure of the package. This is probably why you can't use the plugin or are getting errors. Hotspot Analysis plugin needs an update, but you follow such a temporary solution I explain below.

If you look at hotspot_analysis.py file (QGIS 3 Plugins folder location), you will see the lines (line numbers may be different than yours. I skipped the indentation).

Line 39 from pysal.esda.getisord import *
Line 40 from pysal.esda.moran import *
Line 41 from pysal.weights.Distance import DistanceBand
.
Line 472 thresh = pysal.min_threshold_dist_from_shapefile(path)
.
Line 600 moran = pysal.Moran(y, w)
.
Line 608 w = pysal.knnW_from_shapefile(layerName.split("|")[0], k=weightValue, p=1)
.
Line 613 w = pysal.queen_from_shapefile(layerName.split("|")[0])

Change those lines into the lines below, respectively.

from pysal.explore.esda.getisord import *
from pysal.explore.esda.moran import *
from pysal.lib.weights import DistanceBand, Queen, KNN, user
.
thresh = user.min_threshold_dist_from_shapefile(path)
.
moran = Moran(y, w)
.
w = KNN.from_shapefile(layerName.split("|")[0], k=weightValue, p=1)
.
w = Queen.from_shapefile(layerName.split("|")[0])

Save the changes and re-activate the plugin or re-open QGIS.

  • Thanks Kadir. You are simply Amazing. Your recommendations worked perfectly. – user140183 Apr 10 at 9:12
  • But it solves temporarily. When I select a line layer, I encounter an error, as an example. – Kadir Şahbaz Apr 10 at 9:17
  • I am afraid I also encountered an error as well while performing the analysis. This is the error I got "TypeError: ufunc 'multiply' did not contain a loop with signature matching types dtype(' " Any idea how to work around this. – user140183 Apr 10 at 9:27
  • If I use a 'string' field, I get the same error, too. I have no idea. – Kadir Şahbaz Apr 10 at 9:35
  • This explains why you can only use a numeric field while using ArcGIS. I will try to use a numeric field. Thanks – user140183 Apr 10 at 9:40

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.