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

时间:2013-05-02 19:16:20

标签: image icons geoserver wms sld

我正在为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>

2 个答案:

答案 0 :(得分:7)

我发现这篇文章很老,但也许有人会从我的答案中受益。

我没有成功使用相对图像路径,所以我转向使用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>

答案 1 :(得分:0)

您可以将图像放在样式文件夹