Style Commands#

Manage GeoServer styles (SLD - Styled Layer Descriptor). Styles define how layers are rendered.

List Styles#

List all available styles.

1
./geoserver-cli style list

Output:

1
2
3
4
line
polygon
point
custom_style

Get Style#

Get style metadata (not the SLD content).

1
./geoserver-cli style get line

Create Style#

Create a new style and upload its SLD content.

From File#

1
./geoserver-cli style create my_style --sld @style.sld

From Stdin#

1
cat style.sld | ./geoserver-cli style create my_style --sld -

Inline SLD#

1
./geoserver-cli style create my_style --sld '<StyledLayerDescriptor version="1.0.0">...</StyledLayerDescriptor>'

Custom Filename#

1
./geoserver-cli style create my_style --sld @style.sld --filename custom_name.sld

Update Style#

Replace the SLD content of an existing style.

1
2
3
4
5
# From file
./geoserver-cli style update my_style --sld @updated_style.sld

# From stdin
cat updated_style.sld | ./geoserver-cli style update my_style --sld -

Delete Style#

Delete a style. Requires --yes flag.

1
./geoserver-cli style delete my_style --yes

!!! warning “Deletion Impact” Deleting a style may affect layers that use it. Ensure no layers depend on the style before deletion.

SLD Format#

Styles use the OGC SLD (Styled Layer Descriptor) XML format. Example:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?xml version="1.0" encoding="UTF-8"?>
<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">
  <NamedLayer>
    <Name>line_style</Name>
    <UserStyle>
      <Title>Line Style</Title>
      <FeatureTypeStyle>
        <Rule>
          <LineSymbolizer>
            <Stroke>
              <CssParameter name="stroke">#0000FF</CssParameter>
              <CssParameter name="stroke-width">2</CssParameter>
            </Stroke>
          </LineSymbolizer>
        </Rule>
      </FeatureTypeStyle>
    </UserStyle>
  </NamedLayer>
</StyledLayerDescriptor>

Examples#

Create and Apply Style#

1
2
3
4
5
# 1. Create style from SLD file
./geoserver-cli style create road_style --sld @road.sld

# 2. Apply to layer
./geoserver-cli layer update roads --default-style road_style

Update Style from Git#

1
2
3
4
5
# Pull latest style from repository
git pull

# Update style in GeoServer
./geoserver-cli style update road_style --sld @styles/road.sld

Batch Style Creation#

1
2
3
4
# Create multiple styles
for style in line polygon point; do
  ./geoserver-cli style create ${style} --sld @styles/${style}.sld
done

Style from Template#

1
2
3
4
5
# Generate SLD from template (example)
sed "s/COLOR/#FF0000/g" template.sld > red_style.sld

# Create style
./geoserver-cli style create red_polygon --sld @red_style.sld