Adding attribute based on Function in GRASS GIS Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?How to access vector coordinates in GRASS GIS from python?Updating 30 Shapefiles, adding attribute and populating based on dataAdding additional nodes to network in Grass GISChanging data type in ArcGIS attribute table?Create Addons for GRASS GIS“Identity” equivalent in Grass GISPygrass ERROR: Mapset is not setExporting multiple layers to single dxf file using Grass GIS?Fill in new field in attribute table based on the values of another field in GISHow to update new column with v.distance from GRASS GIS?

Co-worker has annoying ringtone

Is multiple magic items in one inherently imbalanced?

Monty Hall Problem-Probability Paradox

What does the writing on Poe's helmet say?

Why not send Voyager 3 and 4 following up the paths taken by Voyager 1 and 2 to re-transmit signals of later as they fly away from Earth?

What order were files/directories output in dir?

If Windows 7 doesn't support WSL, then what is "Subsystem for UNIX-based Applications"?

I got rid of Mac OSX and replaced it with linux but now I can't change it back to OSX or windows

How to write capital alpha?

Why complex landing gears are used instead of simple,reliability and light weight muscle wire or shape memory alloys?

As a dual citizen, my US passport will expire one day after traveling to the US. Will this work?

A term for a woman complaining about things/begging in a cute/childish way

Asymptotics question

What would you call this weird metallic apparatus that allows you to lift people?

Found this skink in my tomato plant bucket. Is he trapped? Or could he leave if he wanted?

I can't produce songs

Special flights

Did Mueller's report provide an evidentiary basis for the claim of Russian govt election interference via social media?

Why is a lens darker than other ones when applying the same settings?

Can you force honesty by using the Speak with Dead and Zone of Truth spells together?

Does the Black Tentacles spell do damage twice at the start of turn to an already restrained creature?

What does Turing mean by this statement?

Most effective melee weapons for arboreal combat? (pre-gunpowder technology)

GDP with Intermediate Production



Adding attribute based on Function in GRASS GIS



Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Announcing the arrival of Valued Associate #679: Cesar Manara
Unicorn Meta Zoo #1: Why another podcast?How to access vector coordinates in GRASS GIS from python?Updating 30 Shapefiles, adding attribute and populating based on dataAdding additional nodes to network in Grass GISChanging data type in ArcGIS attribute table?Create Addons for GRASS GIS“Identity” equivalent in Grass GISPygrass ERROR: Mapset is not setExporting multiple layers to single dxf file using Grass GIS?Fill in new field in attribute table based on the values of another field in GISHow to update new column with v.distance from GRASS GIS?



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I would like to create a new attribute based on another attribute using a formula in GRASS GIS.



I would like to do multiple 'if' functions embedded example:



if attribute x = 1.2: 1e-6
if attribute x = 2: 5e-6
if attribute x = 3: 1e-5


there would be as many embedded if functions as different values in my vector table. I can do this in MS Access or Excel, but I would like to do this directly in GRASS GIS.










share|improve this question






























    1















    I would like to create a new attribute based on another attribute using a formula in GRASS GIS.



    I would like to do multiple 'if' functions embedded example:



    if attribute x = 1.2: 1e-6
    if attribute x = 2: 5e-6
    if attribute x = 3: 1e-5


    there would be as many embedded if functions as different values in my vector table. I can do this in MS Access or Excel, but I would like to do this directly in GRASS GIS.










    share|improve this question


























      1












      1








      1








      I would like to create a new attribute based on another attribute using a formula in GRASS GIS.



      I would like to do multiple 'if' functions embedded example:



      if attribute x = 1.2: 1e-6
      if attribute x = 2: 5e-6
      if attribute x = 3: 1e-5


      there would be as many embedded if functions as different values in my vector table. I can do this in MS Access or Excel, but I would like to do this directly in GRASS GIS.










      share|improve this question
















      I would like to create a new attribute based on another attribute using a formula in GRASS GIS.



      I would like to do multiple 'if' functions embedded example:



      if attribute x = 1.2: 1e-6
      if attribute x = 2: 5e-6
      if attribute x = 3: 1e-5


      there would be as many embedded if functions as different values in my vector table. I can do this in MS Access or Excel, but I would like to do this directly in GRASS GIS.







      grass attribute-table






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Apr 12 at 11:28









      Taras

      2,3703730




      2,3703730










      asked Apr 11 at 23:36









      fanfanGisfanfanGis

      356




      356




















          1 Answer
          1






          active

          oldest

          votes


















          2














          If your GRASS database backend is sqlite (the default) then the parallel to if...then... is CASE...WHEN...THEN.... So the CASE statement would look something like (assuming you have a column attrib):



          CASE attrib
          WHEN 1.2 THEN 1e-6
          WHEN 2 THEN 5e-6
          END


          and the full v.db.update in GRASS would be (assuming the vector is named "my_vect" and the new column is "new_attrib":



          v.db.addcolumn map=my_vect column="new_attrib DOUBLE PRECISION"
          db.execute sql="UPDATE my_vect SET new_attrib='CASE attrib WHEN 1.2 THEN 1e-6 WHEN 2 THEN 5e-6 END'"


          But if there are many values in the attrib column, this will get very cumbersome. You might consider extracting all the values, preparing a text file of the new attrib values, then running the update in a loop:



          v.db.select -c map=my_vect column="attrib" file=attribs.txt
          v.db.addcolumn map=my_vect column="new_attrib DOUBLE PRECISION"
          # Now, edit the attribs.txt file so that each line contains a pair of old_value new_value
          # Then run v.db.update in a loop
          while read old new; do
          v.db.update map=my_vect column=new_attrib where="attrib=$old" value=$new
          done < attribs.txt





          share|improve this answer























            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%2f318546%2fadding-attribute-based-on-function-in-grass-gis%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









            2














            If your GRASS database backend is sqlite (the default) then the parallel to if...then... is CASE...WHEN...THEN.... So the CASE statement would look something like (assuming you have a column attrib):



            CASE attrib
            WHEN 1.2 THEN 1e-6
            WHEN 2 THEN 5e-6
            END


            and the full v.db.update in GRASS would be (assuming the vector is named "my_vect" and the new column is "new_attrib":



            v.db.addcolumn map=my_vect column="new_attrib DOUBLE PRECISION"
            db.execute sql="UPDATE my_vect SET new_attrib='CASE attrib WHEN 1.2 THEN 1e-6 WHEN 2 THEN 5e-6 END'"


            But if there are many values in the attrib column, this will get very cumbersome. You might consider extracting all the values, preparing a text file of the new attrib values, then running the update in a loop:



            v.db.select -c map=my_vect column="attrib" file=attribs.txt
            v.db.addcolumn map=my_vect column="new_attrib DOUBLE PRECISION"
            # Now, edit the attribs.txt file so that each line contains a pair of old_value new_value
            # Then run v.db.update in a loop
            while read old new; do
            v.db.update map=my_vect column=new_attrib where="attrib=$old" value=$new
            done < attribs.txt





            share|improve this answer



























              2














              If your GRASS database backend is sqlite (the default) then the parallel to if...then... is CASE...WHEN...THEN.... So the CASE statement would look something like (assuming you have a column attrib):



              CASE attrib
              WHEN 1.2 THEN 1e-6
              WHEN 2 THEN 5e-6
              END


              and the full v.db.update in GRASS would be (assuming the vector is named "my_vect" and the new column is "new_attrib":



              v.db.addcolumn map=my_vect column="new_attrib DOUBLE PRECISION"
              db.execute sql="UPDATE my_vect SET new_attrib='CASE attrib WHEN 1.2 THEN 1e-6 WHEN 2 THEN 5e-6 END'"


              But if there are many values in the attrib column, this will get very cumbersome. You might consider extracting all the values, preparing a text file of the new attrib values, then running the update in a loop:



              v.db.select -c map=my_vect column="attrib" file=attribs.txt
              v.db.addcolumn map=my_vect column="new_attrib DOUBLE PRECISION"
              # Now, edit the attribs.txt file so that each line contains a pair of old_value new_value
              # Then run v.db.update in a loop
              while read old new; do
              v.db.update map=my_vect column=new_attrib where="attrib=$old" value=$new
              done < attribs.txt





              share|improve this answer

























                2












                2








                2







                If your GRASS database backend is sqlite (the default) then the parallel to if...then... is CASE...WHEN...THEN.... So the CASE statement would look something like (assuming you have a column attrib):



                CASE attrib
                WHEN 1.2 THEN 1e-6
                WHEN 2 THEN 5e-6
                END


                and the full v.db.update in GRASS would be (assuming the vector is named "my_vect" and the new column is "new_attrib":



                v.db.addcolumn map=my_vect column="new_attrib DOUBLE PRECISION"
                db.execute sql="UPDATE my_vect SET new_attrib='CASE attrib WHEN 1.2 THEN 1e-6 WHEN 2 THEN 5e-6 END'"


                But if there are many values in the attrib column, this will get very cumbersome. You might consider extracting all the values, preparing a text file of the new attrib values, then running the update in a loop:



                v.db.select -c map=my_vect column="attrib" file=attribs.txt
                v.db.addcolumn map=my_vect column="new_attrib DOUBLE PRECISION"
                # Now, edit the attribs.txt file so that each line contains a pair of old_value new_value
                # Then run v.db.update in a loop
                while read old new; do
                v.db.update map=my_vect column=new_attrib where="attrib=$old" value=$new
                done < attribs.txt





                share|improve this answer













                If your GRASS database backend is sqlite (the default) then the parallel to if...then... is CASE...WHEN...THEN.... So the CASE statement would look something like (assuming you have a column attrib):



                CASE attrib
                WHEN 1.2 THEN 1e-6
                WHEN 2 THEN 5e-6
                END


                and the full v.db.update in GRASS would be (assuming the vector is named "my_vect" and the new column is "new_attrib":



                v.db.addcolumn map=my_vect column="new_attrib DOUBLE PRECISION"
                db.execute sql="UPDATE my_vect SET new_attrib='CASE attrib WHEN 1.2 THEN 1e-6 WHEN 2 THEN 5e-6 END'"


                But if there are many values in the attrib column, this will get very cumbersome. You might consider extracting all the values, preparing a text file of the new attrib values, then running the update in a loop:



                v.db.select -c map=my_vect column="attrib" file=attribs.txt
                v.db.addcolumn map=my_vect column="new_attrib DOUBLE PRECISION"
                # Now, edit the attribs.txt file so that each line contains a pair of old_value new_value
                # Then run v.db.update in a loop
                while read old new; do
                v.db.update map=my_vect column=new_attrib where="attrib=$old" value=$new
                done < attribs.txt






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Apr 12 at 11:17









                MichaMicha

                11.1k1421




                11.1k1421



























                    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%2f318546%2fadding-attribute-based-on-function-in-grass-gis%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

                    រឿង រ៉ូមេអូ និង ហ្ស៊ុយលីយេ សង្ខេបរឿង តួអង្គ បញ្ជីណែនាំ

                    Crop image to path created in TikZ? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)Crop an inserted image?TikZ pictures does not appear in posterImage behind and beyond crop marks?Tikz picture as large as possible on A4 PageTransparency vs image compression dilemmaHow to crop background from image automatically?Image does not cropTikzexternal capturing crop marks when externalizing pgfplots?How to include image path that contains a dollar signCrop image with left size given

                    QGIS export composer to PDF scale the map [closed] Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?Print Composer QGIS 2.6, how to export image?QGIS 2.8.1 print composer won't export all OpenCycleMap base layer tilesSave Print/Map QGIS composer view as PNG/PDF using Python (without changing anything in visible layout)?Export QGIS Print Composer PDF with searchable text labelsQGIS Print Composer does not change from landscape to portrait orientation?How can I avoid map size and scale changes in print composer?Fuzzy PDF export in QGIS running on macSierra OSExport the legend into its 100% size using Print ComposerScale-dependent rendering in QGIS PDF output