How to create very small subsets of a Sentinel-2 product

Hi, I’m very new to snappy and SNAP in general
I have been attempting to subset small regions from Sentinel-2 products (crop fields). I have come into the following error when using snappy and I suspect the issue is the co-ordinates are rounded up to fewer decimal places making them identical and therefore making the height and width of the polygon equal to zero.
Having a look at subsets in the SNAP toolbox I see that geo co-ordinates are only taken up to 3 decimal places.

Below is my source code

product = ProductIO.readProduct(r'Path to product')
SubsetOp = snappy.jpy.get_type('org.esa.snap.core.gpf.common.SubsetOp')

wkt = str(df.iloc[0,-1])
geom = WKTReader().read(wkt)

op = SubsetOp()
op.setSourceProduct(product)
op.setGeoRegion(geom)
op.setCopyMetadata(True)

subset = op.getTargetProduct()

ProductIO.writeProduct(subset, "test_subset.dim", "BEAM-DIMAP")

The dataframe cell ‘df.iloc[0,-1]’ returns the following:

POLYGON ((0.5989372730255127 51.106129010265214, 0.6025421619415282 51.106129010265214, 0.6025421619415282 51.10731460488895, 0.5989372730255127 51.10731460488895, 0.5989372730255127 51.106129010265214))

This results in the following error:

---> 12 subset = op.getTargetProduct()

RuntimeError: org.esa.snap.core.gpf.OperatorException: The pixel region 'java.awt.Rectangle[x=10,y=6,width=0,height=0]' is invalid.

Is there any way for me to crop such a small chunk from a Sentinel-2 product?

Thanks for the report.
I don’t think it is caused by rounding issues. At the first glance it seems that on of methods we use does not work as expected. It shall return the bounding box of the geometry, but if the geometry lies within a pixel, then it seems to return 0 instead of 1.

Are you using SNAP 8?
Could you provide the name of the product you have used? Then we can try reproduce and investigate this further.

I’ve put this into the issue tracker:
[SNAP-1419] Subset fails for very small areas - JIRA (atlassian.net)

Thank you for the reply,

I am using SNAP 8, the product I tried this on is “S2B_MSIL1C_20210324T105639_N0209_R094_T30UYB_20210324T134452”

Hi,

I was able to reproduce it with SNAP 8.
The good news is that it is already fixed in the current development branch for SNAP 9.

I’m not sure if this can be ported to 8.x soon. Maybe you need to wait for SNAP 9. Which should be release in the first half of this year.