1

I am using gdal_translate.exe to get a PNG file from a WMS server. Depending on the image size the resulting PNG files shows some sort of fragmentation. The type of fragmentation varies depending on the size and aspect. It seems to happen more with flatter images than square ones but I can't get a consistent handle on the issue.

This happens with the GDAL precompiled binaries from 1.8.0 and also my own local build at 2.1.2 and also the OSGeo4W binaries. There are no problems getting the correct PNG file using a browser, CURL.EXE or QGIS.

So I suspect that something is wrong in GDAL.

Note that -outsize must be set to match the WIDTH and HEIGHT parameters.

THIS IS THE TORN IMAGE (attached)

gdal_translate -outsize 1025 604 -of png "WMS:http://maps.six.nsw.gov.au/arcgis/services/public/NSW_Imagery/MapServer/WMSServer?SERVICE=WMS&REQUEST=GetMap&VERSION=1.3.0&CRS=EPSG:4326&FORMAT=image/png&STYLES=default&LAYERS=BestImageryDates&WIDTH=1025&HEIGHT=604&BBOX=-38.35116600,139.23662900,-26.60347900,159.17524268" "c:\temp\gda_212A.png"

THIS GIVES THE CORRECT IMAGE BUT SMALLER

Hmm - as I don't have enough credits to add more than 2 links I cannot add both the sample image and the second query that returns the good smaller image. So instead I added the image plus instructions on how to get the smaller image.

Replace the following parts of the query as follows...

-outsize 1025 604 >EDIT> -outsize 512 302

&WIDTH=1025&HEIGHT=604 >EDIT> &WIDTH=512&HEIGHT=302

"c:\temp\gda_212A.png" >EDIT> "c:\temp\gda_212B.png"

Does anyone know what the cause is?

Further testing results just now... I changed the output format and request to BMP and TIFF and the result is the same, the image is torn.

PART SOLUTION

I have found what appears to be problem in the GDAL code, but am not sure if it really is. For my two cents worth whilst debugging I found the following problems that seem to be 1.3.0 related:

In function GDALWMSRasterBand::ReadBlocks()

The URL for the block comes from AskMiniDriverForBlock(&url, ix, iy);

The returned block data is based on swapped values for

m_data_window.m_x0

m_data_window.m_y0

m_data_window.m_x1

m_data_window.m_y1

I found that the WMS fetches data in blocks m_default_block_size_x and m_default_block_size_y which are 1024. This triggers the block read and messed up blocks.

I think this could be fixed in the code but can be worked around by using a service description to get the data instead.

Here is something that works now...

gdal_translate -outsize 1161 689 -of png "<GDAL_WMS><Service name=""WMS""><Version>1.3.0</Version><ServerUrl>http://maps.six.nsw.gov.au/arcgis/services/public/NSW_Imagery/MapServer/WMSServer?</ServerUrl><CRS>EPSG:4326</CRS><ImageFormat>image/png</ImageFormat><Transparent>FALSE</Transparent><Layers>BestImageryDates</Layers><Styles>default</Styles><BBoxOrder>yxYX</BBoxOrder></Service><DataWindow><UpperLeftX>139.23662900</UpperLeftX><UpperLeftY>-38.35116600</UpperLeftY><LowerRightX>159.04270529</LowerRightX><LowerRightY>-26.60347900</LowerRightY><SizeX>1161</SizeX><SizeY>689</SizeY></DataWindow><Projection>EPSG:4326</Projection><BandsCount>3</BandsCount><BlockSizeX>1161</BlockSizeX><BlockSizeY>689</BlockSizeY></GDAL_WMS>" "c:\temp\gdal_212_SD1.png"

Justin

Image A Torn Image

closed as off-topic by PolyGeo Feb 20 '17 at 3:21

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This problem cannot or can no longer be reproduced. Changes to the system or to the asker's circumstances may have rendered the question obsolete, or the question does not include a procedure to enable potential answerers to reproduce the same symptoms. Such questions are off-topic as they are unlikely to help future readers, but editing them to include more details can lead to re-opening." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Is the image missing "THIS IS THE TORN IMAGE (attached)" – user30184 Nov 27 '16 at 17:32
  • You will get more information about the requests that GDAL really sends to the server by adding --debug on into your gdal_translate command. But it seems that you have found the correct solution by adding a hint about the BBOX axis order. – user30184 Nov 28 '16 at 8:20