Did you change anything in the code? In the video I changed the code slightly after the crash. Make sure your code matches the code in the video from after the crash. If it does, and you still get a crash then it could be something with the files you are using.
Hi, Thank you for the tutorial. Is there any way to combine two rasters (reclassified raster and a binary raster) to find the no of pixels of a binary raster in the each category of the reclassified raster ?
Hi There, thank you for the video. I have a question. If I want to do a subtraction between two raster layers and I want to get only a certain extent of the area. Should I use the "extent" parameter? How do I set the desired bounding box? Thank you!
Thanks for the video. For line 12 I get the error message File "", line 13, in AttributeError: 'str' object has no attribute 'extent'. Any idea what's going on there?
Would it be possible to do a video about PyQGIS documentation? - where do you go when you check the syntax of these commands, how to read, search and understand the documentation? I'm newish to python and when I look at the docs I feel like part of my brain must be missing
Check out this course: opensourceoptions.com/courses/courses/pyqgis-learn-the-qgis-python-api/ The sample (free) lessons will go through documentation for some specific functions. Hopefully you'll find it helpful.
Hey man, I'm trying to run a batch QGIS3 NDVI calculator script on a bunch of ENVI 16 bit unsigned .bil data cubes, and the outputs are all 32bit and dark n grainy. Is there a way to set the output data type?
Your outputs are 32 bit because NDVI is going to result in a floating point value, not an integer. You might be able to change the data type by converting NDVI to an integer value. Also, you can probably just adjust the symbology to get the outputs to look the way you want.
@@geospatialschool Okay, that sort of sheds some light on it. But I don't think I provided enough detail. If I run the NDVI equation in the QGIS calculator GUI it yields a decent resolution, image with stats; STATISTICS_MAXIMUM=0.58577406406403 STATISTICS_MEAN=-0.13778701532923 STATISTICS_MINIMUM=-0.59615385532379 STATISTICS_STDDEV=0.30573901223104 STATISTICS_VALID_PERCENT=100 But when I use Python, the output is dark and has lost resolution. The stats are: STATISTICS_MAXIMUM=0 STATISTICS_MEAN=-0.92910058966749 STATISTICS_MINIMUM=-1 STATISTICS_STDDEV=0.05557199898703 STATISTICS_VALID_PERCENT=100 AREA_OR_POINT=Area I can't see any way to adjust it to appear like the GUIs output The for loop code I'm using is: lddLrs = [l for l in QgsProject().instance().mapLayers().values() if isinstance(l, QgsRasterLayer)] I'm trying to figure out if there's some else I need to add? Bearing in mind I don't fully understand what I'm doing yet .
@@Richard-sk3vh Maybe the statistics aren't being fully calculated. Even though they look different you could still have the same values in the two NDVI rasters. Check that out first. If the values are different then there's a problem with your calculation.
Hi there, I got it to work once applied the change suggested below (ras.raster). Question: 1) I want to multiply bands 1-55 of an image by 400 and bands 56 to 242 by 800. Then 2) I want to rescale the Y value to range between 0 and 1. and then 3) I would like to convert the bands numbers to wavelengths, so that in viper tools wavelength and not band numbers show up. What is the simplest way to do this? I am new to python. I tried raster calculator but cannot figure out how to get the batch mode to work. thanks U
That's a very detailed question and would take some time to prepare an answer. The basics are all there in this video. You just need to loop through all the bands and perform the desired operation(s).
I will eventually have the code available in a website post. The data can be downloaded online. This video will show you how: th-cam.com/video/VlKkAYoNoRE/w-d-xo.html
For this simple operation, yes. But the point of the video is to show you that raster calculator operations can be automated so if you need to run the same calculation multiple times, or on multiple datasets, you can replicate it easily.
I just incorporated this into a PyQgis model for 60 geotiff files which recalculated the rasters and hand the results to a conversion function. Easily a day+ of manual GUI labour sorted in 2 hours.
have you figured out why qgis crashes (7:25)? The same happens to me over and over again, but simply restarting the program doesn´t solve the problem.
Did you change anything in the code? In the video I changed the code slightly after the crash. Make sure your code matches the code in the video from after the crash. If it does, and you still get a crash then it could be something with the files you are using.
@@geospatialschool Thanks for this hint.
NOTE for everyone: change ras.layer into ras.raster ;
Then it all gonna work trouble free.
Hi,
Thank you for the tutorial. Is there any way to combine two rasters (reclassified raster and a binary raster) to find the no of pixels of a binary raster in the each category of the reclassified raster ?
Hi There, thank you for the video. I have a question.
If I want to do a subtraction between two raster layers and I want to get only a certain extent of the area. Should I use the "extent" parameter? How do I set the desired bounding box?
Thank you!
Thanks for the video. For line 12 I get the error message File "", line 13, in
AttributeError: 'str' object has no attribute 'extent'. Any idea what's going on there?
The variable that you're calling 'extent' on is of string type
Would it be possible to do a video about PyQGIS documentation? - where do you go when you check the syntax of these commands, how to read, search and understand the documentation? I'm newish to python and when I look at the docs I feel like part of my brain must be missing
Check out this course: opensourceoptions.com/courses/courses/pyqgis-learn-the-qgis-python-api/
The sample (free) lessons will go through documentation for some specific functions. Hopefully you'll find it helpful.
Hey man, I'm trying to run a batch QGIS3 NDVI calculator script on a bunch of ENVI 16 bit unsigned .bil data cubes, and the outputs are all 32bit and dark n grainy.
Is there a way to set the output data type?
Your outputs are 32 bit because NDVI is going to result in a floating point value, not an integer. You might be able to change the data type by converting NDVI to an integer value. Also, you can probably just adjust the symbology to get the outputs to look the way you want.
@@geospatialschool Okay, that sort of sheds some light on it. But I don't think I provided enough detail.
If I run the NDVI equation in the QGIS calculator GUI it yields a decent resolution, image with stats;
STATISTICS_MAXIMUM=0.58577406406403
STATISTICS_MEAN=-0.13778701532923
STATISTICS_MINIMUM=-0.59615385532379
STATISTICS_STDDEV=0.30573901223104
STATISTICS_VALID_PERCENT=100
But when I use Python, the output is dark and has lost resolution. The stats are:
STATISTICS_MAXIMUM=0
STATISTICS_MEAN=-0.92910058966749
STATISTICS_MINIMUM=-1
STATISTICS_STDDEV=0.05557199898703
STATISTICS_VALID_PERCENT=100
AREA_OR_POINT=Area
I can't see any way to adjust it to appear like the GUIs output
The for loop code I'm using is:
lddLrs = [l for l in QgsProject().instance().mapLayers().values() if isinstance(l, QgsRasterLayer)]
I'm trying to figure out if there's some else I need to add? Bearing in mind I don't fully understand what I'm doing yet .
@@Richard-sk3vh Maybe the statistics aren't being fully calculated. Even though they look different you could still have the same values in the two NDVI rasters. Check that out first. If the values are different then there's a problem with your calculation.
Hi there, I got it to work once applied the change suggested below (ras.raster). Question: 1) I want to multiply bands 1-55 of an image by 400 and bands 56 to 242 by 800. Then 2) I want to rescale the Y value to range between 0 and 1. and then 3) I would like to convert the bands numbers to wavelengths, so that in viper tools wavelength and not band numbers show up. What is the simplest way to do this? I am new to python. I tried raster calculator but cannot figure out how to get the batch mode to work. thanks U
That's a very detailed question and would take some time to prepare an answer. The basics are all there in this video. You just need to loop through all the bands and perform the desired operation(s).
@@geospatialschool thanks I am working through the various videos and will tackle. Great videos!
Hola!! puedes dejar aquí los códigos y las imagenes por favor? Gracias!
English?
@@geospatialschool Hi thanks!! Can you leave here the codes you have made and the data to practice?
I will eventually have the code available in a website post. The data can be downloaded online. This video will show you how: th-cam.com/video/VlKkAYoNoRE/w-d-xo.html
Using GUI would have been much faster.
For this simple operation, yes. But the point of the video is to show you that raster calculator operations can be automated so if you need to run the same calculation multiple times, or on multiple datasets, you can replicate it easily.
I just incorporated this into a PyQgis model for 60 geotiff files which recalculated the rasters and hand the results to a conversion function. Easily a day+ of manual GUI labour sorted in 2 hours.
awesome, I will add this calc.lastError() to know if something goes wrong