Land-Sea-Mask

Hello,

is it possible to mask a Raster tile to the dimensions of a vector file. If i use the Land-Sea-Mask in snappy it returns a raster with values for the input multi polygon . But the file has still the dimensions of the input file. The area not included in the vector is filled with zeros. I want a file without any zeros. Just the dimension of the input vector file.

def land_sea_mask(input_product, vectorfile, shp_name):

separateShapes = False
HashMap = jpy.get_type('java.util.HashMap')
parameters = HashMap()
parameters.put('vectorFile', vectorfile)
parameters.put('separateShapes', separateShapes)
#####################
band_with_vector_1 = GPF.createProduct('Import-Vector', parameters, input_product)
#####################
# Landseamask with imported vector
HashMap = jpy.get_type('java.util.HashMap')
parameters = HashMap()
parameters.put('geometry', shp_name)
parameters.put('invertGeometry', False)
parameters.put('byPass', False)
result = GPF.createProduct('Land-Sea-Mask', parameters, band_with_vector_1)

return result`

You’ll need to trim the image with subset. Determine where in the image the data starts being anything other than no data value for all four sides.

An easier way would be to get the bounding box of your vector geometry and then subset with that.
You can pass a geometry to subset and it will do just that.
subsetOp.setGeoRegion(geometry);

I tried it out:

def land_sea_mask(input_product, vectorfile):

HashMap = jpy.get_type('java.util.HashMap')
parameters = HashMap()
parameters.put('setGeoRegion', vectorfile)
result = GPF.createProduct('Subset', parameters, snappy.ProductIO.readProduct(input_product))

The resulting geo tiff has still a dimension of (10980 x 10980 pixel).

How can I land sea mask using srtm? I use something like below, but I code the error message: RuntimeError: java.lang.ArithmeticException: / by zero

def landseamask(source):
print(’\landmasking…’)
parameters = HashMap()
parameters.put(‘landMask’, True)
parameters.put(‘useSRTM’, True)
parameters.put(‘invertGeometry’, False)
parameters.put(‘shorelineExtension’, 0)
output = GPF.createProduct(‘Land-Sea-Mask’, parameters, source)
return output