QGIS + GEOSERVER 图层符号化(根据表数据自定义图层样式)
    		       		warning:
    		            这篇文章距离上次修改已过422天,其中的内容可能已经有所变动。
    		        
        		                
                
-- 假设我们有一个名为 "cities" 的表,包含城市名称和人口数据
-- 我们将使用这些数据来定制GeoServer中QGIS图层的样式
 
-- 创建一个新的样式模板
INSERT INTO geostore_style (name, type, data) VALUES (
  'custom_cities_style',  -- 样式名称
  'sld',  -- 类型
  '<StyledLayerDescriptor version="1.0.0" 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" xsi:schemaLocation="http://www.opengis.net/sld http://schemas.opengis.net/sld/1.0.0/StyledLayerDescriptor.xsd">
    <NamedLayer>
      <Name>Cities</Name>
      <UserStyle>
        <FeatureTypeStyle>
          <Rule>
            <Title>City</Title>
            <ogc:Filter>
              <ogc:PropertyIsGreaterThan>
                <ogc:PropertyName>population</ogc:PropertyName>
                <ogc:Literal>100000</ogc:Literal>
              </ogc:PropertyIsGreaterThan>
            </ogc:Filter>
            <PointSymbolizer>
              <Graphic>
                <Mark>
                  <WellKnownName>circle</WellKnownName>
                  <Fill>
                    <CssParameter name="fill">#FF0000</CssParameter>
                  </Fill>
                </Mark>
                <Size>${symbolScale} * 8</Size>
              </Graphic>
            </PointSymbolizer>
            <TextSymbolizer>
              <Label>
                <ogc:PropertyName>name</ogc:PropertyName>
              </Label>
              <Font>
                <CssParameter name="font-family">Arial</CssParameter>
                <CssParameter name="font-size">12</CssParameter>
              </Font>
              <LabelPlacement>
                <PointPlacement>
                  <AnchorPoint>
                    <AnchorPointX>0.5</AnchorPointX>
                    <AnchorPointY>0.5</AnchorPointY>
                  </AnchorPoint>
                </PointPlacement>
              </LabelPlacement>
              <Fill>
                <CssParameter name="fill">#000000</CssParameter>
              </Fill>
            </TextSymbolizer>
          </Rule>
        </FeatureTypeStyle>
      </UserStyle>
    </NamedLayer>
  </StyledLayerDescriptor>'
);
 
-- 将样式与图层关联
UPDATE geostore_data SET sld_id = (SELECT id FROM geostore_style WHERE name = 'custom_cities_style');这个例子展示了如何创建一个新的样式模板并将其与QGIS图
评论已关闭