TypeError: “unsupported operand type(s) for /: 'int' and 'list'” in QGIS?“Couldn't load plugin mmqgis...

Why are the outputs of printf and std::cout different

Bash: What does "masking return values" mean?

Does the statement `int val = (++i > ++j) ? ++i : ++j;` invoke undefined behavior?

Ban on all campaign finance?

Using "wallow" verb with object

Instead of Universal Basic Income, why not Universal Basic NEEDS?

How is the Swiss post e-voting system supposed to work, and how was it wrong?

An Accountant Seeks the Help of a Mathematician

Rules about breaking the rules. How do I do it well?

Know when to turn notes upside-down(eighth notes, sixteen notes, etc.)

Meaning of "SEVERA INDEOVI VAS" from 3rd Century slab

What is a good source for large tables on the properties of water?

Why did it take so long to abandon sail after steamships were demonstrated?

Connecting top and bottom SMD component pads using via

Am I not good enough for you?

Official degrees of earth’s rotation per day

Life insurance that covers only simultaneous/dual deaths

Theorems like the Lovász Local Lemma?

Can the damage from a Talisman of Pure Good (or Ultimate Evil) be non-lethal?

Russian cases: A few examples, I'm really confused

Is a lawful good "antagonist" effective?

Dot in front of file

How to make healing in an exploration game interesting

Why would a flight no longer considered airworthy be redirected like this?



TypeError: “unsupported operand type(s) for /: 'int' and 'list'” in QGIS?


“Couldn't load plugin mmqgis due to an error when calling its classFactory() method”Clip line vector by shape fails - error 1005QGIS couldn't load processing plugin - Windows 7How to fix a “arguments did not match any overloaded call” errorQGIS select by location failingQGIS, Python and GniPlannerFTTH ErrorSelect by location QGIS and PostGIS. Exception: unknownCount points in polygon tool keeps failing in QGISArea of Intersection between two polygon files in QGISGetting QGIS processing script field calculator error?













2















In a academic project I've produced a small python script for watershed analysis. This script relates shapefiles attributes and generates a .txt file.



I am trying to adjust the script to use within the QGIS environment. When I use it, it shows the following error:




unsupported operand type (s) for /: 'int' and 'list' See log for more details




In logs we can see:



2019-01-03T21:10:57 2   Uncaught error while executing algorithm
Traceback (most recent call last):
File "C:/PROGRA~1/QGIS2~1.18/apps/qgis-ltr/./python/pluginsprocessingcoreGeoAlgorithm.py", line 203, in execute
self.processAlgorithm(progress)
File "C:/PROGRA~1/QGIS2~1.18/apps/qgis-ltr/./python/pluginsprocessingscriptScriptAlgorithm.py", line 381, in processAlgorithm
exec((script), ns)
File "<string>", line 123, in <module>
File "<string>", line 35, in densidade_rios
TypeError: unsupported operand type(s) for /: 'int' and 'list'


Here is the code:



from qgis.core import *
import math

# Function
def densidade_rios(valor_total_rios, valor_area_bacia):
dr = valor_total_rios / valor_area_bacia
return dr

# Loading dreinage and watershed layers
dlayer = QgsVectorLayer(Drenagem, "drenagem", "ogr")
blayer = QgsVectorLayer(Bacia, "bacia", "ogr")

# Dreinage attributes
dfeatures = dlayer.getFeatures()
# Listing values per column
listdfeatures = list(zip(*dfeatures))

# Max and min order values
maxordem = max(listdfeatures[0])
minordem = min(listdfeatures[0])

# Counting features of channel hierarchy (dreinage layer values)
ordem = minordem
hierarquia = []
while (ordem <= maxordem):
contagem = listdfeatures[0].count(ordem)
hierarquia.append(contagem)
ordem += 1

# Total of rivers - quantity of first order rivers (dreinage layer values)
totalrios = hierarquia[0]

# Watershed attributes
areabh = blayer.getValues(blayer.fields()[0].name())[0]

# Using function
dr = densidade_rios(totalrios, areabh)


Attribute table values of drenagem layer:



enter image description here



Attribute table values of bacia layer:



enter image description here










share|improve this question




















  • 2





    What is the value of areabh = blayer.getValues(blayer.fields()[0].name())[0] ? Perhaps that line has changed and the last [0] has been forgotten. I can't fully understand what it's trying to do, the comments are in a language that I don't know. Both values should be a number type but the 2nd one is a list object at that line.

    – Michael Stimson
    Jan 4 at 0:44








  • 2





    @MichaelStimson you are right. I need one more [0] in the line areabh = blayer.getValues(blayer.fields()[0].name())[0] to take the value of the list. Because of this it wasn't working, because I was taking all the list, not one value of the list. So, the code have to be areabh = blayer.getValues(blayer.fields()[0].name())[0][0]. Problem solved, the code is working! Thank you!

    – Carolina
    Jan 4 at 14:24


















2















In a academic project I've produced a small python script for watershed analysis. This script relates shapefiles attributes and generates a .txt file.



I am trying to adjust the script to use within the QGIS environment. When I use it, it shows the following error:




unsupported operand type (s) for /: 'int' and 'list' See log for more details




In logs we can see:



2019-01-03T21:10:57 2   Uncaught error while executing algorithm
Traceback (most recent call last):
File "C:/PROGRA~1/QGIS2~1.18/apps/qgis-ltr/./python/pluginsprocessingcoreGeoAlgorithm.py", line 203, in execute
self.processAlgorithm(progress)
File "C:/PROGRA~1/QGIS2~1.18/apps/qgis-ltr/./python/pluginsprocessingscriptScriptAlgorithm.py", line 381, in processAlgorithm
exec((script), ns)
File "<string>", line 123, in <module>
File "<string>", line 35, in densidade_rios
TypeError: unsupported operand type(s) for /: 'int' and 'list'


Here is the code:



from qgis.core import *
import math

# Function
def densidade_rios(valor_total_rios, valor_area_bacia):
dr = valor_total_rios / valor_area_bacia
return dr

# Loading dreinage and watershed layers
dlayer = QgsVectorLayer(Drenagem, "drenagem", "ogr")
blayer = QgsVectorLayer(Bacia, "bacia", "ogr")

# Dreinage attributes
dfeatures = dlayer.getFeatures()
# Listing values per column
listdfeatures = list(zip(*dfeatures))

# Max and min order values
maxordem = max(listdfeatures[0])
minordem = min(listdfeatures[0])

# Counting features of channel hierarchy (dreinage layer values)
ordem = minordem
hierarquia = []
while (ordem <= maxordem):
contagem = listdfeatures[0].count(ordem)
hierarquia.append(contagem)
ordem += 1

# Total of rivers - quantity of first order rivers (dreinage layer values)
totalrios = hierarquia[0]

# Watershed attributes
areabh = blayer.getValues(blayer.fields()[0].name())[0]

# Using function
dr = densidade_rios(totalrios, areabh)


Attribute table values of drenagem layer:



enter image description here



Attribute table values of bacia layer:



enter image description here










share|improve this question




















  • 2





    What is the value of areabh = blayer.getValues(blayer.fields()[0].name())[0] ? Perhaps that line has changed and the last [0] has been forgotten. I can't fully understand what it's trying to do, the comments are in a language that I don't know. Both values should be a number type but the 2nd one is a list object at that line.

    – Michael Stimson
    Jan 4 at 0:44








  • 2





    @MichaelStimson you are right. I need one more [0] in the line areabh = blayer.getValues(blayer.fields()[0].name())[0] to take the value of the list. Because of this it wasn't working, because I was taking all the list, not one value of the list. So, the code have to be areabh = blayer.getValues(blayer.fields()[0].name())[0][0]. Problem solved, the code is working! Thank you!

    – Carolina
    Jan 4 at 14:24
















2












2








2


0






In a academic project I've produced a small python script for watershed analysis. This script relates shapefiles attributes and generates a .txt file.



I am trying to adjust the script to use within the QGIS environment. When I use it, it shows the following error:




unsupported operand type (s) for /: 'int' and 'list' See log for more details




In logs we can see:



2019-01-03T21:10:57 2   Uncaught error while executing algorithm
Traceback (most recent call last):
File "C:/PROGRA~1/QGIS2~1.18/apps/qgis-ltr/./python/pluginsprocessingcoreGeoAlgorithm.py", line 203, in execute
self.processAlgorithm(progress)
File "C:/PROGRA~1/QGIS2~1.18/apps/qgis-ltr/./python/pluginsprocessingscriptScriptAlgorithm.py", line 381, in processAlgorithm
exec((script), ns)
File "<string>", line 123, in <module>
File "<string>", line 35, in densidade_rios
TypeError: unsupported operand type(s) for /: 'int' and 'list'


Here is the code:



from qgis.core import *
import math

# Function
def densidade_rios(valor_total_rios, valor_area_bacia):
dr = valor_total_rios / valor_area_bacia
return dr

# Loading dreinage and watershed layers
dlayer = QgsVectorLayer(Drenagem, "drenagem", "ogr")
blayer = QgsVectorLayer(Bacia, "bacia", "ogr")

# Dreinage attributes
dfeatures = dlayer.getFeatures()
# Listing values per column
listdfeatures = list(zip(*dfeatures))

# Max and min order values
maxordem = max(listdfeatures[0])
minordem = min(listdfeatures[0])

# Counting features of channel hierarchy (dreinage layer values)
ordem = minordem
hierarquia = []
while (ordem <= maxordem):
contagem = listdfeatures[0].count(ordem)
hierarquia.append(contagem)
ordem += 1

# Total of rivers - quantity of first order rivers (dreinage layer values)
totalrios = hierarquia[0]

# Watershed attributes
areabh = blayer.getValues(blayer.fields()[0].name())[0]

# Using function
dr = densidade_rios(totalrios, areabh)


Attribute table values of drenagem layer:



enter image description here



Attribute table values of bacia layer:



enter image description here










share|improve this question
















In a academic project I've produced a small python script for watershed analysis. This script relates shapefiles attributes and generates a .txt file.



I am trying to adjust the script to use within the QGIS environment. When I use it, it shows the following error:




unsupported operand type (s) for /: 'int' and 'list' See log for more details




In logs we can see:



2019-01-03T21:10:57 2   Uncaught error while executing algorithm
Traceback (most recent call last):
File "C:/PROGRA~1/QGIS2~1.18/apps/qgis-ltr/./python/pluginsprocessingcoreGeoAlgorithm.py", line 203, in execute
self.processAlgorithm(progress)
File "C:/PROGRA~1/QGIS2~1.18/apps/qgis-ltr/./python/pluginsprocessingscriptScriptAlgorithm.py", line 381, in processAlgorithm
exec((script), ns)
File "<string>", line 123, in <module>
File "<string>", line 35, in densidade_rios
TypeError: unsupported operand type(s) for /: 'int' and 'list'


Here is the code:



from qgis.core import *
import math

# Function
def densidade_rios(valor_total_rios, valor_area_bacia):
dr = valor_total_rios / valor_area_bacia
return dr

# Loading dreinage and watershed layers
dlayer = QgsVectorLayer(Drenagem, "drenagem", "ogr")
blayer = QgsVectorLayer(Bacia, "bacia", "ogr")

# Dreinage attributes
dfeatures = dlayer.getFeatures()
# Listing values per column
listdfeatures = list(zip(*dfeatures))

# Max and min order values
maxordem = max(listdfeatures[0])
minordem = min(listdfeatures[0])

# Counting features of channel hierarchy (dreinage layer values)
ordem = minordem
hierarquia = []
while (ordem <= maxordem):
contagem = listdfeatures[0].count(ordem)
hierarquia.append(contagem)
ordem += 1

# Total of rivers - quantity of first order rivers (dreinage layer values)
totalrios = hierarquia[0]

# Watershed attributes
areabh = blayer.getValues(blayer.fields()[0].name())[0]

# Using function
dr = densidade_rios(totalrios, areabh)


Attribute table values of drenagem layer:



enter image description here



Attribute table values of bacia layer:



enter image description here







qgis python pyqgis vector typeerror






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 9 mins ago









Andre Silva

7,735113785




7,735113785










asked Jan 4 at 0:18









CarolinaCarolina

288




288








  • 2





    What is the value of areabh = blayer.getValues(blayer.fields()[0].name())[0] ? Perhaps that line has changed and the last [0] has been forgotten. I can't fully understand what it's trying to do, the comments are in a language that I don't know. Both values should be a number type but the 2nd one is a list object at that line.

    – Michael Stimson
    Jan 4 at 0:44








  • 2





    @MichaelStimson you are right. I need one more [0] in the line areabh = blayer.getValues(blayer.fields()[0].name())[0] to take the value of the list. Because of this it wasn't working, because I was taking all the list, not one value of the list. So, the code have to be areabh = blayer.getValues(blayer.fields()[0].name())[0][0]. Problem solved, the code is working! Thank you!

    – Carolina
    Jan 4 at 14:24
















  • 2





    What is the value of areabh = blayer.getValues(blayer.fields()[0].name())[0] ? Perhaps that line has changed and the last [0] has been forgotten. I can't fully understand what it's trying to do, the comments are in a language that I don't know. Both values should be a number type but the 2nd one is a list object at that line.

    – Michael Stimson
    Jan 4 at 0:44








  • 2





    @MichaelStimson you are right. I need one more [0] in the line areabh = blayer.getValues(blayer.fields()[0].name())[0] to take the value of the list. Because of this it wasn't working, because I was taking all the list, not one value of the list. So, the code have to be areabh = blayer.getValues(blayer.fields()[0].name())[0][0]. Problem solved, the code is working! Thank you!

    – Carolina
    Jan 4 at 14:24










2




2





What is the value of areabh = blayer.getValues(blayer.fields()[0].name())[0] ? Perhaps that line has changed and the last [0] has been forgotten. I can't fully understand what it's trying to do, the comments are in a language that I don't know. Both values should be a number type but the 2nd one is a list object at that line.

– Michael Stimson
Jan 4 at 0:44







What is the value of areabh = blayer.getValues(blayer.fields()[0].name())[0] ? Perhaps that line has changed and the last [0] has been forgotten. I can't fully understand what it's trying to do, the comments are in a language that I don't know. Both values should be a number type but the 2nd one is a list object at that line.

– Michael Stimson
Jan 4 at 0:44






2




2





@MichaelStimson you are right. I need one more [0] in the line areabh = blayer.getValues(blayer.fields()[0].name())[0] to take the value of the list. Because of this it wasn't working, because I was taking all the list, not one value of the list. So, the code have to be areabh = blayer.getValues(blayer.fields()[0].name())[0][0]. Problem solved, the code is working! Thank you!

– Carolina
Jan 4 at 14:24







@MichaelStimson you are right. I need one more [0] in the line areabh = blayer.getValues(blayer.fields()[0].name())[0] to take the value of the list. Because of this it wasn't working, because I was taking all the list, not one value of the list. So, the code have to be areabh = blayer.getValues(blayer.fields()[0].name())[0][0]. Problem solved, the code is working! Thank you!

– Carolina
Jan 4 at 14:24












1 Answer
1






active

oldest

votes


















0














As mentioned by Michael Stimson the error is because a list was used where a number was expected.



densidade_rios is returning the result of a division, hence areabh (which is the division's denominator) needs to be a value:



areabh = blayer.getValues('Area_km2')[0][0] # where 'blayer.fields()[0].name()' is the field name 'Area_km2'.


Another way of getting areabh would be:



areabh = [f['Area_km2'] for f in blayer.getFeatures()][0]




share























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "79"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f307536%2ftypeerror-unsupported-operand-types-for-int-and-list-in-qgis%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    As mentioned by Michael Stimson the error is because a list was used where a number was expected.



    densidade_rios is returning the result of a division, hence areabh (which is the division's denominator) needs to be a value:



    areabh = blayer.getValues('Area_km2')[0][0] # where 'blayer.fields()[0].name()' is the field name 'Area_km2'.


    Another way of getting areabh would be:



    areabh = [f['Area_km2'] for f in blayer.getFeatures()][0]




    share




























      0














      As mentioned by Michael Stimson the error is because a list was used where a number was expected.



      densidade_rios is returning the result of a division, hence areabh (which is the division's denominator) needs to be a value:



      areabh = blayer.getValues('Area_km2')[0][0] # where 'blayer.fields()[0].name()' is the field name 'Area_km2'.


      Another way of getting areabh would be:



      areabh = [f['Area_km2'] for f in blayer.getFeatures()][0]




      share


























        0












        0








        0







        As mentioned by Michael Stimson the error is because a list was used where a number was expected.



        densidade_rios is returning the result of a division, hence areabh (which is the division's denominator) needs to be a value:



        areabh = blayer.getValues('Area_km2')[0][0] # where 'blayer.fields()[0].name()' is the field name 'Area_km2'.


        Another way of getting areabh would be:



        areabh = [f['Area_km2'] for f in blayer.getFeatures()][0]




        share













        As mentioned by Michael Stimson the error is because a list was used where a number was expected.



        densidade_rios is returning the result of a division, hence areabh (which is the division's denominator) needs to be a value:



        areabh = blayer.getValues('Area_km2')[0][0] # where 'blayer.fields()[0].name()' is the field name 'Area_km2'.


        Another way of getting areabh would be:



        areabh = [f['Area_km2'] for f in blayer.getFeatures()][0]





        share











        share


        share










        answered 8 mins ago









        Andre SilvaAndre Silva

        7,735113785




        7,735113785






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Geographic Information Systems Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f307536%2ftypeerror-unsupported-operand-types-for-int-and-list-in-qgis%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Щит и меч (фильм) Содержание Названия серий | Сюжет |...

            Венесуэла на летних Олимпийских играх 2000 Содержание Состав...

            Meter-Bus Содержание Параметры шины | Стандартизация |...