<?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">
  
  <NamedLayer>
    <Name>sea_ice_drift_rotated_scaled</Name>
    <UserStyle>
      <Title>Sea Ice Drift - Rotated Arrows Scaled by Velocity</Title>
      
      <!-- =============================== -->
      <!-- Main Arrow Style -->
      <!-- =============================== -->
      <FeatureTypeStyle>
        <Rule>
          <Name>Ice Drift Arrows</Name>
          
          <!-- Arrow symbol with dynamic sizing and rotation -->
          <PointSymbolizer>
            <Graphic>
              <Mark>
                <WellKnownName>triangle</WellKnownName>
                <Stroke>
                  <CssParameter name="stroke">#0D47A1</CssParameter>
                  <CssParameter name="stroke-width">1</CssParameter>
                </Stroke>
              </Mark>
              
              <!-- Size scaled by velocity: Larger arrows for faster drift -->
              <Size>
                <ogc:Function name="Min">
                  <!-- Base size + (velocity * scaling factor) -->
                  <ogc:Add>
                    <ogc:Literal>8</ogc:Literal>    <!-- Minimum size -->
                    <ogc:Mul>
                      <ogc:PropertyName>drift_km</ogc:PropertyName>
                      <ogc:Literal>0.6</ogc:Literal>   <!-- Scaling factor -->
                    </ogc:Mul>
                  </ogc:Add>
                  <ogc:Literal>30</ogc:Literal>    <!-- Maximum size -->
                </ogc:Function>
              </Size>
              
              <!-- Rotation based on direction (0° = North) -->
              <Rotation>
                <ogc:PropertyName>direction</ogc:PropertyName>
              </Rotation>
            </Graphic>
          </PointSymbolizer>
        </Rule>
      </FeatureTypeStyle>
      
      <!-- =============================== -->
      <!-- Alternative: Detailed Arrow with Shaft -->
      <!-- =============================== -->
      <FeatureTypeStyle>
        <Rule>
          <Name>Detailed Arrows</Name>
          <MaxScaleDenominator>5000000</MaxScaleDenominator> <!-- Only at larger scales -->
          
          <!-- Arrow shaft (line) -->
          <PointSymbolizer>
            <Graphic>
              <Mark>
                <WellKnownName>shape://vertline</WellKnownName>
                <Stroke>
                  <CssParameter name="stroke">
                    <ogc:Function name="Interpolate">
                      <ogc:PropertyName>velocity</ogc:PropertyName>
                      <ogc:Literal>color</ogc:Literal>
                      <ogc:Literal>0</ogc:Literal>
                      <ogc:Literal>#2196F3</ogc:Literal>
                      <ogc:Literal>50</ogc:Literal>
                      <ogc:Literal>#FF9800</ogc:Literal>
                      <ogc:Literal>100</ogc:Literal>
                      <ogc:Literal>#F44336</ogc:Literal>
                    </ogc:Function>
                  </CssParameter>
                  <CssParameter name="stroke-width">
                    <ogc:Add>
                      <ogc:Literal>1</ogc:Literal>
                      <ogc:Mul>
                        <ogc:PropertyName>velocity</ogc:PropertyName>
                        <ogc:Literal>0.05</ogc:Literal>
                      </ogc:Mul>
                    </ogc:Add>
                  </CssParameter>
                  <CssParameter name="stroke-linecap">round</CssParameter>
                </Stroke>
              </Mark>
              <!-- Shaft length proportional to velocity -->
              <Size>
                <ogc:Add>
                  <ogc:Literal>15</ogc:Literal>
                  <ogc:Mul>
                    <ogc:PropertyName>velocity</ogc:PropertyName>
                    <ogc:Literal>0.8</ogc:Literal>
                  </ogc:Mul>
                </ogc:Add>
              </Size>
              <Rotation>
                <ogc:PropertyName>direction</ogc:PropertyName>
              </Rotation>
            </Graphic>
          </PointSymbolizer>
          
          <!-- Arrowhead -->
          <PointSymbolizer>
            <Graphic>
              <Mark>
                <WellKnownName>triangle</WellKnownName>
                <Fill>
                  <ogc:Function name="Interpolate">
                    <ogc:PropertyName>velocity</ogc:PropertyName>
                    <ogc:Literal>color</ogc:Literal>
                    <ogc:Literal>0</ogc:Literal>
                    <ogc:Literal>#0D47A1</ogc:Literal>
                    <ogc:Literal>50</ogc:Literal>
                    <ogc:Literal>#FF6F00</ogc:Literal>
                    <ogc:Literal>100</ogc:Literal>
                    <ogc:Literal>#B71C1C</ogc:Literal>
                  </ogc:Function>
                </Fill>
                <Stroke>
                  <CssParameter name="stroke">#000000</CssParameter>
                  <CssParameter name="stroke-width">0.5</CssParameter>
                </Stroke>
              </Mark>
              <!-- Arrowhead size -->
              <Size>
                <ogc:Add>
                  <ogc:Literal>8</ogc:Literal>
                  <ogc:Mul>
                    <ogc:PropertyName>velocity</ogc:PropertyName>
                    <ogc:Literal>0.3</ogc:Literal>
                  </ogc:Mul>
                </ogc:Add>
              </Size>
              <Rotation>
                <ogc:PropertyName>direction</ogc:PropertyName>
              </Rotation>
              <!-- Position arrowhead at end of shaft -->
              <Displacement>
                <DisplacementX>
                  <ogc:Div>
                    <ogc:Add>
                      <ogc:Literal>15</ogc:Literal>
                      <ogc:Mul>
                        <ogc:PropertyName>velocity</ogc:PropertyName>
                        <ogc:Literal>0.8</ogc:Literal>
                      </ogc:Mul>
                    </ogc:Add>
                    <ogc:Literal>2</ogc:Literal>
                  </ogc:Div>
                </DisplacementX>
                <DisplacementY>0</DisplacementY>
              </Displacement>
            </Graphic>
          </PointSymbolizer>
        </Rule>
      </FeatureTypeStyle>
      
      <!-- =============================== -->
      <!-- Velocity-based Symbol Variations -->
      <!-- =============================== -->
      <FeatureTypeStyle>
        <!-- Very Slow Drift (0-5 cm/s) -->
        <Rule>
          <Name>Very Slow Ice (0-5 cm/s)</Name>
          <ogc:Filter>
            <ogc:And>
              <ogc:PropertyIsGreaterThanOrEqualTo>
                <ogc:PropertyName>velocity</ogc:PropertyName>
                <ogc:Literal>0</ogc:Literal>
              </ogc:PropertyIsGreaterThanOrEqualTo>
              <ogc:PropertyIsLessThan>
                <ogc:PropertyName>velocity</ogc:PropertyName>
                <ogc:Literal>5</ogc:Literal>
              </ogc:PropertyIsLessThan>
            </ogc:And>
          </ogc:Filter>
          
          <PointSymbolizer>
            <Graphic>
              <Mark>
                <WellKnownName>circle</WellKnownName>
                <Fill>
                  <CssParameter name="fill">#BBDEFB</CssParameter>
                </Fill>
                <Stroke>
                  <CssParameter name="stroke">#64B5F6</CssParameter>
                  <CssParameter name="stroke-width">1</CssParameter>
                </Stroke>
              </Mark>
              <Size>
                <ogc:Add>
                  <ogc:Literal>5</ogc:Literal>
                  <ogc:Mul>
                    <ogc:PropertyName>velocity</ogc:PropertyName>
                    <ogc:Literal>0.5</ogc:Literal>
                  </ogc:Mul>
                </ogc:Add>
              </Size>
              <Rotation>
                <ogc:PropertyName>direction</ogc:PropertyName>
              </Rotation>
            </Graphic>
          </PointSymbolizer>
        </Rule>
        
        <!-- Slow Drift (5-15 cm/s) -->
        <Rule>
          <Name>Slow Ice (5-15 cm/s)</Name>
          <ogc:Filter>
            <ogc:And>
              <ogc:PropertyIsGreaterThanOrEqualTo>
                <ogc:PropertyName>velocity</ogc:PropertyName>
                <ogc:Literal>5</ogc:Literal>
              </ogc:PropertyIsGreaterThanOrEqualTo>
              <ogc:PropertyIsLessThan>
                <ogc:PropertyName>velocity</ogc:PropertyName>
                <ogc:Literal>15</ogc:Literal>
              </ogc:PropertyIsLessThan>
            </ogc:And>
          </ogc:Filter>
          
          <PointSymbolizer>
            <Graphic>
              <Mark>
                <WellKnownName>triangle</WellKnownName>
                <Fill>
                  <CssParameter name="fill">#64B5F6</CssParameter>
                </Fill>
                <Stroke>
                  <CssParameter name="stroke">#1976D2</CssParameter>
                  <CssParameter name="stroke-width">1</CssParameter>
                </Stroke>
              </Mark>
              <Size>
                <ogc:Add>
                  <ogc:Literal>8</ogc:Literal>
                  <ogc:Mul>
                    <ogc:PropertyName>velocity</ogc:PropertyName>
                    <ogc:Literal>0.7</ogc:Literal>
                  </ogc:Mul>
                </ogc:Add>
              </Size>
              <Rotation>
                <ogc:PropertyName>direction</ogc:PropertyName>
              </Rotation>
            </Graphic>
          </PointSymbolizer>
        </Rule>
        
        <!-- Medium Drift (15-30 cm/s) -->
        <Rule>
          <Name>Medium Ice (15-30 cm/s)</Name>
          <ogc:Filter>
            <ogc:And>
              <ogc:PropertyIsGreaterThanOrEqualTo>
                <ogc:PropertyName>velocity</ogc:PropertyName>
                <ogc:Literal>15</ogc:Literal>
              </ogc:PropertyIsGreaterThanOrEqualTo>
              <ogc:PropertyIsLessThan>
                <ogc:PropertyName>velocity</ogc:PropertyName>
                <ogc:Literal>30</ogc:Literal>
              </ogc:PropertyIsLessThan>
            </ogc:And>
          </ogc:Filter>
          
          <PointSymbolizer>
            <Graphic>
              <Mark>
                <WellKnownName>shape://oarrow</WellKnownName>
                <Fill>
                  <CssParameter name="fill">#4DB6AC</CssParameter>
                </Fill>
                <Stroke>
                  <CssParameter name="stroke">#00796B</CssParameter>
                  <CssParameter name="stroke-width">1.2</CssParameter>
                </Stroke>
              </Mark>
              <Size>
                <ogc:Add>
                  <ogc:Literal>12</ogc:Literal>
                  <ogc:Mul>
                    <ogc:PropertyName>velocity</ogc:PropertyName>
                    <ogc:Literal>0.6</ogc:Literal>
                  </ogc:Mul>
                </ogc:Add>
              </Size>
              <Rotation>
                <ogc:PropertyName>direction</ogc:PropertyName>
              </Rotation>
            </Graphic>
          </PointSymbolizer>
        </Rule>
        
        <!-- Fast Drift (30-50 cm/s) -->
        <Rule>
          <Name>Fast Ice (30-50 cm/s)</Name>
          <ogc:Filter>
            <ogc:And>
              <ogc:PropertyIsGreaterThanOrEqualTo>
                <ogc:PropertyName>velocity</ogc:PropertyName>
                <ogc:Literal>30</ogc:Literal>
              </ogc:PropertyIsGreaterThanOrEqualTo>
              <ogc:PropertyIsLessThan>
                <ogc:PropertyName>velocity</ogc:PropertyName>
                <ogc:Literal>50</ogc:Literal>
              </ogc:PropertyIsLessThan>
            </ogc:And>
          </ogc:Filter>
          
          <PointSymbolizer>
            <Graphic>
              <Mark>
                <WellKnownName>shape://oarrow</WellKnownName>
                <Fill>
                  <CssParameter name="fill">#FFB74D</CssParameter>
                </Fill>
                <Stroke>
                  <CssParameter name="stroke">#FF9800</CssParameter>
                  <CssParameter name="stroke-width">1.5</CssParameter>
                </Stroke>
              </Mark>
              <Size>
                <ogc:Add>
                  <ogc:Literal>15</ogc:Literal>
                  <ogc:Mul>
                    <ogc:PropertyName>velocity</ogc:PropertyName>
                    <ogc:Literal>0.7</ogc:Literal>
                  </ogc:Mul>
                </ogc:Add>
              </Size>
              <Rotation>
                <ogc:PropertyName>direction</ogc:PropertyName>
              </Rotation>
            </Graphic>
          </PointSymbolizer>
        </Rule>
        
        <!-- Very Fast Drift (50+ cm/s) -->
        <Rule>
          <Name>Very Fast Ice (50+ cm/s)</Name>
          <ogc:Filter>
            <ogc:PropertyIsGreaterThanOrEqualTo>
              <ogc:PropertyName>velocity</ogc:PropertyName>
              <ogc:Literal>50</ogc:Literal>
            </ogc:PropertyIsGreaterThanOrEqualTo>
          </ogc:Filter>
          
          <PointSymbolizer>
            <Graphic>
              <Mark>
                <WellKnownName>shape://oarrow</WellKnownName>
                <Fill>
                  <CssParameter name="fill">#EF5350</CssParameter>
                </Fill>
                <Stroke>
                  <CssParameter name="stroke">#D32F2F</CssParameter>
                  <CssParameter name="stroke-width">2</CssParameter>
                </Stroke>
              </Mark>
              <Size>
                <ogc:Add>
                  <ogc:Literal>18</ogc:Literal>
                  <ogc:Mul>
                    <ogc:PropertyName>velocity</ogc:PropertyName>
                    <ogc:Literal>0.8</ogc:Literal>
                  </ogc:Mul>
                </ogc:Add>
              </Size>
              <Rotation>
                <ogc:PropertyName>direction</ogc:PropertyName>
              </Rotation>
            </Graphic>
          </PointSymbolizer>
        </Rule>
      </FeatureTypeStyle>
      
      <!-- =============================== -->
      <!-- Optional: Velocity Labels -->
      <!-- =============================== -->
      <FeatureTypeStyle>
        <Rule>
          <Name>Velocity Labels</Name>
          <MaxScaleDenominator>2000000</MaxScaleDenominator> <!-- Only show at close zoom -->
          
          <TextSymbolizer>
            <Label>
              <ogc:Function name="numberFormat">
                <ogc:Literal>##.#</ogc:Literal>
                <ogc:PropertyName>velocity</ogc:PropertyName>
              </ogc:Function>
            </Label>
            <Font>
              <CssParameter name="font-family">Arial</CssParameter>
              <CssParameter name="font-size">
                <ogc:Add>
                  <ogc:Literal>9</ogc:Literal>
                  <ogc:Mul>
                    <ogc:PropertyName>velocity</ogc:PropertyName>
                    <ogc:Literal>0.05</ogc:Literal>
                  </ogc:Mul>
                </ogc:Add>
              </CssParameter>
              <CssParameter name="font-weight">bold</CssParameter>
            </Font>
            <LabelPlacement>
              <PointPlacement>
                <Displacement>
                  <DisplacementX>0</DisplacementX>
                  <DisplacementY>
                    <ogc:Neg>
                      <ogc:Add>
                        <ogc:Literal>12</ogc:Literal>
                        <ogc:Mul>
                          <ogc:PropertyName>velocity</ogc:PropertyName>
                          <ogc:Literal>0.3</ogc:Literal>
                        </ogc:Mul>
                      </ogc:Add>
                    </ogc:Neg>
                  </DisplacementY>
                </Displacement>
              </PointPlacement>
            </LabelPlacement>
            <Fill>
              <CssParameter name="fill">#1A237E</CssParameter>
            </Fill>
            <Halo>
              <Radius>1.5</Radius>
              <Fill>
                <CssParameter name="fill">#FFFFFF</CssParameter>
              </Fill>
            </Halo>
          </TextSymbolizer>
        </Rule>
      </FeatureTypeStyle>
      
    </UserStyle>
  </NamedLayer>
</StyledLayerDescriptor>
