TransWikia.com

Geoserver WMS only works in JPEG format not PNG

Geographic Information Systems Asked on December 6, 2020

I have around 5,000 Geotiffs that cannot be viewed as image/png in Geoserver 2.17 but work fine if I specify the format parameter as image/jpeg.

For example this URL works:
http://serverName/geoserver/workspaceName/wms?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&FORMAT=image/jpeg&TRANSPARENT=true&LAYERS=layerName&exceptions=application%2Fvnd.ogc.se_inimage&WIDTH=464&HEIGHT=768&BBOX=19.6875%2C-41.66015625%2C60.46875%2C25.83984375

But this URL does not:
http://serverName/geoserver/workspaceName/wms?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&FORMAT=image/png&TRANSPARENT=true&LAYERS=layerName&exceptions=application%2Fvnd.ogc.se_inimage&WIDTH=464&HEIGHT=768&BBOX=19.6875%2C-41.66015625%2C60.46875%2C25.83984375

(The only differences in the above URL are the requested format) The failing URL produces the following error in the geoserver.log file:

ERROR [geoserver.ows] -
org.geoserver.platform.ServiceException: Failed to encode the PNG
       at org.geoserver.wms.map.png.PNGJWriter.writePNG(PNGJWriter.java:49)
<stack trace snipped>
Caused by: java.lang.IllegalArgumentException: Could not find a scanline extractor for PlanarImage[minX=0 minY=0 width=464 height=768 tileGridXOffset=0 tileGridYOffset=0 tileWidth=464 tileHeight=768 sampleModel=java.awt.image.PixelInterleavedSampleModel@5081004 colorModel=ColorModel: #pixelBits = 40 numComponents = 5 color space = com.sun.media.imageioimpl.common.BogusColorSpace@63d52a5a transparency = 1 has alpha = false isAlphaPre = false]

I have also run a few of the source Geotiffs through gdalinfo and noticed that they have four "bands" listed in the metadata not three. I did not create these Geotiffs so although I know they were created with ESRI software I do not know if the colours are RGB, CMYK or other.

Here is the output from gdalinfo:

Driver: GTiff/GeoTIFF
Warning 1: TIFFReadDirectory:Sum of Photometric type-related color channels and ExtraSamples doesn't match SamplesPerPixel. Defining non-color channels as ExtraSamples.
Warning 1: TIFFReadDirectory:Sum of Photometric type-related color channels and ExtraSamples doesn't match SamplesPerPixel. Defining non-color channels as ExtraSamples.
Warning 1: TIFFReadDirectory:Sum of Photometric type-related color channels and ExtraSamples doesn't match SamplesPerPixel. Defining non-color channels as ExtraSamples.
Warning 1: TIFFReadDirectory:Sum of Photometric type-related color channels and ExtraSamples doesn't match SamplesPerPixel. Defining non-color channels as ExtraSamples.
Files: [FilenameRedacted].tif
       [FilenameRedacted].tif.ovr
       [FilenameRedacted].tif.aux.xml
Size is 1073, 1776
Coordinate System is:
GEOGCRS["WGS 84",
    DATUM["World Geodetic System 1984",
        ELLIPSOID["WGS 84",6378137,298.257223563,
            LENGTHUNIT["metre",1]]],
    PRIMEM["Greenwich",0,
        ANGLEUNIT["degree",0.0174532925199433]],
    CS[ellipsoidal,2],
        AXIS["geodetic latitude (Lat)",north,
            ORDER[1],
            ANGLEUNIT["degree",0.0174532925199433]],
        AXIS["geodetic longitude (Lon)",east,
            ORDER[2],
            ANGLEUNIT["degree",0.0174532925199433]],
    ID["EPSG",4326]]
Data axis to CRS axis mapping: 2,1
Origin = (26.484318298149674,14.558273233474697)
Pixel Size = (0.025335934027968,-0.025335934027968)
Metadata:
  AREA_OR_POINT=Area
  DataType=Generic
Image Structure Metadata:
  COMPRESSION=LZW
  INTERLEAVE=PIXEL
Corner Coordinates:
Upper Left  (  26.4843183,  14.5582732) ( 26d29' 3.55"E, 14d33'29.78"N)
Lower Left  (  26.4843183, -30.4383456) ( 26d29' 3.55"E, 30d26'18.04"S)
Upper Right (  53.6697755,  14.5582732) ( 53d40'11.19"E, 14d33'29.78"N)
Lower Right (  53.6697755, -30.4383456) ( 53d40'11.19"E, 30d26'18.04"S)
Center      (  40.0770469,  -7.9400362) ( 40d 4'37.37"E,  7d56'24.13"S)
Band 1 Block=128x128 Type=Byte, ColorInterp=Red
  Min=0.000 Max=255.000
  Minimum=0.000, Maximum=255.000, Mean=245.168, StdDev=34.603
  NoData Value=9
  Overviews: 537x888, 269x444, 135x222
  Metadata:
    SourceBandIndex=0
    STATISTICS_COVARIANCES=1197.395437532503,1168.303096515968,1060.836601071883,0
    STATISTICS_MAXIMUM=255
    STATISTICS_MEAN=245.16798453699
    STATISTICS_MINIMUM=0
    STATISTICS_SKIPFACTORX=1
    STATISTICS_SKIPFACTORY=1
    STATISTICS_STDDEV=34.603402109222
Band 2 Block=128x128 Type=Byte, ColorInterp=Green
  Min=0.000 Max=255.000
  Minimum=0.000, Maximum=255.000, Mean=245.801, StdDev=34.041
  NoData Value=9
  Overviews: 537x888, 269x444, 135x222
  Metadata:
    SourceBandIndex=1
    STATISTICS_COVARIANCES=1168.303096515968,1158.780089641089,1048.169976810254,0
    STATISTICS_MAXIMUM=255
    STATISTICS_MEAN=245.80137046658
    STATISTICS_MINIMUM=0
    STATISTICS_SKIPFACTORX=1
    STATISTICS_SKIPFACTORY=1
    STATISTICS_STDDEV=34.040859120197
Band 3 Block=128x128 Type=Byte, ColorInterp=Blue
  Min=0.000 Max=255.000
  Minimum=0.000, Maximum=255.000, Mean=246.754, StdDev=31.208
  NoData Value=9
  Overviews: 537x888, 269x444, 135x222
  Metadata:
    SourceBandIndex=2
    STATISTICS_COVARIANCES=1060.836601071883,1048.169976810254,973.9317344822535,0
    STATISTICS_MAXIMUM=255
    STATISTICS_MEAN=246.75405294156
    STATISTICS_MINIMUM=0
    STATISTICS_SKIPFACTORX=1
    STATISTICS_SKIPFACTORY=1
    STATISTICS_STDDEV=31.20787936535
Band 4 Block=128x128 Type=Byte, ColorInterp=Undefined
  Min=255.000 Max=255.000
  Minimum=255.000, Maximum=255.000, Mean=255.000, StdDev=0.000
  NoData Value=9
  Overviews: 537x888, 269x444, 135x222
  Metadata:
    SourceBandIndex=3
    STATISTICS_COVARIANCES=0,0,0,0
    STATISTICS_MAXIMUM=255
    STATISTICS_MEAN=255
    STATISTICS_MINIMUM=255
    STATISTICS_SKIPFACTORX=1
    STATISTICS_SKIPFACTORY=1
    STATISTICS_STDDEV=0

In my OpenLayers based application I can ensure the WMS URL specifies the format as JPEG, but end-users using QGIS, Arcmap or ArcPro cannot be expected to know that one of the formats doesn’t work.

Is there any way I can make the image/png format work?


Edit: As per suggestion, tried changing the PNG encoder on the "Image Processing" page from the default "PNGJ based encoder" to "Java own encoder". The java stack trace in the geoserver.log has now changed to:

ERROR [geoserver.ows] -
java.lang.IllegalStateException: No suitable image writer for this output.
        at org.geotools.image.ImageWorker.writePNG(ImageWorker.java:3734)
        at org.geoserver.wms.map.PNGMapResponse.formatImageOutputStream(PNGMapResponse.java:110)
        at org.geoserver.wms.map.RenderedImageMapResponse.write(RenderedImageMapResponse.java:110)

One Answer

Turns out my guess about 4 byte CMYK colours in the Geotiff was correct. I asked the department I sourced the data from to re-run the export but with RGB colours and they all work now when requested in either format (PNG or JPEG tiles) from Geoserver.

Answered by Ralph on December 6, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP