I am evaluating the ArcGIS Maps SDK for Qt to see if it fits our needs. To test it, I have done a small project for a map and scene viewer. In both viewers, I import a GeoTIF (data/orofotomosaic.tif in the project) which is an RBGA image. However, the image is shown with with background instead of transparency (in the attached image there's also another GeoTIF displayed in green scale which is not relevant to this post):
The way I create that raster layer is:
Esri::ArcGISRuntime::Raster *raster = new
Esri::ArcGISRuntime::Raster("path/to/photomosaic.tif", parent);
Esri::ArcGISRuntime::RasterLayer *raster_layer = new Esri::ArcGISRuntime::RasterLayer(raster, parent);
How can I keep the transparent background of the imported TIF file?
https://community.esri.com/t5/qt-maps-sdk-questions/can-i-use-raster-function-mask-to-make-a-range-o...
I asked about something similar a while back, @JamesBallard1 is there any progress on this?
Hi @TroyFoster. No progress on "included ranges" I'm afraid.
I just stumpled upon this now as well. I thought one might be able to use a ColormapRenderer as illustrated here: Colormap renderer | ArcGIS Maps SDK for Qt | Esri Developer
However, using transparent colors does not seem to work. Funnily enough, when there are values that have no corresponding color they are rendered transparent! Is this a bug? Seems to me like it is...
In this example I defined 500 colors with the rules
< 250: Transparent. But it is rendered black!
< 300: Yellow.
< 400: Red.
> 400: Dark Red.
As you can see all values above 500 (i.e. more than the number of defined values), are rendered transparent!
Here is the code I used:
void ColormapTest::setup()
{
// [...]
Raster* raster = new Raster(filepath, this);
m_rasterLayer = new RasterLayer(raster, this);
ColormapRenderer* colormapRenderer = createColormapRenderer(m_rasterLayer);
m_rasterLayer->setRenderer(colormapRenderer);
m_map->operationalLayers()->append(m_rasterLayer);
}
ColormapRenderer*
ColormapTest::createColormapRenderer(QObject* parent)
{
QList<QColor> colors;
int maxValue = 500;
colors.reserve(maxValue);
for (int i = 0; i < maxValue; ++i) {
if (i < 250) {
colors.append(Qt::transparent);
} else if (i < 300) {
colors.append(Qt::yellow);
} else if (i < 400) {
colors.append(Qt::red);
} else {
colors.append(Qt::darkRed);
}
}
ColormapRenderer* colormapRenderer = new ColormapRenderer(colors, parent);
return colormapRenderer;
}
I don't understand how the ColormapRenderer is supposed to work ColormapRenderer Class | ArcGIS Maps SDK for Qt | Esri Developer
In the ctor one can only pass QList<QColor>. How can we define colors for negative values? Do we have to apply a raster function to normalize the values between 0 - 255 beforehand? If we rearrange the values so that everything above a certain value has no color defined, then we can render them fully transparent... Sadly no opacity is supported this way.
> But it is rendered black!
@imbachb I believe this is another symptom of the same problem with supporting raster transparency with certain formats. Someone else had reported a similar finding where transparency was rendered as solid back here: https://community.esri.com/t5/qt-maps-sdk-questions/geotiff-with-transparency-nodata/m-p/1262976#M48...
Hi @apalomer-iqua.
I can confirm that we don't support transparency with GeoTiff format. Possibly it's something we could support in the future, but it's not in our plans for the moment.
There are a few options. PNG should work with transparency, but I don't know if it's possible to switch formats of your raster data.
Another possibility is to use a raster mask function:
https://developers.arcgis.com/qt/layers/add-raster-data/#mask
A notable downside to this is the mask function would only allow you define a pixel as ON or OFF, it will not give you transparency, i.e. percentage of "opaqueness". In your case that may be ok.