Maintaining raster grid when clipping

20 views
Skip to first unread message

Nathan Thomas

unread,
Jul 2, 2018, 4:02:55 PM7/2/18
to RSGISLib Support
Hi Dan/Pete,

I have two rasters Image1 and Image2. Image1 is a local country sized dataset and Image2 is a global dataset. I want to subset Image2 to where Image1 is valid - for example '(b1==1)?b2:0'. Although the same images are the same projection and resolution they are not the same extent and I can't guarantee that they are on the same grid. I would like to subset Image2 to get Image3, but I want Image3 to have the same grid as Image2. I ideally don't want to use the CreateCopyImageCommand as this will give me a lot of global sized rasters and I want the extent to be that of the smaller image. Do you know of a way that I could subset a larger image by a smaller image, whilst maintaining the grid (but not extent) of the larger image?

I know RIOS has a 'setReferenceImage' command but this also keeps the extent of the larger image.

Cheers, Nathan

Peter Bunting

unread,
Jul 3, 2018, 4:46:18 AM7/3/18
to Nathan Thomas, RSGISLib Support
Hi Nathan, 

Just use 
rsgislib.imageutils.subset2img(inputimageinputROIimageoutputimagegdalformattype)
The grid of the output image will be the same as the input with just the extent from the ROI image. 

To use the two images together you’ll have to put them on the same grid, RSGISLib just does the nearest - to effectively nearest neighbour interpolation if you were to resample the second image.

Cheers, Pete


--
You received this message because you are subscribed to the Google Groups "RSGISLib Support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rsgislib-suppo...@googlegroups.com.
To post to this group, send email to rsgislib...@googlegroups.com.
Visit this group at https://groups.google.com/group/rsgislib-support.
For more options, visit https://groups.google.com/d/optout.

Nathan Thomas

unread,
Jul 3, 2018, 10:18:27 AM7/3/18
to Peter Bunting, RSGISLib Support
Hi Pete,

Thanks. This is useful for subsetting one image by another, but I was hoping to mask the image at the same time. I am looking for a way to keep the grid of the larger image but subset and mask it using the smaller image. Does that make sense?

Thanks, Nathan

On 3 July 2018 at 04:46, Peter Bunting <peteb...@gmail.com> wrote:
Hi Nathan, 

Just use 
rsgislib.imageutils.subset2img(inputimageinputROIimageoutputimagegdalformattype)
The grid of the output image will be the same as the input with just the extent from the ROI image. 

To use the two images together you’ll have to put them on the same grid, RSGISLib just does the nearest - to effectively nearest neighbour interpolation if you were to resample the second image.

Cheers, Pete
On 2 Jul 2018, at 21:02, Nathan Thomas <nmtho...@gmail.com> wrote:

Hi Dan/Pete,

I have two rasters Image1 and Image2. Image1 is a local country sized dataset and Image2 is a global dataset. I want to subset Image2 to where Image1 is valid - for example '(b1==1)?b2:0'. Although the same images are the same projection and resolution they are not the same extent and I can't guarantee that they are on the same grid. I would like to subset Image2 to get Image3, but I want Image3 to have the same grid as Image2. I ideally don't want to use the CreateCopyImageCommand as this will give me a lot of global sized rasters and I want the extent to be that of the smaller image. Do you know of a way that I could subset a larger image by a smaller image, whilst maintaining the grid (but not extent) of the larger image?

I know RIOS has a 'setReferenceImage' command but this also keeps the extent of the larger image.

Cheers, Nathan

--
You received this message because you are subscribed to the Google Groups "RSGISLib Support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rsgislib-support+unsubscribe@googlegroups.com.
To post to this group, send email to rsgislib-support@googlegroups.com.

Peter Bunting

unread,
Jul 3, 2018, 10:22:08 AM7/3/18
to Nathan Thomas, RSGISLib Support
HI Nathan, 

If you use the mask command then that will do what you want cutting to the common extent.

rsgislib.imageutils.maskImage(inputimageimagemaskoutputimagegdalformatdatatypeoutvaluemaskvalue)

Cheers, Pete

Nathan Thomas

unread,
Jul 3, 2018, 10:26:22 AM7/3/18
to Peter Bunting, RSGISLib Support
Awesome, thanks Pete. I'll give it a go!

Nathan
Reply all
Reply to author
Forward
0 new messages