2

我想使用 R 将 txt 文件中的值放入 XML 文档中。保存这些值的 txt 文件如下所示:

"Value" "Label" "v"
AB  Albeluvisol 166,71,43,255
ABal    Alic Albeluvisol    173,114,101,255
ABap    Abruptic Albeluvisol    236,76,203,255
ABar    Arenic Albeluvisol  30,177,58,255
ABau    Alumic Albeluvisol  157,9,124,255
ABeun   Endoeutric Albeluvisol  69,16,63,255
ABfg    Fragic Albeluvisol  208,39,109,255
ABfr    Ferric Albeluvisol  196,209,39,255
ABge    Gelic Albeluvisol   93,27,59,255
ABgl    Gleyic Albeluvisol  232,125,4,255
ABha    Haplic Albeluvisol  0,34,146,255
ABhi    Histic Albeluvisol  98,99,192,255
ABsl    Siltic Albeluvisol  6,68,227,255
ABst    Stagnic Albeluvisol 140,236,81,255
ABum    Umbric Albeluvisol  25,98,131,255

XML结构是这样的:

<!DOCTYPE qgis PUBLIC 'http://mrcc.com/qgis.dtd' 'SYSTEM'>
<qgis version="1.8.0-Lisboa" minimumScale="0" maximumScale="1e+08" hasScaleBasedVisibilityFlag="0">
  <transparencyLevelInt>255</transparencyLevelInt>
  <renderer-v2 attr="MIN_TOP" symbollevels="0" type="categorizedSymbol">
    <categories>
      <category symbol="0" value="AB" label="Albeluvisol"/>
      <category symbol="1" value="ABal" label="Alic Albeluvisol"/>
      ...
    </categories>
    <symbols>
          <symbol outputUnit="MM" alpha="1" type="fill" name="0">
            <layer pass="0" class="SimpleFill" locked="0">
            <prop k="color" v="115,216,189,255"/>
            </layer>
          </symbol>
          <symbol outputUnit="MM" alpha="1" type="fill" name="1">
            <layer pass="0" class="SimpleFill" locked="0">
            <prop k="color" v="115,154,211,255"/>
            </layer>
          </symbol>
          ...
    </symbols>
  </renderer-v2>
</qgis>

..对于文本文件中的每一行,应创建具有适当值、标签和颜色 ('v') 的类别和符号,符号名称为 0 到 n。

我想为此使用 R-Package XML - 这可行吗?

编辑

这就是我尝试过的,但很快就卡住了:

The txt-file..
Value   Label   v
AB  Albeluvisol 76,123,181,255
ABal    Alic Albeluvisol    166,229,79,255
ABap    Abruptic Albeluvisol    203,101,0,255
ABar    Arenic Albeluvisol  52,126,43,255
ABau    Alumic Albeluvisol  69,202,22,255
ABeun   Endoeutric Albeluvisol  141,159,172,255
ABfg    Fragic Albeluvisol  160,19,146,255
ABfr    Ferric Albeluvisol  21,228,207,255
ABge    Gelic Albeluvisol   131,52,191,255
ABgl    Gleyic Albeluvisol  46,192,91,255
ABha    Haplic Albeluvisol  86,171,183,255
ABhi    Histic Albeluvisol  204,147,127,255
ABsl    Siltic Albeluvisol  93,3,234,255
ABst    Stagnic Albeluvisol 175,219,207,255
ABum    Umbric Albeluvisol  97,118,95,255
AC  Acrisol 37,223,37,255
ACab    Albic Acrisol   66,93,142,255
ACan    Andic Acrisol   87,125,156,255
ACap    Abruptic Acrisol    58,11,251,255
ACar    Arenic Acrisol  254,179,2,255
ACau    Alumic Acrisol  228,147,46,255
ACcr    Chromic Acrisol 109,48,156,255
ACdyh   Hyperdystric Acrisol    203,86,138,255
ACfr    Ferric Acrisol  16,219,128,255
ACgl    Gleyic Acrisol  69,60,134,255
ACgr    Geric Acrisol   73,224,129,255
ACha    Haplic Acrisol  54,116,89,255
AChu    Humic Acrisol   241,76,173,255
ACle    Leptic Acrisol  39,147,130,255
ACll    Lamellic Acrisol    79,243,242,255
ACohh   Hyperochric Acrisol 98,53,169,255
ACpf    Profondic Acrisol   164,206,189,255
ACpl    Plinthic Acrisol    102,165,217,255
ACro    Rhodic Acrisol  18,105,158,255
ACsk    Skeletic Acrisol    212,190,222,255
ACst    Stagnic Acrisol 230,45,189,255
ACum    Umbric Acrisol  159,204,66,255
ACvi    Vitric Acrisol  105,101,90,255
ACvt    Vetic Acrisol   35,216,122,255
AL  Alisol  64,30,191,255
ALab    Albic Alisol    27,197,145,255
ALan    Andic Alisol    167,104,99,255
ALap    Abruptic Alisol 232,54,26,255
ALar    Arenic Alisol   193,17,246,255
ALcr    Chromic Alisol  236,16,244,255
ALdyh   Hyperdystric Alisol 101,172,147,255
ALfr    Ferric Alisol   157,248,133,255
ALgl    Gleyic Alisol   20,163,20,255
ALha    Haplic Alisol   76,0,12,255
ALhu    Humic Alisol    152,5,5,255
ALll    Lamellic Alisol 131,3,75,255
ALni    Nitic Alisol    255,214,234,255
ALpf    Profondic Alisol    212,196,222,255
ALpl    Plinthic Alisol 212,82,85,255
ALro    Rhodic Alisol   84,101,67,255
ALsk    Skeletic Alisol 93,144,151,255
ALst    Stagnic Alisol  113,223,47,255
ALum    Umbric Alisol   18,211,68,255
ALvr    Vertic Alisol   182,246,252,255
AN  Andosol 151,158,16,255
ANao    Acroxic Andosol 214,160,242,255
ANar    Arenic Andosol  161,253,63,255
ANca    Calcaric Andosol    255,21,136,255
ANdu    Duric Andosol   193,51,181,255
ANdy    Dystric Andosol 194,125,147,255
ANes    Eutrisilic Andosol  195,245,16,255
ANeu    Eutric Andosol  228,146,232,255
ANfu    Fulvic Andosol  229,160,139,255
ANgl    Gleyic Andosol  158,214,159,255
ANha    Haplic Andosol  200,157,120,255
ANhi    Histic Andosol  115,176,106,255
ANhy    Hydric Andosol  161,147,198,255
ANle    Leptic Andosol  77,250,147,255
ANlv    Luvic Andosol   169,29,249,255
ANme    Melanic Andosol 245,133,133,255
ANmo    Mollic Andosol  106,63,219,255
ANph    Pachic Andosol  250,43,114,255
ANpi    Placic Andosol  92,15,64,255
ANsi    Silic Andosol   93,2,140,255
ANsk    Skeletic Andosol    14,20,208,255
ANso    Sodic Andosol   115,74,84,255
ANth    Thaptic Andosol 204,59,247,255
ANum    Umbric Andosol  56,214,155,255
ANvi    Vitric Andosol  68,65,21,255
ANvt    Vetic Andosol   42,8,155,255
AR  Arenosol    26,85,235,255
ARab    Albic Arenosol  79,43,202,255
ARad    Aridic Arenosol 122,43,168,255
ARca    Calcaric Arenosol   205,237,73,255
ARduw   Hypoduric Arenosol  212,219,40,255
ARdy    Dystric Arenosol    207,216,152,255
AReu    Eutric Arenosol 64,122,207,255
ARfg    Fragic Arenosol 208,104,187,255
ARfl    Ferralic Arenosol   21,55,31,255
ARge    Gelic Arenosol  176,75,99,255
ARgl    Gleyic Arenosol 66,92,252,255
ARgp    Gypsiric Arenosol   145,147,80,255
ARha    Haplic Arenosol 72,80,88,255
ARll    Lamellic Arenosol   130,86,209,255
ARlvw   Hypoluvic Arenosol  218,146,132,255
ARpl    Plinthic Arenosol   94,18,68,255
ARpr    Protic Arenosol 202,75,198,255
ARru    Rubic Arenosol  244,30,13,255
ARszw   Hyposalic Arenosol  48,107,60,255
ARtf    Tephric Arenosol    50,118,100,255
ARye    Yermic Arenosol 70,97,89,255
AT  Anthrosol   119,149,97,255
ATar    Arenic Anthrosol    30,139,145,255
ATfl    Ferralic Anthrosol  227,65,73,255
ATgl    Gleyic Anthrosol    157,207,249,255
AThg    Hydragric Anthrosol 69,5,192,255
ATht    Hortic Anthrosol    195,227,4,255
ATir    Irragric Anthrosol  224,201,255,255
ATlv    Luvic Anthrosol 161,203,179,255
ATpa    Plaggic Anthrosol   198,173,202,255
ATrg    Regic Anthrosol 50,184,153,255
ATsd    Spodic Anthrosol    25,166,13,255
ATst    Stagnic Anthrosol   233,123,208,255
ATtr    Terric Anthrosol    11,110,112,255
CH  Chernozem   208,202,159,255
CHcc    Calcic Chernozem    65,43,96,255
CHch    Chernic Chernozem   232,148,121,255
CHgl    Gleyic Chernozem    64,10,237,255
CHgs    Glossic Chernozem   76,43,122,255
CHha    Haplic Chernozem    213,219,10,255
CHlv    Luvic Chernozem 146,167,123,255
CHsl    Siltic Chernozem    88,35,207,255
CHvm    Vermic Chernozem    198,239,124,255
CHvr    Vertic Chernozem    201,147,235,255
CL  Calcisol    242,128,106,255
CLad    Aridic Calcisol 80,4,246,255
CLcch   Hypercalcic Calcisol    212,161,162,255
CLccw   Hypocalcic Calcisol 220,208,102,255
CLgl    Gleyic Calcisol 114,181,121,255
CLha    Haplic Calcisol 73,193,220,255
CLle    Leptic Calcisol 45,163,58,255
CLlv    Luvic Calcisol  169,39,235,255
CLohh   Hyperochric Calcisol    134,58,236,255
CLpt    Petric Calcisol 4,208,71,255
CLsk    Skeletic Calcisol   116,185,186,255
CLso    Sodic Calcisol  123,202,17,255
CLszn   Endosalic Calcisol  251,155,149,255
CLty    Takyric Calcisol    20,23,177,255
CLvr    Vertic Calcisol 208,122,73,255
CLye    Yermic Calcisol 125,192,190,255
CM  Cambisol    112,232,215,255
CMad    Aridic Cambisol 229,151,59,255
CMan    Andic Cambisol  30,246,208,255
CMca    Calcaric Cambisol   223,171,62,255
CMcr    Chromic Cambisol    118,105,203,255
CMdy    Dystric Cambisol    118,2,11,255
CMeu    Eutric Cambisol 185,45,197,255
CMfl    Ferralic Cambisol   130,30,106,255
CMfv    Fluvic Cambisol 242,143,79,255
CMge    Gelic Cambisol  57,186,188,255
CMgl    Gleyic Cambisol 71,16,71,255
CMgp    Gypsiric Cambisol   218,169,80,255
CMgt    Gelistagnic Cambisol    3,184,97,255
CMha    Haplic Cambisol 184,65,159,255
CMle    Leptic Cambisol 191,68,25,255
CMmo    Mollic Cambisol 101,217,57,255
CMohh   Hyperochric Cambisol    72,23,62,255
CMpl    Plinthic Cambisol   118,154,204,255
CMro    Rhodic Cambisol 127,128,252,255
CMsk    Skeletic Cambisol   106,90,89,255
CMso    Sodic Cambisol  166,142,119,255
CMst    Stagnic Cambisol    199,13,67,255
CMszn   Endosalic Cambisol  185,11,119,255
CMty    Takyric Cambisol    100,129,2,255
CMvi    Vitric Cambisol 114,196,6,255
CMvr    Vertic Cambisol 14,244,243,255
CMye    Yermic Cambisol 86,220,211,255
CR  Cryosol 192,38,151,255
CRad    Aridic Cryosol  154,30,42,255
CRan    Andic Cryosol   197,198,203,255
CRcc    Calcic Cryosol  126,101,90,255
CRgc    Glacic Cryosol  146,52,8,255
CRgl    Gleyic Cryosol  135,185,52,255
CRgy    Gypsic Cryosol  176,157,25,255
CRha    Haplic Cryosol  62,17,230,255
CRhi    Histic Cryosol  129,12,15,255
CRle    Leptic Cryosol  182,10,48,255
CRli    Lithic Cryosol  200,81,142,255
CRmo    Mollic Cryosol  147,18,58,255
CRna    Natric Cryosol  240,238,130,255
CRoa    Oxyaquic Cryosol    152,52,161,255
CRst    Stagnic Cryosol 182,89,30,255
CRsz    Salic Cryosol   104,215,8,255
CRti    Thionic Cryosol 211,234,204,255
CRtu    Turbic Cryosol  206,170,116,255
CRum    Umbric Cryosol  237,70,165,255
CRye    Yermic Cryosol  25,240,184,255
DU  Durisol 210,232,69,255
DUad    Aridic Durisol  2,62,249,255
DUar    Arenic Durisol  41,54,2,255
DUcc    Calcic Durisol  252,164,90,255
DUcr    Chromic Durisol 50,71,19,255
DUgy    Gypsic Durisol  112,194,144,255
DUha    Haplic Durisol  226,79,8,255
DUle    Leptic Durisol  88,168,134,255
DUlv    Luvic Durisol   35,65,181,255
DUohh   Hyperochric Durisol 100,253,38,255
DUpt    Petric Durisol  22,79,108,255
DUty    Takyric Durisol 28,79,239,255
DUvr    Vertic Durisol  198,28,163,255
DUye    Yermic Durisol  66,47,52,255
FL  Fluvisol    198,124,170,255
FLad    Aridic Fluvisol 21,252,189,255
FLar    Arenic Fluvisol 29,191,188,255
FLca    Calcaric Fluvisol   105,211,135,255
FLdy    Dystric Fluvisol    33,30,231,255
FLeu    Eutric Fluvisol 17,40,247,255
FLge    Gelic Fluvisol  189,184,102,255
FLgl    Gleyic Fluvisol 195,201,96,255
FLgp    Gypsiric Fluvisol   240,248,131,255
FLha    Haplic Fluvisol 10,36,174,255
FLhi    Histic Fluvisol 230,82,240,255
FLhu    Humic Fluvisol  55,34,14,255
FLmo    Mollic Fluvisol 115,201,133,255
FLsk    Skeletic Fluvisol   30,17,171,255
FLso    Sodic Fluvisol  85,129,223,255
FLst    Stagnic Fluvisol    111,107,242,255
FLsz    Salic Fluvisol  202,95,14,255
FLtf    Tephric Fluvisol    61,242,159,255
FLti    Thionic Fluvisol    131,22,140,255
FLty    Takyric Fluvisol    78,166,119,255
FLum    Umbric Fluvisol 222,18,144,255
FLye    Yermic Fluvisol 38,115,250,255
FR  Ferralsol   142,76,47,255
FRac    Acric Ferralsol 188,224,54,255
FRan    Andic Ferralsol 116,88,74,255
FRar    Arenic Ferralsol    95,177,72,255
FRau    Alumic Ferralsol    235,201,54,255
FRdyh   Hyperdystric Ferralsol  109,216,243,255
FReuh   Hypereutric Ferralsol   50,210,79,255
FRfr    Ferric Ferralsol    235,59,156,255
FRgi    Gibbsic Ferralsol   147,154,195,255
FRgl    Gleyic Ferralsol    148,39,244,255
FRgr    Geric Ferralsol 248,136,98,255
FRha    Haplic Ferralsol    106,58,96,255
FRhi    Histic Ferralsol    154,79,133,255
FRhu    Humic Ferralsol 42,103,202,255
FRlx    Lixic Ferralsol 17,112,62,255
FRmo    Mollic Ferralsol    46,229,0,255
FRpl    Plinthic Ferralsol  150,104,192,255
FRpo    Posic Ferralsol 131,78,171,255
FRro    Rhodic Ferralsol    206,207,101,255
FRstn   Endostagnic Ferralsol   193,137,31,255
FRum    Umbric Ferralsol    230,49,229,255
FRvt    Vetic Ferralsol 130,160,13,255
FRxa    Xanthic Ferralsol   35,125,138,255
GL  Gleysol 127,218,62,255
GLan    Andic Gleysol   190,61,143,255
GLap    Abruptic Gleysol    128,235,75,255
GLaq    Anthraquic Gleysol  15,133,162,255
GLar    Arenic Gleysol  168,189,132,255
GLau    Alumic Gleysol  90,235,164,255
GLax    Alcalic Gleysol 13,167,150,255
GLca    Calcaric Gleysol    236,71,32,255
GLcc    Calcic Gleysol  246,238,4,255
GLdy    Dystric Gleysol 221,178,61,255
GLeu    Eutric Gleysol  69,111,195,255
GLge    Gelic Gleysol   183,25,103,255
GLgy    Gypsic Gleysol  185,183,151,255
GLha    Haplic Gleysol  168,243,164,255
GLhi    Histic Gleysol  70,171,201,255
GLhu    Humic Gleysol   13,8,68,255
GLmo    Mollic Gleysol  49,151,106,255
GLpl    Plinthic Gleysol    108,128,22,255
GLso    Sodic Gleysol   189,139,43,255
GLszn   Endosalic Gleysol   187,98,122,255
GLtf    Tephric Gleysol 197,9,103,255
GLti    Thionic Gleysol 167,92,156,255
GLtx    Toxic Gleysol   254,14,58,255
GLty    Takyric Gleysol 59,90,251,255
GLum    Umbric Gleysol  209,11,238,255
GLvi    Vitric Gleysol  204,107,70,255
GY  Gypsisol    152,212,112,255
GYad    Aridic Gypsisol 168,60,62,255
GYaz    Arzic Gypsisol  90,198,153,255
GYcc    Calcic Gypsisol 25,12,129,255
GYdu    Duric Gypsisol  222,139,245,255
GYgyh   Hypergypsic Gypsisol    254,255,7,255
GYgyw   Hypogypsic Gypsisol 85,241,120,255
GYha    Haplic Gypsisol 54,206,224,255
GYle    Leptic Gypsisol 232,174,54,255
GYlv    Luvic Gypsisol  6,234,204,255
GYohh   Hyperochric Gypsisol    88,151,189,255
GYpt    Petric Gypsisol 63,198,53,255
GYsk    Skeletic Gypsisol   201,226,6,255
GYso    Sodic Gypsisol  71,145,27,255
GYszn   Endosalic Gypsisol  244,4,192,255
GYty    Takyric Gypsisol    244,140,37,255
GYvr    Vertic Gypsisol 243,54,76,255
GYye    Yermic Gypsisol 135,239,26,255
HS  Histosol    119,191,213,255
HSax    Alcalic Histosol    67,172,152,255
HScy    Cryic Histosol  133,160,16,255
HSdy    Dystric Histosol    81,188,246,255
HSeu    Eutric Histosol 122,254,156,255
HSfi    Fibric Histosol 209,133,237,255
HSfo    Folic Histosol  83,168,152,255
HSgc    Glacic Histosol 197,26,29,255
HSge    Gelic Histosol  20,24,167,255
HSom    Ombric Histosol 252,190,95,255
HSrh    Rheic Histosol  16,0,179,255
HSsa    Sapric Histosol 186,6,20,255
HSsz    Salic Histosol  67,90,49,255
HSti    Thionic Histosol    218,160,22,255
HStx    Toxic Histosol  234,29,227,255
KS  Kastanozem  213,33,238,255
KSam    Anthric Kastanozem  235,26,229,255
KScc    Calcic Kastanozem   139,65,46,255
KScr    Chromic Kastanozem  14,12,102,255
KSgy    Gypsic Kastanozem   50,123,155,255
KSha    Haplic Kastanozem   9,197,253,255
KSlv    Luvic Kastanozem    152,64,129,255
KSsl    Siltic Kastanozem   215,227,93,255
KSsow   Hyposodic Kastanozem    212,69,73,255
KSvr    Vertic Kastanozem   91,41,73,255
LP  Leptosol    178,8,165,255
LPad    Aridic Leptosol 13,216,25,255
LPca    Calcaric Leptosol   86,27,147,255
LPdy    Dystric Leptosol    49,107,247,255
LPeu    Eutric Leptosol 216,80,30,255
LPge    Gelic Leptosol  200,146,30,255
LPgl    Gleyic Leptosol 147,8,34,255
LPgp    Gypsiric Leptosol   38,148,228,255
LPha    Haplic Leptosol 122,190,124,255
LPhk    Hyperskeletic Leptosol  85,87,152,255
LPhu    Humic Leptosol  231,249,182,255
LPli    Lithic Leptosol 190,64,91,255
LPmo    Mollic Leptosol 215,42,244,255
LPrz    Rendzic Leptosol    125,184,158,255
LPum    Umbric Leptosol 193,60,195,255
LPvr    Vertic Leptosol 106,14,68,255
LPye    Yermic Leptosol 205,20,156,255
LV  Luvisol 250,255,201,255
LVab    Albic Luvisol   207,214,157,255
LVan    Andic Luvisol   252,157,0,255
LVar    Arenic Luvisol  77,244,136,255
LVcc    Calcic Luvisol  125,127,129,255
LVcr    Chromic Luvisol 221,43,130,255
LVct    Cutanic Luvisol 183,127,78,255
LVdy    Dystric Luvisol 30,208,6,255
LVfr    Ferric Luvisol  109,191,29,255
LVgl    Gleyic Luvisol  233,234,220,255
LVha    Haplic Luvisol  59,235,167,255
LVle    Leptic Luvisol  61,26,236,255
LVll    Lamellic Luvisol    60,224,60,255
LVohh   Hyperochric Luvisol 109,84,254,255
LVpf    Profondic Luvisol   159,172,54,255
LVro    Rhodic Luvisol  6,22,141,255
LVsow   Hyposodic Luvisol   220,91,21,255
LVst    Stagnic Luvisol 151,128,197,255
LVvi    Vitric Luvisol  72,149,146,255
LVvr    Vertic Luvisol  41,174,218,255
LX  Lixisol 67,103,228,255
LXab    Albic Lixisol   242,7,137,255
LXan    Andic Lixisol   38,115,5,255
LXap    Abruptic Lixisol    203,97,148,255
LXar    Arenic Lixisol  60,188,156,255
LXcc    Calcic Lixisol  58,33,96,255
LXcr    Chromic Lixisol 141,181,157,255
LXfr    Ferric Lixisol  60,253,26,255
LXgl    Gleyic Lixisol  194,85,49,255
LXgr    Geric Lixisol   28,86,212,255
LXha    Haplic Lixisol  76,40,46,255
LXhu    Humic Lixisol   94,57,115,255
LXle    Leptic Lixisol  111,128,91,255
LXll    Lamellic Lixisol    200,194,74,255
LXohh   Hyperochric Lixisol 117,235,76,255
LXpf    Profondic Lixisol   38,12,182,255
LXpl    Plinthic Lixisol    49,116,219,255
LXro    Rhodic Lixisol  145,189,232,255
LXst    Stagnic Lixisol 145,216,71,255
LXvi    Vitric Lixisol  22,103,77,255
LXvt    Vetic Lixisol   119,43,28,255
NT  Nitisol 197,13,235,255
NTal    Alic Nitisol    167,138,189,255
NTan    Andic Nitisol   99,127,240,255
NTau    Alumic Nitisol  173,134,157,255
NTdy    Dystric Nitisol 10,78,148,255
NTeu    Eutric Nitisol  187,180,156,255
NTfl    Ferralic Nitisol    69,24,240,255
NTha    Haplic Nitisol  75,53,140,255
NThu    Humic Nitisol   231,97,2,255
NTmo    Mollic Nitisol  55,139,127,255
NTro    Rhodic Nitisol  51,48,157,255
NTum    Umbric Nitisol  140,216,1,255
NTvt    Vetic Nitisol   120,156,20,255
PH  Phaeozem    239,57,36,255
PHab    Albic Phaeozem  183,35,207,255
PHan    Andic Phaeozem  146,61,124,255
PHap    Abruptic Phaeozem   130,35,0,255
PHca    Calcaric Phaeozem   245,227,68,255
PHcr    Chromic Phaeozem    107,204,59,255
PHgl    Gleyic Phaeozem 147,98,87,255
PHgs    Glossic Phaeozem    151,5,83,255
PHgz    Greyic Phaeozem 107,137,235,255
PHha    Haplic Phaeozem 148,9,175,255
PHle    Leptic Phaeozem 135,189,182,255
PHlv    Luvic Phaeozem  170,117,168,255
PHph    Pachic Phaeozem 226,181,220,255
PHsk    Skeletic Phaeozem   154,32,251,255
PHsl    Siltic Phaeozem 159,121,224,255
PHso    Sodic Phaeozem  0,19,219,255
PHst    Stagnic Phaeozem    91,90,71,255
PHtf    Tephric Phaeozem    109,141,139,255
PHvi    Vitric Phaeozem 194,154,144,255
PHvm    Vermic Phaeozem 138,22,21,255
PHvr    Vertic Phaeozem 106,79,87,255
PL  Planosol    248,196,204,255
PLab    Albic Planosol  94,244,210,255
PLal    Alic Planosol   150,58,110,255
PLar    Arenic Planosol 242,163,43,255
PLau    Alumic Planosol 126,155,66,255
PLax    Alcalic Planosol    107,171,139,255
PLca    Calcaric Planosol   1,191,172,255
PLcc    Calcic Planosol 122,169,24,255
PLcr    Chromic Planosol    79,167,27,255
PLdy    Dystric Planosol    168,6,18,255
PLeu    Eutric Planosol 85,123,0,255
PLfr    Ferric Planosol 6,77,146,255
PLge    Gelic Planosol  73,11,142,255
PLgl    Gleyic Planosol 239,251,13,255
PLgr    Geric Planosol  78,253,185,255
PLgy    Gypsic Planosol 163,138,162,255
PLha    Haplic Planosol 160,153,85,255
PLhi    Histic Planosol 58,23,184,255
PLlv    Luvic Planosol  251,108,42,255
PLmo    Mollic Planosol 8,33,170,255
PLpf?   Petroferric Planosol    141,230,198,255
PLpl    Plinthic Planosol   119,253,212,255
PLro    Rhodic Planosol 84,86,65,255
PLso    Sodic Planosol  52,246,157,255
PLszn   Endosalic Planosol  16,49,92,255
PLti    Thionic Planosol    93,59,177,255
PLum    Umbric Planosol 157,33,39,255
PLvr    Vertic Planosol 148,63,204,255
PT  Plinthosol  167,201,92,255
PTab    Albic Plinthosol    203,36,244,255
PTac    Acric Plinthosol    123,153,203,255
PTal    Alic Plinthosol 131,42,189,255
PTap    Abruptic Plinthosol 68,51,2,255
PTau    Alumic Plinthosol   102,192,204,255
PTdun   Endoduric Plinthosol    168,87,50,255
PTeun   Endoeutric Plinthosol   105,74,174,255
PTfr    Ferric Plinthosol   165,87,125,255
PTgr    Geric Plinthosol    191,114,241,255
PTgs    Glossic Plinthosol  105,136,157,255
PTha    Haplic Plinthosol   61,91,96,255
PThu    Humic Plinthosol    214,231,254,255
PTph    Pachic Plinthosol   227,213,175,255
PTpt    Petric Plinthosol   244,13,110,255
PTst    Stagnic Plinthosol  144,56,223,255
PTum    Umbric Plinthosol   50,132,113,255
PTvt    Vetic Plinthosol    227,178,29,255
PZ  Podzol  232,94,33,255
PZam    Anthric Podzol  69,56,147,255
PZcb    Carbic Podzol   0,225,133,255
PZdn    Densic Podzol   51,118,169,255
PZet    Entic Podzol    228,15,53,255
PZfg    Fragic Podzol   213,23,97,255
PZge    Gelic Podzol    103,38,107,255
PZgl    Gleyic Podzol   162,9,63,255
PZha    Haplic Podzol   26,252,172,255
PZhi    Histic Podzol   77,40,90,255
PZll    Lamellic Podzol 28,119,215,255
PZpi    Placic Podzol   252,60,104,255
PZrs    Rustic Podzol   218,44,81,255
PZsk    Skeletic Podzol 74,46,189,255
PZst    Stagnic Podzol  155,220,24,255
PZum    Umbric Podzol   32,53,131,255
RG  Regosol 85,151,171,255
RGad    Aridic Regosol  75,2,140,255
RGah    Anthropic Regosol   154,230,254,255
RGai    Aric Regosol    141,60,195,255
RGanb   Thaptoandic Regosol 26,163,13,255
RGar    Arenic Regosol  136,191,201,255
RGca    Calcaric Regosol    134,170,122,255
RGdy    Dystric Regosol 233,128,189,255
RGeu    Eutric Regosol  123,154,60,255
RGga    Garbic Regosol  24,184,156,255
RGge    Gelic Regosol   20,9,21,255
RGgl    Gleyic Regosol  243,61,100,255
RGgp    Gypsiric Regosol    197,215,13,255
RGgt    Gelistagnic Regosol 133,116,47,255
RGha    Haplic Regosol  184,77,228,255
RGhu    Humic Regosol   157,38,155,255
RGle    Leptic Regosol  77,42,104,255
RGohh   Hyperochric Regosol 134,226,27,255
RGrd    Reductic Regosol    27,202,65,255
RGsk    Skeletic Regosol    239,20,191,255
RGsow   Hyposodic Regosol   15,114,183,255
RGsp    Spolic Regosol  49,128,36,255
RGst    Stagnic Regosol 71,228,33,255
RGszw   Hyposalic Regosol   26,242,34,255
RGtf    Tephric Regosol 237,139,228,255
RGty    Takyric Regosol 147,217,139,255
RGub    Urbic Regosol   94,78,126,255
RGvib   Thaptovitric Regosol    194,73,164,255
RGvm    Vermic Regosol  83,174,250,255
RGye    Yermic Regosol  196,211,24,255
SC  Solonchak   84,224,175,255
SCad    Aridic Solonchak    67,181,232,255
SCae    Aceric Solonchak    224,46,137,255
SCcc    Calcic Solonchak    156,215,99,255
SCcl    Chloridic Solonchak 217,76,38,255
SCcn    Carbonatic Solonchak    160,81,144,255
SCdu    Duric Solonchak 74,53,187,255
SCge    Gelic Solonchak 251,194,221,255
SCgl    Gleyic Solonchak    24,16,82,255
SCgy    Gypsic Solonchak    95,108,248,255
SCha    Haplic Solonchak    13,5,224,255
SChi    Histic Solonchak    35,110,46,255
SCmo    Mollic Solonchak    222,251,62,255
SCoh    Ochric Solonchak    127,168,202,255
SCps    Petrosalic Solonchak    29,80,178,255
SCso    Sodic Solonchak 62,217,219,255
SCst    Stagnic Solonchak   71,158,178,255
SCsu    Sulphatic Solonchak 251,213,88,255
SCszh   Hypersalic Solonchak    65,239,42,255
SCty    Takyric Solonchak   165,59,26,255
SCvr    Vertic Solonchak    41,184,229,255
SCye    Yermic Solonchak    254,167,1,255
SN  Solonetz    210,156,16,255
SNab    Albic Solonetz  102,167,94,255
SNad    Aridic Solonetz 112,116,164,255
SNcc    Calcic Solonetz 65,254,102,255
SNdu    Duric Solonetz  18,75,23,255
SNgl    Gleyic Solonetz 78,205,133,255
SNgy    Gypsic Solonetz 193,118,222,255
SNha    Haplic Solonetz 1,54,176,255
SNhu    Humic Solonetz  209,61,76,255
SNmg    Magnesic Solonetz   116,39,222,255
SNmo    Mollic Solonetz 231,123,231,255
SNst    Stagnic Solonetz    72,253,80,255
SNsz    Salic Solonetz  113,116,76,255
SNty    Takyric Solonetz    252,159,203,255
SNvr    Vertic Solonetz 198,204,138,255
SNye    Yermic Solonetz 205,158,19,255
UM  Umbrisol    147,204,64,255
UMab    Albic Umbrisol  45,198,125,255
UMam    Anthric Umbrisol    168,113,74,255
UMar    Arenic Umbrisol 65,33,42,255
UMfl    Ferralic Umbrisol   213,26,158,255
UMge    Gelic Umbrisol  162,102,137,255
UMgl    Gleyic Umbrisol 172,43,102,255
UMha    Haplic Umbrisol 79,33,21,255
UMhu    Humic Umbrisol  129,98,43,255
UMle    Leptic Umbrisol 146,117,15,255
UMsk    Skeletic Umbrisol   124,117,57,255
UMst    Stagnic Umbrisol    248,173,83,255
VR  Vertisol    134,115,133,255
VRal    Alic Vertisol   7,40,39,255
VRcc    Calcic Vertisol 207,105,83,255
VRcr    Chromic Vertisol    69,212,113,255
VRdu    Duric Vertisol  30,0,232,255
VReu    Eutric Vertisol 58,235,66,255
VRgm    Grumic Vertisol 229,76,31,255
VRgp    Gypsiric Vertisol   200,91,169,255
VRgy    Gypsic Vertisol 217,194,239,255
VRha    Haplic Vertisol 14,200,44,255
VRms    Mesotrophic Vertisol    43,45,135,255
VRmz    Mazic Vertisol  161,47,28,255
VRna    Natric Vertisol 46,14,227,255
VRpe    Pellic Vertisol 185,191,56,255
VRsow   Hyposodic Vertisol  73,189,178,255
VRsz    Salic Vertisol  47,180,175,255
VRti    Thionic Vertisol    125,212,179,255
1 1 11 1    Town    202,221,9,255
2 2 22 2    Soil disturbed by man   178,167,152,255
3 3 33 3    Water body  17,103,22,255
4 4 44 4    Marsh   103,31,242,255
5 5 55 5    Glacier 201,209,111,255
6 6 66 6    Rock outcrops   177,136,131,255
    No information  0,0,0,255

## R:
library(XML)

leg <- read.delim("D:/GIS_DataBase/Environmental_Data/soil/vector/WRB_FULL.txt", 
                  header = T, sep = "\t")

n <- nrow(leg)
name <- 0:(n-1)
value <- as.character(leg$Value)
v <- as.character(leg$v)
label <- as.character(leg$Label)

node_ctgs <- newXMLNode("categories")
node_symb <- newXMLNode("symbols")
node_lyr <- newXMLNode("layer")
node_prop <- newXMLNode("prop")

for (i in name) addChildren(node_ctgs, newXMLNode("category", attrs = c(symbol=name[i], value=value[i], label = label[i])))

我会这样进行,将节点一个接一个地放置..这合适吗?但是,我对如何制作循环以实现符号节点的嵌套结构一无所知。

4

1 回答 1

4

像您所做的那样发布您的数据是没有帮助的。最好使用dput或类似的东西。请看一下制作一个很棒的 R 示例

我手动调整了您的数据子集:

require(XML)
tf <- read.table(stringsAsFactors = FALSE, header = TRUE, text = 'Value Label v
AB  "Albeluvisol" "166,71,43,255"
ABal    "Alic Albeluvisol"    "173,114,101,255"
ABap    "Abruptic Albeluvisol"    "236,76,203,255"
ABar    "Arenic Albeluvisol"  "30,177,58,255"
ABau    "Alumic Albeluvisol"  "157,9,124,255"
ABeun   "Endoeutric Albeluvisol"  "69,16,63,255"
ABfg    "Fragic Albeluvisol"  "208,39,109,255"
ABfr    "Ferric Albeluvisol"  "196,209,39,255"
ABge    "Gelic Albeluvisol"   "93,27,59,255"
ABgl    "Gleyic Albeluvisol"  "232,125,4,255"
ABha    "Haplic Albeluvisol"  "0,34,146,255"
ABhi    "Histic Albeluvisol"  "98,99,192,255"
ABsl    "Siltic Albeluvisol"  "6,68,227,255"
ABst    "Stagnic Albeluvisol" "140,236,81,255"
ABum    "Umbric Albeluvisol"  "25,98,131,255"')

您可以构建 xml,只是构建具有属性的节点,然后通过子节点工作。

base = newXMLNode("qgis")
addAttributes(base,version="1.8.0-Lisboa",minimumScale="0",maximumScale="1e+08",hasScaleBasedVisibilityFlag="0")
trans <- newXMLNode("transparencyLevelInt", 255)
rend <- newXMLNode("renderer-v2", attrs = c(attr="MIN_TOP",symbollevels="0",type="categorizedSymbol"))
# sort the categories
categories <- newXMLNode("categories")
category <- lapply(seq_along(tf$Value),function(x){newXMLNode("category",
                                 attrs = c(symbol = as.character(x-1), value = tf$Value[x], label = tf$Label[x]))
                                 })
addChildren(categories,category)
# sort the symbols
symbols <- newXMLNode("symbols")
symbol <- lapply(seq_along(tf$Value),function(x){dum.sym <- newXMLNode("symbol",
                                 attrs = c(outputUnit="MM",alpha="1",type="fill",name=as.character(x-1)))
                                 layer <- newXMLNode("layer", attrs =c(pass="0",class="SimpleFill",locked="0"))
                                 prop <- newXMLNode("prop", attrs =c(k="color",v= tf$v[x]))
                                 addChildren(layer, prop)
                                 addChildren(dum.sym, layer)
                                 }) 

addChildren(symbols, symbol)

# add categories and symbols to rend
addChildren(rend, list(categories, symbols))

addChildren(base, list(trans, rend))

这应该给出:

> base
<qgis version="1.8.0-Lisboa" minimumScale="0" maximumScale="1e+08" hasScaleBasedVisibilityFlag="0">
  <transparencyLevelInt>255</transparencyLevelInt>
  <renderer-v2 attr="MIN_TOP" symbollevels="0" type="categorizedSymbol">
    <categories>
      <category symbol="0" value="AB" label="Albeluvisol"/>
      <category symbol="1" value="ABal" label="Alic Albeluvisol"/>
      <category symbol="2" value="ABap" label="Abruptic Albeluvisol"/>
      <category symbol="3" value="ABar" label="Arenic Albeluvisol"/>
      <category symbol="4" value="ABau" label="Alumic Albeluvisol"/>
      <category symbol="5" value="ABeun" label="Endoeutric Albeluvisol"/>
      <category symbol="6" value="ABfg" label="Fragic Albeluvisol"/>
      <category symbol="7" value="ABfr" label="Ferric Albeluvisol"/>
      <category symbol="8" value="ABge" label="Gelic Albeluvisol"/>
      <category symbol="9" value="ABgl" label="Gleyic Albeluvisol"/>
      <category symbol="10" value="ABha" label="Haplic Albeluvisol"/>
      <category symbol="11" value="ABhi" label="Histic Albeluvisol"/>
      <category symbol="12" value="ABsl" label="Siltic Albeluvisol"/>
      <category symbol="13" value="ABst" label="Stagnic Albeluvisol"/>
      <category symbol="14" value="ABum" label="Umbric Albeluvisol"/>
    </categories>
    <symbols>
      <symbol outputUnit="MM" alpha="1" type="fill" name="0">
        <layer pass="0" class="SimpleFill" locked="0">
          <prop k="color" v="166,71,43,255"/>
        </layer>
      </symbol>
      <symbol outputUnit="MM" alpha="1" type="fill" name="1">
        <layer pass="0" class="SimpleFill" locked="0">
          <prop k="color" v="173,114,101,255"/>
        </layer>
      </symbol>
      <symbol outputUnit="MM" alpha="1" type="fill" name="2">
        <layer pass="0" class="SimpleFill" locked="0">
          <prop k="color" v="236,76,203,255"/>
        </layer>
      </symbol>
      <symbol outputUnit="MM" alpha="1" type="fill" name="3">
        <layer pass="0" class="SimpleFill" locked="0">
          <prop k="color" v="30,177,58,255"/>
        </layer>
      </symbol>
      <symbol outputUnit="MM" alpha="1" type="fill" name="4">
        <layer pass="0" class="SimpleFill" locked="0">
          <prop k="color" v="157,9,124,255"/>
        </layer>
      </symbol>
      <symbol outputUnit="MM" alpha="1" type="fill" name="5">
        <layer pass="0" class="SimpleFill" locked="0">
          <prop k="color" v="69,16,63,255"/>
        </layer>
      </symbol>
      <symbol outputUnit="MM" alpha="1" type="fill" name="6">
        <layer pass="0" class="SimpleFill" locked="0">
          <prop k="color" v="208,39,109,255"/>
        </layer>
      </symbol>
      <symbol outputUnit="MM" alpha="1" type="fill" name="7">
        <layer pass="0" class="SimpleFill" locked="0">
          <prop k="color" v="196,209,39,255"/>
        </layer>
      </symbol>
      <symbol outputUnit="MM" alpha="1" type="fill" name="8">
        <layer pass="0" class="SimpleFill" locked="0">
          <prop k="color" v="93,27,59,255"/>
        </layer>
      </symbol>
      <symbol outputUnit="MM" alpha="1" type="fill" name="9">
        <layer pass="0" class="SimpleFill" locked="0">
          <prop k="color" v="232,125,4,255"/>
        </layer>
      </symbol>
      <symbol outputUnit="MM" alpha="1" type="fill" name="10">
        <layer pass="0" class="SimpleFill" locked="0">
          <prop k="color" v="0,34,146,255"/>
        </layer>
      </symbol>
      <symbol outputUnit="MM" alpha="1" type="fill" name="11">
        <layer pass="0" class="SimpleFill" locked="0">
          <prop k="color" v="98,99,192,255"/>
        </layer>
      </symbol>
      <symbol outputUnit="MM" alpha="1" type="fill" name="12">
        <layer pass="0" class="SimpleFill" locked="0">
          <prop k="color" v="6,68,227,255"/>
        </layer>
      </symbol>
      <symbol outputUnit="MM" alpha="1" type="fill" name="13">
        <layer pass="0" class="SimpleFill" locked="0">
          <prop k="color" v="140,236,81,255"/>
        </layer>
      </symbol>
      <symbol outputUnit="MM" alpha="1" type="fill" name="14">
        <layer pass="0" class="SimpleFill" locked="0">
          <prop k="color" v="25,98,131,255"/>
        </layer>
      </symbol>
    </symbols>
  </renderer-v2>
</qgis> 
于 2013-05-03T17:21:49.327 回答