Python SubsetOp invalid region

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

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)

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.

Okay, I should have remember earlier.
This is a known issue.

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