Wednesday, 12 December 2018

geoserver - Getting a constant background color for transparency


I am creating a series of tif files at 1:10k scale over a vast area (760 tiles) using arcpy.mapping.ExportToTIFF and then stitch them together to create a single ecw. The output looks ok but when I try to turn on transparency I find that the background "white" is not pure white (255,255,255) but values that "look white" like "254,254,252" or "254, 251, 250)


Is there anyway of setting a tolerance in the export so that any value between say 250 and 255) get re-described as 255,255,255? or any no-data areas get 255,255,255?


Alternatively would putting a background color (like green screening) that's not on the mxd work better than keeping the background undefined?


I am posting this and also researching the above options and others as they come to me as this is urgent.


EDIT 1 When I try jpg2000 I get better results but some white's are not correct. I am running the following command to create the tif


arcpy.mapping.ExportToTIFF(mxd,r"tests\SF\100k\SF100k_" + str(ddp.pageRow.PageName) + ".tif",df,9306,9306*ar,1800,True)


The issue is with the generated tif's as the "white" changes between tiles so when I stitch them in Global Mapper the "white" is different on each file. Would a raster calculator operation be able to clean this up? or can I fix it in the generation of the tif (ideally)? I need to run a similar process on 16 other map series at a few different scales so we are looking at over 10,000 individual tif tiles in 16 groups so the latter is preferred. enter image description here


EDIT 2:


PNG image enter image description here


Same area TIF image enter image description here


Any idea on why they look so different when it's exactly the same data? It's interesting that the symbology for the PNG is based on the data view while the TIF is based on the layout view. The PNG is much closer to the intended symbology.


Can Geoserver deal with Transparency in a different way to ArcGIS where the above issues then become irrelevant.


Thanks all,



Answer



This problem is two-part:




  • ECW is a lossy compressed format, meaning it cannot accurately represent individual pixels' original values but instead uses wavelet compression to approximate the colors of chunks of the image. Unfortunately this type of compression is not good at representing continuous areas of identical colors.

  • ECW version 3 does not support an alpha channel, which allows you to specify areas of transparency. ECW version 4 does support alpha channels, but ArcGIS's built-in ECW support is for the older version 3.


The two solutions I see are to either:



  • Switch to JPEG2000, which is similar to ECW but also supports lossless compression as well as alpha channels

  • Use another software package such as ERDAS to create the ECW with alpha channel, but use the ERDAS ECW plugin for ArcGIS to be able to correctly read the alpha channels in ArcGIS


See also: Remove Collar from ECW File (Orthophoto Mosaic)



Update:


While the TIFF format itself supports alpha channel transparency, neither the interactive nor the arcpy TIFF export functions support it.


However, you could use PNG instead (using arcpy.mapping.ExportToPNG(), which does support alpha channel transparency. Simply set the background color and the transparent color to the same value and you will get a PNG with alpha channel, which you should be able to then convert to JPEG2000 and (hopefully) retain the alpha channel.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...