Hi Helga,
actually the official intended way to get the lat/lon values is via the Geocoding.
from snappy import (GeoPos, PixelPos)
gc = sourceProduct.getSceneGeoCoding()
#or in multi-resolution case use the geo-coding of the raster
gc = sourceProduct.getRasterDataNode(“name”).getGeoCoding()
geoPos = gc.getGeoPos(PixelPos(x, y), None)
lat = geoPos.getLat()
lon = geoPos.getLon()
You would iterate over your pixel indices (x,y) and fill an array. But this can be tedious and actually you already found the solution. At least halfway. You can use setOwner(). This way the new band is owned by the source product but is not part of it.
virtLat = VirtualBand(“__lat”, ProductData.TYPE_FLOAT32, sourceProduct.getSceneRasterWidth(), sourceProduct.getSceneRasterHeight(), “LAT”)
virtLat.setOwner(sourceProduct)
virtLon = VirtualBand(“__lon”, ProductData.TYPE_FLOAT32, sourceProduct.getSceneRasterWidth(), sourceProduct.getSceneRasterHeight(), “LON”)
virtLat.setOwner(sourceProduct)