8

I have a raster published in my geoserver with default raster style as below

<NamedLayer>
<Name>default_raster</Name>
<UserStyle>
<!-- Styles can have names, titles and abstracts -->
  <Title>Default Raster</Title>
  <Abstract>A sample style that draws a raster, good for displaying imagery</Abstract>
  <!-- FeatureTypeStyles describe how to render different features -->
  <!-- A FeatureTypeStyle for rendering rasters -->
  <FeatureTypeStyle>
    <Rule>
      <Name>rule1</Name>
      <Title>Opaque Raster</Title>
      <Abstract>A raster with 100% opacity</Abstract>
      <RasterSymbolizer>
        <Opacity>1.0</Opacity>
      </RasterSymbolizer>
    </Rule>
  </FeatureTypeStyle>
</UserStyle>

And my imagery looks like enter image description here

Which has black color set for no data. I want to make the no data to transparent. How that can be done?

1

2 Answers 2

3

I'm not sure if this question is still relevant to anyone, but I found a solution using YSLD. Check out the documentation on the raster symbolizer and note the "intervals" color ramp. You can simply set the interval containing the no-data value to transparent. For example, if your no-data value is something north of 36000:

title: Discrete Ramp'
feature-styles:
- name: raster
  rules:
  - name: raster
  - symbolizers:
    - raster:
        opacity: 1.0
        color-map:
          type: intervals
          entries:
          - ['#000000',0, 36000,'']

The format here is [<color>,<transparency>,<cell value>,<symbol>]. You can, of course, add more entries to symbolize other ranges of values. I hope this helps, even though it's a few years too late. :)

1
  • That's also something you could do with SLD ColorMap elements: you define a ColorMapEntry with the opacity attribute set to 0. I used this "trick" for my maps to set transparency!
    – Campa
    Commented Nov 5, 2021 at 10:50
2

I don't think it can be done with SLD. Publish your imagery as a image mosaic and change the "input transparent color" to black instead.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.