<html style="direction: ltr;">
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
    <style type="text/css">body p { margin-bottom: 0cm; margin-top: 0pt; } </style>
  </head>
  <body style="direction: ltr;"
    bidimailui-detected-decoding-type="latin-charset" bgcolor="#FFFFFF"
    text="#000000">
    <div class="moz-cite-prefix">On 06/08/2014 03:41 PM, Bleninger, Sara
      wrote:<br>
    </div>
    <blockquote
cite="mid:09078B4A4BBF084F8CBE2F234D30CE00206D571C@exmbx01.UNI-BAMBERG.DE"
      type="cite">
      <meta http-equiv="Content-Type" content="text/html;
        charset=ISO-8859-1">
      <meta name="Generator" content="Microsoft Word 14 (filtered
        medium)">
      <style><!--
/* Font Definitions */
@font-face
        {font-family:Wingdings;
        panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
        {font-family:Wingdings;
        panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";
        mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
        {mso-style-priority:34;
        margin-top:0cm;
        margin-right:0cm;
        margin-bottom:0cm;
        margin-left:36.0pt;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";
        mso-fareast-language:EN-US;}
span.E-MailFormatvorlage17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";
        mso-fareast-language:EN-US;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:70.85pt 70.85pt 2.0cm 70.85pt;}
div.WordSection1
        {page:WordSection1;}
/* List Definitions */
@list l0
        {mso-list-id:1926378510;
        mso-list-type:hybrid;
        mso-list-template-ids:-924784232 446355780 67567619 67567621 67567617 67567619 67567621 67567617 67567619 67567621;}
@list l0:level1
        {mso-level-start-at:0;
        mso-level-number-format:bullet;
        mso-level-text:-;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:"Calibri","sans-serif";
        mso-fareast-font-family:Calibri;
        mso-bidi-font-family:"Times New Roman";}
@list l0:level2
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:"Courier New";}
@list l0:level3
        {mso-level-number-format:bullet;
        mso-level-text:\F0A7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:Wingdings;}
@list l0:level4
        {mso-level-number-format:bullet;
        mso-level-text:\F0B7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:Symbol;}
@list l0:level5
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:"Courier New";}
@list l0:level6
        {mso-level-number-format:bullet;
        mso-level-text:\F0A7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:Wingdings;}
@list l0:level7
        {mso-level-number-format:bullet;
        mso-level-text:\F0B7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:Symbol;}
@list l0:level8
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:"Courier New";}
@list l0:level9
        {mso-level-number-format:bullet;
        mso-level-text:\F0A7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        text-indent:-18.0pt;
        font-family:Wingdings;}
ol
        {margin-bottom:0cm;}
ul
        {margin-bottom:0cm;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
      <div class="WordSection1">
        <p class="MsoNormal"><span lang="EN-US">Hi,<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US">I am quite unfamiliar to
            GRASS GIS, so I hope, that the following question is not too
            elementary…<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
        <p class="MsoNormal">There are two datasets: <o:p></o:p></p>
        <p class="MsoListParagraph"
          style="text-indent:-18.0pt;mso-list:l0 level1 lfo1"><!--[if !supportLists]--><span
            lang="EN-US"><span style="mso-list:Ignore">-<span
                style="font:7.0pt "Times New Roman"">         
              </span></span></span><!--[endif]--><span lang="EN-US">a
            shapefile consisting of geographical information to create a
            map of regions, the last column is a code for the regions<o:p></o:p></span></p>
        <p class="MsoListParagraph"
          style="text-indent:-18.0pt;mso-list:l0 level1 lfo1"><!--[if !supportLists]--><span
            lang="EN-US"><span style="mso-list:Ignore">-<span
                style="font:7.0pt "Times New Roman"">         
              </span></span></span><!--[endif]--><span lang="EN-US">a
            file of results of R computations. The units are the regions
            that are coded in the shapefile. Here the code for regions
            is the first column. It is possible to store this file in
            several formats.<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US">It is possible to upload
            the shapefile data in GRASS and make the map of regions.
            Now, I want to color the map according to the R results. How
            can I connect the R results information to the mapping
            information and color the map?<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
      </div>
    </blockquote>
    <p><br>
    </p>
    <p>You could do this in a number of ways:</p>
    <p>If you want to work in GRASS then v.db.join is the module you
      need. It would go something like:</p>
    <p><br>
    </p>
    <p># Make sure you are using the sqlite database backend first</p>
    <p>db.connect -p</p>
    <p>#Import the shape into GRASS<br>
    </p>
    <p>v.in.ogr dsn=regions.shp out=regions</p>
    <p># Should contain a column "code"</p>
    <p># Now import a csv of the R computation data<br>
    </p>
    <p># Assume we have a column "r_code" different from the column name
      in the shapefile </p>
    <p>db.in.ogr dsn=r.computations.csv out=r_comp<br>
    </p>
    <p>v.db.join map=regions column=code otable=r_comp ocolumn=r_code</p>
    <p># Verify that the new data exists:</p>
    <p>v.info -c</p>
    <p># You can now export the joined vector data table back to a
      shapefile</p>
    <p>v.out.ogr input=regions dsn=regions_merged.shp<br>
    </p>
    <p># (Or you could create the map within GRASS...)</p>
    <p><br>
    </p>
    <p><br>
    </p>
    <p>You might also prefer to do this straight in R, with the merge()
      function: </p>
    <p># load the rgdal library</p>
    <p>library(rgdal)</p>
    <p># Import the shapefile</p>
    <p>reg <- readOGR('regions.shp', 'regions')</p>
    <p># Check the structure, make sure you have the data column "code"<br>
    </p>
    <p>str(reg)<br>
    </p>
    <p># Make the R computations a data frame (if it is not already)</p>
    <p>r.comp.df <- as.data.frame(r.comp)</p>
    <p># Now merge</p>
    <p>reg.merge <- merge(reg, r.comp.df, by.x="code", by.y="r_code")</p>
    <p>str(reg.merge)<br>
    </p>
    <p># If you need this as a shapefile, you can export</p>
    <p>writeOGR(reg.merge, dsn="reg_merge.shp",layer="reg_merge",
      driver="ESRI Shapefile")</p>
    <p># or as GRASS vector. You probably will have to install the
      spgrass6 package first:</p>
    <p>install.packages('spgrass6')</p>
    <p>library(spgrass6)</p>
    <p># The following needs to be done when R is started *from with a
      GRASS session*<br>
    </p>
    <p>writeVECT6(reg.merge, "reg_merge")</p>
    <p><br>
    </p>
    <p>Finally, most folks might prefer the simplest: to do the join
      right in QGIS by loading the shapefile, and using the built in
      JOIN capability - it's in the layer's Properties window, JOIN tab.</p>
    <p>Now, once the join is done, in QGIS you can use Styling to color
      the region polygons using the joined attribute columns. In the
      layer's Properties window you select the Style tab, and choose
      "Categorized" instead of "Single Symbol", then select which column
      contains the categories, setup coloring, etc.</p>
    <p><br>
    </p>
    <p>HTH,</p>
    <p>Micha<br>
    </p>
    <p><br>
    </p>
    <blockquote
cite="mid:09078B4A4BBF084F8CBE2F234D30CE00206D571C@exmbx01.UNI-BAMBERG.DE"
      type="cite">
      <div class="WordSection1">
        <p class="MsoNormal"><span lang="EN-US">Thanks for your help!<o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US"><o:p> </o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US">Sara <o:p></o:p></span></p>
        <p class="MsoNormal"><span lang="EN-US"> <o:p></o:p></span></p>
      </div>
      <br>
      <br>
      This mail was received via Mail-SeCure System.<br>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
grass-user mailing list
<a class="moz-txt-link-abbreviated" href="mailto:grass-user@lists.osgeo.org">grass-user@lists.osgeo.org</a>
<a class="moz-txt-link-freetext" href="http://lists.osgeo.org/mailman/listinfo/grass-user">http://lists.osgeo.org/mailman/listinfo/grass-user</a>
This mail was received via Mail-SeCure System.


</pre>
    </blockquote>
    <br>
  </body>
</html>