外部图形和属性规则的 Geoserver SLD 样式问题

Posted

技术标签:

【中文标题】外部图形和属性规则的 Geoserver SLD 样式问题【英文标题】:Geoserver SLD styling issue with external graphics and attribute rules 【发布时间】:2013-05-02 19:16:20 【问题描述】:

我正在为 Geoserver wms 层创建 SLD。 SLD 验证无误,但图标不会显示在地图中。我正在使用基于属性的规则来比较字符串,以便为正确的功能显示正确的图像。这是我的代码,感谢您的帮助!

<?xml version="1.0" encoding="ISO-8859-1"?>
<StyledLayerDescriptor version="1.0.0" 
xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd" 
xmlns="http://www.opengis.net/sld" 
xmlns:ogc="http://www.opengis.net/ogc" 
xmlns:xlink="http://www.w3.org/1999/xlink" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<NamedLayer>
<Name>Upper Shore Image Points</Name>
<UserStyle>
  <Title>Vendor Points</Title>
  <FeatureTypeStyle>
  <Rule>
   <Name>Famers Market</Name>
    <Title>All Farmers Markets</Title>
      <ogc:Filter>
        <ogc:PropertyIsLike wildCard="*" singleChar="." escape="!">
           <ogc:PropertyName>type</ogc:PropertyName>
           <ogc:Literal>farmers maket vendor</ogc:Literal>
         </ogc:PropertyIsLike>
       </ogc:Filter>
      <PointSymbolizer>
        <Graphic>
          <ExternalGraphic>
            <OnlineResource
              xlink:type="simple"
              xlink:href="Farmers Markets.jpg" />
            <Format>image/jpeg</Format>
          </ExternalGraphic>
          <Size>32</Size>
        </Graphic>
      </PointSymbolizer>
    </Rule>
   <Rule>
   <Name>Fruit and Vegetable</Name>
    <Title>All Fruit and Vegetable</Title>
      <ogc:Filter>
        <ogc:PropertyIsLike wildCard="*" singleChar="." escape="!">
           <ogc:PropertyName>type</ogc:PropertyName>
           <ogc:Literal>Fruit and Vegetable Farm</ogc:Literal>
         </ogc:PropertyIsLike>
       </ogc:Filter>
      <PointSymbolizer>
        <Graphic>
          <ExternalGraphic>
            <OnlineResource
              xlink:type="simple"
              xlink:href="Fruit and Vegetable Farms.jpg" />
            <Format>image/jpeg</Format>
          </ExternalGraphic>
          <Size>32</Size>
        </Graphic>
      </PointSymbolizer>
    </Rule>
 <Rule>
   <Name>Horse Stable</Name>
    <Title>All Horse Stables</Title>
      <ogc:Filter>
        <ogc:PropertyIsLike wildCard="*" singleChar="." escape="!">
           <ogc:PropertyName>type</ogc:PropertyName>
           <ogc:Literal>Horse Stable</ogc:Literal>
         </ogc:PropertyIsLike>
       </ogc:Filter>
      <PointSymbolizer>
        <Graphic>
          <ExternalGraphic>
            <OnlineResource
              xlink:type="simple"
              xlink:href="Horse Stable.jpg" />
            <Format>image/jpeg</Format>
          </ExternalGraphic>
          <Size>32</Size>
        </Graphic>
      </PointSymbolizer>
    </Rule>
     <Rule>
   <Name>Wool Products</Name>
    <Title>All Wool Products</Title>
      <ogc:Filter>
        <ogc:PropertyIsLike wildCard="*" singleChar="." escape="!">
           <ogc:PropertyName>type</ogc:PropertyName>
           <ogc:Literal>Wool Products</ogc:Literal>
         </ogc:PropertyIsLike>
       </ogc:Filter>
      <PointSymbolizer>
        <Graphic>
          <ExternalGraphic>
            <OnlineResource
              xlink:type="simple"
              xlink:href="Wool Products.jpg" />
            <Format>image/jpeg</Format>
          </ExternalGraphic>
          <Size>32</Size>
        </Graphic>
      </PointSymbolizer>
    </Rule>
     <Rule>
   <Name>Restaurant</Name>
    <Title>All Restaurants</Title>
      <ogc:Filter>
        <ogc:PropertyIsLike wildCard="*" singleChar="." escape="!">
           <ogc:PropertyName>type</ogc:PropertyName>
           <ogc:Literal>Restaurant</ogc:Literal>
         </ogc:PropertyIsLike>
       </ogc:Filter>
      <PointSymbolizer>
        <Graphic>
          <ExternalGraphic>
            <OnlineResource
              xlink:type="simple"
              xlink:href="Restaurant.jpg" />
            <Format>image/jpeg</Format>
          </ExternalGraphic>
          <Size>32</Size>
        </Graphic>
      </PointSymbolizer>
    </Rule>
     <Rule>
   <Name>Coffee Roasting</Name>
    <Title>All Coffee Roasting</Title>
      <ogc:Filter>
        <ogc:PropertyIsLike wildCard="*" singleChar="." escape="!">
           <ogc:PropertyName>type</ogc:PropertyName>
           <ogc:Literal>Coffee Roasting</ogc:Literal>
         </ogc:PropertyIsLike>
       </ogc:Filter>
      <PointSymbolizer>
        <Graphic>
          <ExternalGraphic>
            <OnlineResource
              xlink:type="simple"
              xlink:href="Coffee Roasting.jpg" />
            <Format>image/jpeg</Format>
          </ExternalGraphic>
          <Size>32</Size>
        </Graphic>
      </PointSymbolizer>
    </Rule>
     <Rule>
   <Name>Charter Service</Name>
    <Title>All Charter Services</Title>
      <ogc:Filter>
        <ogc:PropertyIsLike wildCard="*" singleChar="." escape="!">
           <ogc:PropertyName>type</ogc:PropertyName>
           <ogc:Literal>Charter Service</ogc:Literal>
         </ogc:PropertyIsLike>
       </ogc:Filter>
      <PointSymbolizer>
        <Graphic>
          <ExternalGraphic>
            <OnlineResource
              xlink:type="simple"
              xlink:href="Charter Service.jpg" />
            <Format>image/jpeg</Format>
          </ExternalGraphic>
          <Size>32</Size>
        </Graphic>
      </PointSymbolizer>
    </Rule>
     <Rule>
   <Name>Apiary</Name>
    <Title>All Apiaries</Title>
      <ogc:Filter>
        <ogc:PropertyIsLike wildCard="*" singleChar="." escape="!">
           <ogc:PropertyName>type</ogc:PropertyName>
           <ogc:Literal>Apiary</ogc:Literal>
         </ogc:PropertyIsLike>
       </ogc:Filter>
      <PointSymbolizer>
        <Graphic>
          <ExternalGraphic>
            <OnlineResource
              xlink:type="simple"
              xlink:href="Apiary.jpg" />
            <Format>image/jpeg</Format>
          </ExternalGraphic>
          <Size>32</Size>
        </Graphic>
      </PointSymbolizer>
    </Rule>
     <Rule>
   <Name>Vineyard</Name>
    <Title>All Vineyards</Title>
      <ogc:Filter>
        <ogc:PropertyIsLike wildCard="*" singleChar="." escape="!">
           <ogc:PropertyName>type</ogc:PropertyName>
           <ogc:Literal>Vineyard</ogc:Literal>
         </ogc:PropertyIsLike>
       </ogc:Filter>
      <PointSymbolizer>
        <Graphic>
          <ExternalGraphic>
            <OnlineResource
              xlink:type="simple"
              xlink:href="Vineyard.jpg" />
            <Format>image/jpeg</Format>
          </ExternalGraphic>
          <Size>32</Size>
        </Graphic>
      </PointSymbolizer>
    </Rule>
     <Rule>
   <Name>Retail Seafood</Name>
    <Title>All Retail Seafood</Title>
      <ogc:Filter>
        <ogc:PropertyIsLike wildCard="*" singleChar="." escape="!">
           <ogc:PropertyName>type</ogc:PropertyName>
           <ogc:Literal>Retail Seafood</ogc:Literal>
         </ogc:PropertyIsLike>
       </ogc:Filter>
      <PointSymbolizer>
        <Graphic>
          <ExternalGraphic>
            <OnlineResource
              xlink:type="simple"
              xlink:href="Retail Seafood.jpg" />
            <Format>image/jpeg</Format>
          </ExternalGraphic>
          <Size>32</Size>
        </Graphic>
      </PointSymbolizer>
    </Rule>
     <Rule>
   <Name>Bakery</Name>
    <Title>All Bakeries</Title>
      <ogc:Filter>
        <ogc:PropertyIsLike wildCard="*" singleChar="." escape="!">
           <ogc:PropertyName>type</ogc:PropertyName>
           <ogc:Literal>Bakery</ogc:Literal>
         </ogc:PropertyIsLike>
       </ogc:Filter>
      <PointSymbolizer>
        <Graphic>
          <ExternalGraphic>
            <OnlineResource
              xlink:type="simple"
              xlink:href="Bakery.jpg" />
            <Format>image/jpeg</Format>
          </ExternalGraphic>
          <Size>32</Size>
        </Graphic>
      </PointSymbolizer>
    </Rule>
     <Rule>
       <Name>Dairy/Eggs</Name>
       <Title>All Dairy/ Eggs</Title>
      <ogc:Filter>
        <ogc:PropertyIsLike wildCard="*" singleChar="." escape="!">
           <ogc:PropertyName>type</ogc:PropertyName>
          <ogc:Literal>Dairy/Eggs</ogc:Literal>
         </ogc:PropertyIsLike>
       </ogc:Filter>
      <PointSymbolizer>
        <Graphic>
          <ExternalGraphic>
            <OnlineResource
              xlink:type="simple"
              xlink:href="Dairy_Eggs.jpg" />
            <Format>image/jpeg</Format>
          </ExternalGraphic>
          <Size>32</Size>
        </Graphic>
      </PointSymbolizer>
    </Rule>
     <Rule>
   <Name>Christmas Tree Farm</Name>
    <Title>All Christmas Tree Farms</Title>
      <ogc:Filter>
        <ogc:PropertyIsLike wildCard="*" singleChar="." escape="!">
           <ogc:PropertyName>type</ogc:PropertyName>
           <ogc:Literal>Christmas Tree Farm</ogc:Literal>
         </ogc:PropertyIsLike>
       </ogc:Filter>
      <PointSymbolizer>
        <Graphic>
          <ExternalGraphic>
            <OnlineResource
              xlink:type="simple"
              xlink:href="Christmas Tree Farm.jpg" />
            <Format>image/jpeg</Format>
          </ExternalGraphic>
          <Size>32</Size>
        </Graphic>
      </PointSymbolizer>
    </Rule>
     <Rule>
       <Name>Grains</Name>
       <Title>All Grain Farms</Title>
      <ogc:Filter>
        <ogc:PropertyIsLike wildCard="*" singleChar="." escape="!">
           <ogc:PropertyName>type</ogc:PropertyName>
          <ogc:Literal>Grains</ogc:Literal>
         </ogc:PropertyIsLike>
       </ogc:Filter>
      <PointSymbolizer>
        <Graphic>
          <ExternalGraphic>
            <OnlineResource
              xlink:type="simple"
              xlink:href="Grains.jpg" />
            <Format>image/jpeg</Format>
          </ExternalGraphic>
          <Size>32</Size>
        </Graphic>
      </PointSymbolizer>
    </Rule>
     <Rule>
   <Name>Meat Products</Name>
    <Title>All Meat Products</Title>
      <ogc:Filter>
        <ogc:PropertyIsLike wildCard="*" singleChar="." escape="!">
           <ogc:PropertyName>type</ogc:PropertyName>
           <ogc:Literal>Meat Products</ogc:Literal>
         </ogc:PropertyIsLike>
       </ogc:Filter>
      <PointSymbolizer>
        <Graphic>
          <ExternalGraphic>
            <OnlineResource
              xlink:type="simple"
              xlink:href="Meat.jpg" />
            <Format>image/jpeg</Format>
          </ExternalGraphic>
          <Size>32</Size>
        </Graphic>
      </PointSymbolizer>
    </Rule>
     <Rule>
   <Name>Nursery</Name>
    <Title>All Nurseries</Title>
      <ogc:Filter>
        <ogc:PropertyIsLike wildCard="*" singleChar="." escape="!">
           <ogc:PropertyName>type</ogc:PropertyName>
           <ogc:Literal>Nursery</ogc:Literal>
         </ogc:PropertyIsLike>
       </ogc:Filter>
      <PointSymbolizer>
        <Graphic>
          <ExternalGraphic>
            <OnlineResource
              xlink:type="simple"
              xlink:href="Nursery.jpg" />
            <Format>image/jpeg</Format>
          </ExternalGraphic>
          <Size>32</Size>
        </Graphic>
      </PointSymbolizer>
    </Rule>
     <Rule>
   <Name>Petting Zoo</Name>
    <Title>All Petting Zoos</Title>
      <ogc:Filter>
        <ogc:PropertyIsLike wildCard="*" singleChar="." escape="!">
           <ogc:PropertyName>type</ogc:PropertyName>
           <ogc:Literal>Petting Zoo</ogc:Literal>
         </ogc:PropertyIsLike>
       </ogc:Filter>
      <PointSymbolizer>
        <Graphic>
          <ExternalGraphic>
            <OnlineResource
              xlink:type="simple"
              xlink:href="Petting Zoo.jpg" />
            <Format>image/jpeg</Format>
          </ExternalGraphic>
          <Size>32</Size>
        </Graphic>
      </PointSymbolizer>
    </Rule>
  </FeatureTypeStyle>
</UserStyle>

【问题讨论】:

【参考方案1】:

我知道这篇文章很旧,但也许有人会从我的回答中受益。

我没有成功使用相对图像路径,所以我转而使用 URL 路径。

将图像放入 $GEOSERVER_DATA_DIR/styles 并使用 http://localhost:8081/geoserver/styles/some_image.png 引用它

例如

<ExternalGraphic>
  <OnlineResource xlink:type="simple" xlink:href="http://localhost:8081/geoserver/styles/some_image.png"/>
  <Format>image/png</Format>
</ExternalGraphic>

【讨论】:

非常感谢。我无法以任何其他方式访问图像。【参考方案2】:

不错的答案,但假设地理服务器实例在端口 8080 上工作,您需要将 8081 更改为 8080

【讨论】:

【参考方案3】:

你可以把你的图片放在 style 文件夹中

【讨论】:

以上是关于外部图形和属性规则的 Geoserver SLD 样式问题的主要内容,如果未能解决你的问题,请参考以下文章

通过SLD_BODY动态改变geoserver的图层样式

GeoServer中使用样式化图层描述符(sld)加注记

GeoServer中sld文件的获取来源

Geoserver Sld 无法正常工作

Geoserver 上的动态 SLD

利用 uDig 生成 GeoServer 可用的 SLD 渲染文件