I'm trying to retrieve pixel values in Sentinel-3 data for specific geographic coordinates using the SNAP-Engine. Until now, I transform the geographic coordinates to the corresponding X and Y with the following code using these links:
- https://stackoverflow.com/questions/51194477/converting-geographical-coordinates-long-lat-to-pixel-position-x-y-for-a-se
- https://senbox.atlassian.net/wiki/spaces/SNAP/pages/19300362/How+to+use+the+SNAP+API+from+Python)
import sys
sys.path.append('/path/to/.snap/snap-python')
from snappy import ProductIO
import numpy as np
from snappy import GeoPos
p = ProductIO.readProduct('/path/to/file.xml')
iwv = p.getBand('IWV')
g = p.getSceneGeoCoding()
def XY_from_LatLon(ProductSceneGeoCoding, latitude, longitude):
#From Latitude, Longitude satellite image, get the x, y position in image
pixelPos = ProductSceneGeoCoding.getPixelPos(GeoPos(latitude, longitude), None)
x = pixelPos.getX()
y = pixelPos.getY()
if str(x)=='nan':
raise ValueError('Latitude or Longitude out of this product')
else:
return x, y
How can I retrieve the data from a pixel using image coordinates (X, Y) in SNAP-Engine ?
After some more searching in SNAP-Engine docs, I found the method: getPixelFloat() that returns the pixel value given x, y. The code above was updated to the following :
import sys
sys.path.append('/path/to/.snap/snap-python')
from snappy import ProductIO
import numpy as np
from snappy import GeoPos
p = ProductIO.readProduct('/path/to/file.xml')
iwv = p.getBand('IWV')
g = p.getSceneGeoCoding()
def XY_from_LatLon(ProductSceneGeoCoding, latitude, longitude):
#From Latitude, Longitude satellite image, get the x, y position in image
pixelPos = ProductSceneGeoCoding.getPixelPos(GeoPos(latitude, longitude), None)
x = pixelPos.getX()
y = pixelPos.getY()
if str(x)=='nan':
raise ValueError('Latitude or Longitude out of this product')
else:
return x, y
x, y = XY_from_LatLon(sg, <lat>, <lon>)
print(iwv.getPixelFloat(x, y))
but it raises the following error:
Traceback (most recent call last):
File "snap.py", line 28, in <module>
print(iwv.getPixelInt(x, y))
RuntimeError: no matching Java method overloads found