jsa
August 10, 2020, 11:26am
#1
Hi,
I’m trying to subset a region from a Sentinel-2 product. No matter what I do, I get an invalid region OperatorException. This is what I do:
from snappy import ProductIO, Product, jpy, GPF
wkt = 'POLYGON ((-111.6030365276919 41.18425473986428, -111.5721789952915 41.18441217527622, -111.5720268696366 41.166928196138855, -111.60287619910223 41.1667708570042, -111.6030365276919 41.18425473986428))'
product = ProductIO.readProduct(S2B_MSIL2A_20200227T181309_N0214_R084_T12TVL_20200227T205338.SAFE/MTD_MSIL2A.xml)
SubsetOp = jpy.get_type('org.esa.snap.core.gpf.common.SubsetOp')
WKTReader = jpy.get_type('com.vividsolutions.jts.io.WKTReader')
op = SubsetOp()
op.setSourceProduct(product)
geometry = WKTReader().read(wkt)
op.setGeoRegion(geometry)
sub_product = op.getTargetProduct()
I always get RuntimeError: org.esa.snap.core.gpf.OperatorException: invalid region on getTargetProduct.
I picked the region myself using the GUI (rectangle tool, then wkt from geometry.
Thanks
marpet
August 10, 2020, 11:58am
#2
Is it still not working with the updated coordinates? The coordinates should be on WGS84. Before you had UTM coordinates.
You could also try to invoke the Subset operator differently:
parameters = HashMap()
parameters.put(‘copyMetadata’, True)
parameters.put(‘geoRegion’, 'POLYGON ((-111.6030365276919 41.18425473986428, -111.5721789952915 41.18441217527622, -111.5720268696366 41.166928196138855, -111.60287619910223 41.1667708570042, -111.6030365276919 41.18425473986428))')
sub_product = GPF.createProduct(“Subset”, parameters, product)
jsa
August 10, 2020, 12:11pm
#3
It doesn’t work with the updated coordinates either. Your code snippet produces the same output: invalid region. However, it is just a tiny fraction of the product area.
marpet
August 10, 2020, 12:23pm
#4
Okay, I should have remember earlier.
This is a known issue.
Hi,
The happens due to the multi-resolution characteristics of Sentinel-2.
This bug is known since a while but not fixed yet.
You can work around this issue by first resampling the product to a common resolution and do the subsetting afterwards.
jsa
August 10, 2020, 12:42pm
#5
It works now! Thank you for your help
Just it case it helps anyone in the future. This snippet makes the above code work:
HashMap = jpy.get_type('java.util.HashMap')
parameters = HashMap()
parameters.put('targetResolution', '10')
product = GPF.createProduct('Resample', parameters, product)
1 Like