danioxoli / HotSpotAnalysis_Plugin

A QGIS plugin for hotspot analysis
GNU General Public License v3.0
55 stars 12 forks source link

QGIS 2 for Mac from Homebrew does not recognise the layers. #6

Closed dheerajchand closed 6 years ago

dheerajchand commented 6 years ago

Hi, I am getting this error in MacOS QGIS from Homebrew. Can someone help?

An error has occurred while executing Python code: TypeError: 'NoneType' object is not iterable Traceback (most recent call last): File "/Users/dheerajchand/.qgis2/python/plugins/HotspotAnalysis/hotspot_analysis.py", line 539, in run layers, layers_shp = self.loadLayerList() TypeError: 'NoneType' object is not iterable Python version: 2.7.14 (default, Mar 9 2018, 23:57:12) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)] QGIS version: 2.18.18 Las Palmas, exported Python Path: /usr/local/Cellar/qgis2/2.18.18/QGIS.app/Contents/MacOS/../Resources/python/plugins/processing /usr/local/Cellar/qgis2/2.18.18/QGIS.app/Contents/MacOS/../Resources/python /Users/dheerajchand/.qgis2/python /Users/dheerajchand/.qgis2/python/plugins /usr/local/Cellar/qgis2/2.18.18/QGIS.app/Contents/MacOS/../Resources/python/plugins /usr/local/opt/gdal2-python/lib/python2.7/site-packages /usr/local/lib/qt-4/python2.7/site-packages /usr/local/opt/qgis2/libexec/python2.7/site-packages /usr/local/lib/python2.7/site-packages /usr/local/opt/python@2/Frameworks/Python.framework/Versions/2.7/lib/python27.zip /usr/local/opt/python@2/Frameworks/Python.framework/Versions/2.7/lib/python2.7 /usr/local/opt/python@2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin /usr/local/opt/python@2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac /usr/local/opt/python@2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages /usr/local/opt/python@2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk /usr/local/opt/python@2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old /usr/local/opt/python@2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload /usr/local/opt/python@2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages /usr/local/opt/python@2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/geos /usr/local/opt/python@2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/wx-3.0-osx_cocoa /Users/dheerajchand/.qgis2//python /Users/dheerajchand/.qgis2/python/plugins/mmqgis/forms

danioxoli commented 6 years ago

Hi,

Looks like you are using an invalid input layer, i.e. not a shapefile. Alternatively, It can be both that you are running the process on a virtual attribute (e.g. deriving from a Join operation) or a virtual layer, which might not be recognized. Can you confirm?

Daniele

dheerajchand commented 6 years ago

It turns out that the I was running on a delimited text layer, which is treated as a virtual layer. I converted to shapefile and am now getting this error.


An error has occurred while executing Python code:

error: unpack requires a string argument of length 20 Traceback (most recent call last): File "/Users/dheerajchand/.qgis2/python/plugins/HotspotAnalysis/hotspot_analysis.py", line 524, in self.dlg.comboBox.currentIndexChanged.connect(lambda: self.load_comboBox()) File "/Users/dheerajchand/.qgis2/python/plugins/HotspotAnalysis/hotspot_analysis.py", line 465, in load_comboBox thresh = pysal.min_threshold_dist_from_shapefile(path) File "/usr/local/lib/python2.7/site-packages/pysal/weights/user.py", line 1079, in min_threshold_dist_from_shapefile points = get_points_array_from_shapefile(shapefile) File "/usr/local/lib/python2.7/site-packages/pysal/weights/util.py", line 1094, in get_points_array_from_shapefile data = get_points_array(f) File "/usr/local/lib/python2.7/site-packages/pysal/weights/util.py", line 1049, in get_points_array data = np.vstack([shape for shape in iterable]) File "/usr/local/lib/python2.7/site-packages/pysal/core/FileIO.py", line 252, in next r = self.read() File "/usr/local/lib/python2.7/site-packages/pysal/core/FileIO.py", line 313, in read row = self._read() File "/usr/local/lib/python2.7/site-packages/pysal/core/IOHandlers/pyShpIO.py", line 142, in _read rec = self.dataObj.get_shape(self.pos) File "/usr/local/lib/python2.7/site-packages/pysal/core/util/shapefile.py", line 362, in get_shape return self.shape.unpack(bufferIO(self.fileObj.read(byts))) File "/usr/local/lib/python2.7/site-packages/pysal/core/util/shapefile.py", line 584, in unpack return _unpackDict(cls.USTRUCT, dat) File "/usr/local/lib/python2.7/site-packages/pysal/core/util/shapefile.py", line 136, in _unpackDict fileObj.read(struct['size'])) error: unpack requires a string argument of length 20

Python version: 2.7.14 (default, Mar 9 2018, 23:57:12) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)] QGIS version: 2.18.18 Las Palmas, exported

Python Path: /usr/local/Cellar/qgis2/2.18.18/QGIS.app/Contents/MacOS/../Resources/python/plugins/processing /usr/local/Cellar/qgis2/2.18.18/QGIS.app/Contents/MacOS/../Resources/python /Users/dheerajchand/.qgis2/python /Users/dheerajchand/.qgis2/python/plugins /usr/local/Cellar/qgis2/2.18.18/QGIS.app/Contents/MacOS/../Resources/python/plugins /usr/local/opt/gdal2-python/lib/python2.7/site-packages /usr/local/lib/qt-4/python2.7/site-packages /usr/local/opt/qgis2/libexec/python2.7/site-packages /usr/local/lib/python2.7/site-packages /usr/local/opt/python@2/Frameworks/Python.framework/Versions/2.7/lib/python27.zip /usr/local/opt/python@2/Frameworks/Python.framework/Versions/2.7/lib/python2.7 /usr/local/opt/python@2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin /usr/local/opt/python@2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac /usr/local/opt/python@2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages /usr/local/opt/python@2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk /usr/local/opt/python@2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-old /usr/local/opt/python@2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload /usr/local/opt/python@2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages /usr/local/opt/python@2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/geos /usr/local/opt/python@2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/wx-3.0-osx_cocoa /Users/dheerajchand/.qgis2//python /Users/dheerajchand/.qgis2/python/plugins/mmqgis/forms

danioxoli commented 6 years ago

Now looks like a bad formatting for the attribute you are using, i.e. not a numeric one. Do you mind to send me for a test the shapefile you are using (by indicating also the name of the fields you want to analyse) at daniele.oxoli@polimi.it?

dheerajchand commented 6 years ago

Sure! I will send via data.world, if that's okay.

dheerajchand commented 6 years ago

https://data.world/dheerajchand/hotspot-analysis-testing is the URL for the datasets but I will also send by email as you asked. I am putting these here for reference so that anyone else viewing the ticket also has access to how this was solved.

dheerajchand commented 6 years ago

What I am hoping to accomplish is to determine areas of incidence of domestic violence crimes in Chicago with respect to the wards. I am trying to learn hotspot analysis and your plugin concurrently. Do I need to recode the dataset to be "1" for True and "0" for False in the DOMESTIC column?

danioxoli commented 6 years ago

The main issue in what you are trying to do with your data is that LISA statistics are tough for numeric attributes and not for binary ones.
This means that your attribute needs for a "magnitude" e.g. the average concentration of a pollutant at each ward, the count of crime cases at each location, and so on. Therefore, you first need to "count" the events (1,0 or True, False) within the areas of interest and then e.g. run the Hotspot analysis on this count or some other related count.

Please, refer to the following literature to get more confident with the topic as well as to better calibrate your expectations and tasks:

1 2 3

Lastly, I suggest you to reproject your data (especially when they are pointwise) in a metric coordinate reference system, e.g. WGS84/UTM16N for Chicago.

Best,

Daniele

dheerajchand commented 6 years ago

Many thanks! Closing the ticket!