Subset of Sentinel-1A images

import snappy

from snappy import ProductIO

from snappy import HashMap

import os,gc

from snappy import GPF

GPF.getDefaultInstance().getOperatorSpiRegistry().loadOperatorSpis()

HashMap = snappy.jpy.get_type('java.util.HashMap')

path = "D:\SENTINEL\"

gc.enable()

for folder in os.listdir(path): output = path + folder + "\"

timestamp = folder.split("_")[4]

date = timestamp[:8]

sentinel_1 = ProductIO.readProduct(output)

print sentinel_1

pols = ['VH','VV']

for p in pols:

polarization = p

wkt = 'POLYGON((17.06138 98.4766, 17.07500 98.55027, 17.10500 98.46833, 17.11833 98.54166))'

geom = WKTReader().read(wkt)

parameters = HashMap()

parameters.put('geoRegion', geom)

parameters.put('outputImageScaleInDb', False)

subset = output+date+"_subset_" + polarization

target_1 = GPF.createProduct("Subset", parameters, sentinel_1)

ProductIO.writeProduct(target_1, subset, 'BEAM-DIMAP')



I am getting an error:

 Traceback (most recent call last):

 File "D:/programs/subset.py", line 26, in

 target_1 = GPF.createProduct("Subset", parameters, sentinel_1)

 RuntimeError: ambiguous Java method call, too many matching method 
 overloads found

@ABraun @marpet

please use the search function. The same error message “too many matching method overloads found” was reported and solved here: Using mask file with KMeansClusterAnalysis in python

I think the problem is a bit different as in the mask thread.

import snappy
from snappy import ProductIO
from snappy import HashMap
import os, gc
from snappy import GPF

# Not necessary
# GPF.getDefaultInstance().getOperatorSpiRegistry().loadOperatorSpis()
# HashMap = snappy.jpy.get_type('java.util.HashMap')
WKTReader = snappy.jpy.get_type('com.vividsolutions.jts.io.WKTReader')

path = "D:\\SENTINEL\\"
gc.enable()

wkt = 'POLYGON((17.06138 98.4766, 17.07500 98.55027, 17.10500 98.46833, 17.11833 98.54166))'
geom = WKTReader().read(wkt)
pols = ['VH', 'VV']

for folder in os.listdir(path):
    output = path + folder + "\\"
    timestamp = folder.split("_")[4]
    date = timestamp[:8]
    sentinel_1 = ProductIO.readProduct(output)
    print(sentinel_1)

    for p in pols:
        polarization = p
        parameters = HashMap()
        parameters.put('geoRegion', geom)
        # parameters.put('outputImageScaleInDb', False) # Not a parameter of Subset but of Calibration

        target_1 = GPF.createProduct("Subset", parameters, sentinel_1)
        subset = output + date + "_subset_" + polarization
        ProductIO.writeProduct(target_1, subset, 'BEAM-DIMAP')

I’ve restructred the code a bit. I think the problem were the pathes to the products and at the line

target_1 = GPF.createProduct("Subset", parameters, sentinel_1)

sentinel_1 was null.

In this thread something similar is done. You can compare it with your code.

1 Like