Martin-Jung / LecoS

LecoS QGis Plugin - Contains several analytical functions for land cover analysis
GNU General Public License v3.0
21 stars 19 forks source link

Error message using "Overlay raster metrics (Polygons)" #20

Open mrobins18 opened 5 years ago

mrobins18 commented 5 years ago

Hello,

I am using the recent release of LecoS (3.0) with QGIS 3.6.3. When trying to run an operation with "overlay raster metrics" to calculate landcover within a vector overlay (a shapefile of 1000m2 buffers) I get the following error message.


Traceback (most recent call last): File "C:/Users/mrobinson/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\LecoS\lecos_sextantealgorithms.py", line 821, in processAlgorithm bat = pov.BatchConverter(inputFilename,vectorFilename,None) File "C:/Users/mrobinson/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\LecoS\landscape_polygonoverlay.py", line 121, in init self.lyr = self.shapef.GetLayer() AttributeError: 'NoneType' object has no attribute 'GetLayer'

Execution failed after 0.03 seconds


I eventually want to do this as a batch process, calculating multiple metrics.

Thanks in advance!

Martin-Jung commented 5 years ago

This error usually pops up if files are not properly loaded (e.g. cannot be read from harddisk). Please check the following:

If this still fails, then please provide a small subset of your data (vector and raster) as test dataset and upload it here, so that the error can be reproduced.

mrobins18 commented 5 years ago

Thanks for your response.

In reattempting the process, I received the same error message.

I have attached some sample data to this thread (vector and raster files) in the hope that the error can be reproduced.

test data.zip

Martin-Jung commented 5 years ago

Failed to reproduce the error on my machine (3.6.3 QGIS) using the LecoS Processing toolbox and polygon overlay. See screenshot. image

mrobins18 commented 5 years ago

I wonder if it has something to do with how I am entering my parameters?

I have attached a screenshot.

I am new to LecoS and the overlay raster application, so perhaps you might be able to identify something I'm missing in my initial set-up

screenshot

Martin-Jung commented 5 years ago

You have to set the check at 'classified' since your input raster is a categorical data set. Only uncheck it if you were to use LecoS with continous data such as elevation. I furthermore entered the class as '8' and the single class metric to land cover proportion.

mrobins18 commented 5 years ago

Hi Martin,

Thank you for your continued assistance with this.

I have replicated your parameter entry on the input interface, being sure to check the "raster classified" box. However, I continue to get the the following error message (see screenshot). I have also tried unsuccessfully to run the operation as a batch process.

My colleague has told me he successfully used the "overlay raster" tool for the same dataset, although he mentioned he was using an older release of the plugin with QGIS 2.1.8.

I am wondering if the issues I'm encountering might have something to do with this being a newer release version in concert with the packages I've included in my custom QGIS install. I have ensured that scipy, numpy, and PIL were included (for python 3).

I will continue to troubleshoot, but please let me know if you have any further suggestions.

Thanks again!

QGIS LecoS Error

mrobins18 commented 5 years ago

Update:

I have since had success with the "Overlay Raster Metrics (polygons)" tool and am now able to successfully process a raster one class at a time, saving each output as a csv file. However, I am unable to complete the same operation using the "run as batch process" option. I have attached a screen shot of both my parameter entry and the subsequent error message I receive. I have also attached my raster and vector files to see if the error can be repeated.

batch process error_june 23 test data.zip

With 11 classes in my landscape raster and 6+ landscape metrics to calculate across multiple vector overlay files, It would be ideal if I could do batch processing. However, if no immediate resolution can be reached, I can at least do individual processing in the interim.

Matt-RS commented 5 years ago

Hi, @mrobins18 I am curious how you managed to solve this? I am currently experiencing exactly the same error. Many thanks

mrobins18 commented 5 years ago

Hi Matt,

I never fully resolved the issue (i.e could not get batch processing to work). I was only able to process a single landscape metric at a time. Further, I found I had to save the output as a shapefile rather than a csv. This was because when I saved as a csv it would result in a csv with 2 columns: one labeled "FID" with a continuous sequence of numbers (e.g 1, 2, 3 ....etc) and other with the landscape metric. However, the "FID" column didn't correspond to any of the columns in the attribute table for my input shapefile. As such, I had no way of confidently determining which landscape value belonged to which polygon. When I saved the output as a shapefile however, it would provide the metric values as a new column and a direct correspondence with each polygon's landscape metric value was clear.

I then copy and pasted the resulting outputs into an excel file and used the same input shapefile to process other metrics since the metric values would subsequently be overwritten rather than adding a new column to the output's attribute table.

Given the smaller number of features I was doing the processing on (11 total), this method was manageable, although obviously not efficient. It would not be feasible for a large number of feature classes.

Martin-Jung commented 5 years ago

Just as info: FID is called a 'Feature ID' and is a (hidden) attribute of all ESRI shapefiles. It corresponds to the row / observation number of your features.

Matt-RS commented 5 years ago

I worked out that despite there being no missing data, the fact there was a default no data value was causing the issue. I then removed that option and the first statistic ran correctly. Since then however, I have tried various different ones and the processing never seems to complete (after more than an hour). The raster is 30kmx30km and the grids are 1kmx1km (I increased the scale for these experiments), so although I would expect it to take a little time this does seem excessive. Do you remember roughly how long they took @mrobins18

Thanks both of you for the information and support.

mrobins18 commented 5 years ago

Hi Matt,

It took about 10-12 minutes to process a single metric.

On Wed, Aug 7, 2019 at 10:42 AM Matt-RS notifications@github.com wrote:

I worked out that despite there being no missing data, the fact there was a default no data value was causing the issue. I then removed that option and the first statistic ran correctly. Since then however, I have tried various different ones and the processing never seems to complete (after more than an hour). The raster is 30kmx30km and the grids are 1kmx1km (I increased the scale for these experiments), so although I would expect it to take a little time this does seem excessive. Do you remember roughly how long they took @mrobins18 https://github.com/mrobins18

Thanks both of you for the information and support.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Martin-Jung/LecoS/issues/20?email_source=notifications&email_token=AMMZT5EJVHK3VJHAH2T6YTDQDMCR5A5CNFSM4HZYL6OKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD3ZFVXQ#issuecomment-519199454, or mute the thread https://github.com/notifications/unsubscribe-auth/AMMZT5G7IOH4YMHWDOT4HBTQDMCR5ANCNFSM4HZYL6OA .

Matt-RS commented 5 years ago

Hmm OK then perhaps the lengthy processing for my relatively large images is as expected.

@Martin-Jung I am hoping you might be able to help with my next error as it appears to relate to the FID. I will copy the error below but please let me know if there is any other information I can provide that would be of use. Thanks

Traceback (most recent call last): File "C:/Users/numbe/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\LecoS\lecos_sextantealgorithms.py", line 842, in processAlgorithm err, r = bat.go(whatC,cl,pixelSize) File "C:/Users/numbe/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\LecoS\landscape_polygonoverlay.py", line 219, in go id = poly.GetFID() AttributeError: 'NoneType' object has no attribute 'GetFID'

Execution failed after 1911.46 seconds

Martin-Jung commented 5 years ago

These error's indicate that the shapefile could not been read ( 'NoneType' ), possibly because

Sorry to be not more of help, but I haven't got much time for LecoS development these days...

Matt-RS commented 5 years ago

Sadly it must be the third option. I will try an older version of QGIS at least, just in case that makes a difference. No worries, it's nice to have such a quick response at least. Thanks

CWen001 commented 5 years ago

After testing a bunch of my data using different settings, I have concluded a few experiences workable, in addition to the suggestions above.

(1) The grid vector has to be a shapefile. Neither geopackage nor geojson works. (2) The CRS of the vector and the raster has to be the same AND to be projected. EPSG 4326 doesn't work, at least for me. (3) Double-check the nodata value for the raster. (4) LecoS doesn't support multipolygon so far.

xxl-qiu commented 4 years ago

@Martin-Jung Hellow,l don't understand how to solve the problem ,such as using LecoS Processing Toolbox.

xxl-qiu commented 4 years ago

@mrobins18 Hellow,How didi you solve the problem.

FloMee commented 4 years ago

Hello,

This is my first post on GitHub and my knowledge on programming is extremely low-lewel but I found an ugly workaround for the problem reported here that i wanted to share with you. I am using LecoS 3.0 with QGIS 3.14. On some point I realized that the parameter VECTOR_GRID consists of the source path and the layername separated by |. You can see this on the picture posted by @mrobins on Jun 21, 2019. My Solution was to replace self.vectorPath = self.vector.source() by self.vectorPath = self.vector.source().split('|')[0] in lecos_dlg.py (line 764) and vectorFilename = vectorlayer.source() by vectorFilename = vectorlayer.source().split("|")[0] in lecos_sextantealgorithms.py (line 807).

This is at least working for me and maybe it is a hint for further problem solving. Thanks @Martin-Jung for this helpful plugin.