Welcome to the BEAM Forum!

We encourage you to sign in our forum and participate in the BEAM community. The forum is maintained by the BEAM project team who will most likely answer your questions within 24 hours (except during common holidays) - if not done by other community members. Collaborate, share your knowledge and learn from other users!

If you don't find what you are looking for, please also consider the following external forums:

Combination View Flat View Tree View
Threads [ Previous | Next ]
RE: SubsetOp usage
toggle
SubsetOp usage
8/3/15 8:28 AM
Apologies for the long delay in clarification(was away on vacation) but I still have few questions with the SubsetOp operator.

I have read this question - SubsetOp Usage

From this link SubsetOp Source Code

what exactly are the units of SubSamplingX and SubSamplingY ?

Also can is it possible to get a illustration on the JstGeometryConverter class ? I could not find a past answer in the forums.
Flag Flag
RE: SubsetOp usage
8/4/15 11:44 AM as a reply to Ashwin D.
SubSamplingX/Y are unitless parameters, specifying the numbers of pixels into which a pixel is subsampled in x and y direction. See ProductSubsetDef for its usage.

The class JtsGeometryConverter converts JtsGeometry-Objects to String and vice versa. See its Converter superclass for more documentation.

Cheers,
Thomas
Flag Flag
RE: SubsetOp usage
8/6/15 9:49 AM as a reply to Thomas Storm.
Thomas,
I was able execute it successfully with the following code snippet. I would appreciate a code review.
 1
 2                 GPF.getDefaultInstance().getOperatorSpiRegistry().loadOperatorSpis();
 3        Product source = ProductIO.readProduct("abc.tif");
 4        int height = source.getSceneRasterHeight();
 5        System.out.println("The height of raster is " + height);
 6        int width = source.getSceneRasterWidth();
 7        System.out.println("The width of raster is " + width);
 8
 9        HashMap<String, Object> parameterMap = new HashMap<>();
10        parameterMap.put("subSamplingX", 100);
11        parameterMap.put("subSamplingY", 100);
12        parameterMap.put("copyMetadata", "true");
13        Product targetProduct = GPF.createProduct("Subset", parameterMap, source);


When I print out the height and width of the sub product I got values 1/100th of the original height and width. Additionally I did not have to set the region parameter. Is that necessary ? I was also able to print out the land coverage values as well.

Regards,
Ashwin.
Flag Flag
RE: SubsetOp usage
8/6/15 1:39 PM as a reply to Ashwin D.
Hi,

you have done something valid, but I think it is not what you wanted to do emoticon

You have created a product of the same scene, but with only 1/100 of the spatial resolution. Typically, you would rather use the SubsetOp to create a spatial subset of the view. In that case, you will need to pass region information (otherwise it cannot work -- by definition). If you also want to downgrade the resolution, you can use subsamplingX and subsamplingY.

Additionally, I'd suggest to preserve the geo-information by adding the line
ProductUtils.copyGeoCoding(source, targetProduct);

Cheers,
Thomas
Flag Flag
RE: SubsetOp usage
8/6/15 2:22 PM as a reply to Thomas Storm.
Thomas,
Your response covers the reason why it is important one has a code review when one enters a new field such as remote sensing :-)
Otherwise like in my case - no errors and it is like everything is fine. I will use the java.awt.Rectangle class and get back to you.
Regards,
Ashwin.
Flag Flag
RE: SubsetOp usage
8/6/15 3:45 PM as a reply to Thomas Storm.
Thomas,
Here is the modified code. I would once again appreciate a code review. Essentially I am 'cropping' a 1 degree by 1 degree tile out of the original GEOTIFF product. Regarding the use of ProductUtils can these two API calls be added to the parameterMap ?

 1
 2                 GPF.getDefaultInstance().getOperatorSpiRegistry().loadOperatorSpis();
 3        Product source = ProductIO.readProduct("abc.tif");
 4        int height = source.getSceneRasterHeight();
 5        System.out.println("The height of raster is " + height);
 6        int width = source.getSceneRasterWidth();
 7        System.out.println("The width of raster is " + width);
 8
 9        HashMap<String, Object> parameterMap = new HashMap<>();
10        Rectangle region = new Rectangle(0,0,3599,3599);
11        parameterMap.put("region", region);
12
13        Product targetProduct = GPF.createProduct("Subset", parameterMap, source);
14          
15        ProductUtils.copyMetadata(source, targetProduct);
16        ProductUtils.copyGeoCoding(source,targetProduct);
17        height = targetProduct.getSceneRasterHeight();
18        System.out.println("The height of raster is " + height);
19        width = targetProduct.getSceneRasterWidth();
20        System.out.println("The width of raster is " + width);


Regards,
Ashwin.
Flag Flag
RE: SubsetOp usage
8/7/15 11:47 AM as a reply to Ashwin D.
Hi Ashwin,

this looks fine. Indeed, it is better to move the information to copy the metadata into the parameters map, like

parameterMap.put("copyMetadata", true);

The copying of the geo-information is already done by the operator; you can just remove it. Sorry, my wrong.

Cheers,
Thomas
Flag Flag
RE: SubsetOp usage
8/22/15 7:19 AM as a reply to Thomas Storm.
Thomas/Marco,
When I try to use the Subset option on VISAT I get an option called Geocoordinates. Using this option I was able to subset a product based on latitude and longitude. Can this be done using the API as well ?
Regards,
Ashwin.
Flag Flag
RE: SubsetOp usage
8/24/15 8:33 AM as a reply to Ashwin D.
Yes, instead of using the region parameter you can do the following.

1String geoBounds = "POLYGON ((14.52 55.38, 15.29 55.38, 15.29 54.91, 14.52 54.91, 14.52 55.38))"
2parameterMap.put("geoRegion", geoBounds);


Regards
Marco
Flag Flag
RE: SubsetOp usage
8/24/15 11:09 AM as a reply to Marco Peters.
Marco Peters:
Yes, instead of using the region parameter you can do the following.

1String geoBounds = "POLYGON ((14.52 55.38, 15.29 55.38, 15.29 54.91, 14.52 54.91, 14.52 55.38))"
2parameterMap.put("geoRegion", geoBounds);


Regards
Marco


Marco,
Looks great. So if I understand your code correctly it has more flexibility than the java.awt.Rectangle class as you can 'crop' any shape out of the existing product. In your example above you have cropped a 'pentagon' out of the product by specifying five lat/lon pairs. Am I correct ?
Regards,
Ashwin.
Flag Flag
RE: SubsetOp usage
8/24/15 1:34 PM as a reply to Ashwin D.
No, it is an rectangle what I have specified. The first and last coordinate have to be the same. See Wikipedia.
You can specify any shape as geoRegion but at the end the bounding box of this shape will be used to subset the product.

Marco
Flag Flag