0

我正在尝试使用SLD(样式化图层描述符)为将显示在映射服务器上的图层着色,但是我的 SLD 中存在错误,因此颜色错误。这是因为 SLD 使用随机十六进制值作为填充值。正确的十六进制值在 SLD 中,但它们不在正确的位置(它们被用作图层名称)。

这是 SLD 中的一个片段,它为一个功能着色(还有大约 850 个其他功能)。

<se:Name>#27D1D1</se:Name>
      <se:Description>
        <se:Title>#27D1D1</se:Title>
      </se:Description>
      <ogc:Filter xmlns:ogc="http://www.opengis.net/ogc">
        <ogc:PropertyIsEqualTo>
          <ogc:PropertyName>HEXCOLOR</ogc:PropertyName>
          <ogc:Literal>#27D1D1</ogc:Literal> <--I want this Hex value
        </ogc:PropertyIsEqualTo>
      </ogc:Filter>
      <se:PolygonSymbolizer>
        <se:Fill>
          <se:SvgParameter name="fill">#cd42a3</se:SvgParameter>  <--- Put here
        </se:Fill>
        <se:Stroke>
          <se:SvgParameter name="stroke">#000001</se:SvgParameter>
          <se:SvgParameter name="stroke-width">1</se:SvgParameter>
          <se:SvgParameter name="stroke-linejoin">bevel</se:SvgParameter>
        </se:Stroke>
      </se:PolygonSymbolizer>
    </se:Rule>
    <se:Rule>

有没有办法 SED 或类似的方法可以将十六进制值从 Literal 复制并粘贴到 Fill?

4

2 回答 2

1

用 sed

sed -E '/Literal/{h;s/([^#]*)(#[^<]*)(.*)/\2/;x};/fill/G;s/([^#]*)(#[^<]*)([^\n]*)\n(.*)/\1\4\3/' SLDfile

当您看到带有文字的行时,请将十六进制数保留在保留空间中。

当您看到一行填充时,将十六进制数与保留空间中的十六进制数交换

于 2017-11-05T11:01:35.773 回答
1

I think this does what you want:

awk '/ogc:Literal/{split($0,a,/[><]/);hex=a[3]} /se:SvgParameter name="fill"/{sub(/#[0-9a-fA-F]*/,hex)} 1' YourFile

So, that says... "If you see the string ogc:Literal, split the line using > and < as separators and put the elements into array a. Save a[3] in a variable called hex for later use. If you see a line containing se:SvgParameter name="fill", substitute anything that looks like a hex value in that line with the variable hex you remembered earlier. The 1 at the end means awk should do its default action, which is to print the line."

If you want to save the modified file, use:

awk ... YourExistingFile > ModifiedFile
于 2017-11-05T10:15:24.827 回答