Pixel Resampling in dataset

37 views
Skip to first unread message

Carlos Leandro Cordeiro

unread,
Apr 26, 2017, 9:54:11 AM4/26/17
to RSGISLib Support
Hello everyone, I need some help. I would like to do a pixel resampling on a set of 200 images. I need to resample for 90 m. I would do this together using only one script and not one image by one. can anybody help me? I tried to use a script, but it did not work. Thank you

Nathan Thomas

unread,
Apr 26, 2017, 10:01:38 AM4/26/17
to Carlos Leandro Cordeiro, RSGISLib Support
Hi Carlos,

I usually do this as follows:

import subprocess
import os

inDir = ‘input filepath’
outDir = ‘output filepath’

files = [file for file in os.listdir(inDir) if file.endswith(‘.tif’)]

for file in files:
subprocess.call(‘gdalwarp -of GTiff -tr 200 200 -r near ’ + os.path.join(inDir, file) + ‘ ‘ + os.path.join(outDir, file.replace(‘.tif’,’_200m.tif')),shell=True)

Note that the -r parameter (resampling method) should be the one most applicable to you.

If you have further issues, could you post your code?

Cheers, Nathan

On 26 Apr 2017, at 06:54, Carlos Leandro Cordeiro <carlosl...@gmail.com> wrote:

Hello everyone, I need some help. I would like to do a pixel resampling on a set of 200 images. I need to resample for 90 m. I would do this together using only one script and not one image by one. can anybody help me? I tried to use a script, but it did not work. Thank you

--
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,
Apr 26, 2017, 10:05:25 AM4/26/17
to RSGISLib Support, carlosl...@gmail.com
correction, -tr 90 90 instead of -tr 200 200

Nathan


On Wednesday, 26 April 2017 07:01:38 UTC-7, Nathan Thomas wrote:
Hi Carlos,

I usually do this as follows:

import subprocess
import os

inDir = ‘input filepath’
outDir = ‘output filepath’

files = [file for file in os.listdir(inDir) if file.endswith(‘.tif’)]

for file in files:
subprocess.call(‘gdalwarp -of GTiff -tr 200 200 -r near ’ + os.path.join(inDir, file) + ‘ ‘ + os.path.join(outDir, file.replace(‘.tif’,’_200m.tif')),shell=True)

Note that the -r parameter (resampling method) should be the one most applicable to you.

If you have further issues, could you post your code?

Cheers, Nathan
On 26 Apr 2017, at 06:54, Carlos Leandro Cordeiro <carlosl...@gmail.com> wrote:

Hello everyone, I need some help. I would like to do a pixel resampling on a set of 200 images. I need to resample for 90 m. I would do this together using only one script and not one image by one. can anybody help me? I tried to use a script, but it did not work. Thank you

--
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.

Pete Bunting [pfb]

unread,
Apr 26, 2017, 10:46:54 AM4/26/17
to Nathan Thomas, RSGISLib Support, carlosl...@gmail.com
Hi Carlos,

If you have an image for the area of interest which is already within the projection etc. that you want then you can use:

rsgislib.imageutils.resampleImage2Match(inRefImg, inProcessImg, outImg, gdalFormat, interpMethod, datatype=None)

Otherwise, there is the function (which is the same as gdalwarp):

rsgislib.imageutils.reprojectImage(inputImage, outputImage, outWKT, gdalFormat='KEA', interp='cubic', inWKT=None, noData=0.0, outPxlRes='image', snap2Grid=True)

Best wishes,

Pete


****************************************************
* Dr Pete Bunting
* Reader in Remote Sensing
* Earth Observation and Ecosystem Dynamics Group
* Department of Geography and Earth Sciences
* Aberystwyth University
* Aberystwyth
* Ceredigion
* SY23 3DB
* UK
*
* Ph: +44 (0) 1970 622615
* Mob: +44 (0) 7917 842743
* Email: p...@aber.ac.uk
* ORCID: http://orcid.org/0000-0002-7435-0148
****************************************************
"Please consider the environment before printing this email or any documents attached”

> On 26 Apr 2017, at 15:05, Nathan Thomas <nmtho...@gmail.com> wrote:
>
> correction, -tr 90 90 instead of -tr 200 200
>
> Nathan
>
> On Wednesday, 26 April 2017 07:01:38 UTC-7, Nathan Thomas wrote:
> Hi Carlos,
>
> I usually do this as follows:
>
> import subprocess
> import os
>
> inDir = ‘input filepath’
> outDir = ‘output filepath’
>
> files = [file for file in os.listdir(inDir) if file.endswith(‘.tif’)]
>
> for file in files:
> subprocess.call(‘gdalwarp -of GTiff -tr 200 200 -r near ’ + os.path.join(inDir, file) + ‘ ‘ + os.path.join(outDir, file.replace(‘.tif’,’_200m.tif')),shell=True)
>
> Note that the -r parameter (resampling method) should be the one most applicable to you.
>
> If you have further issues, could you post your code?
>
> Cheers, Nathan
>
>> On 26 Apr 2017, at 06:54, Carlos Leandro Cordeiro <carlosl...@gmail.com> wrote:
>>
>> Hello everyone, I need some help. I would like to do a pixel resampling on a set of 200 images. I need to resample for 90 m. I would do this together using only one script and not one image by one. can anybody help me? I tried to use a script, but it did not work. Thank you
>>
>> --
>> 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.
>
>
> --
> 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.
--------------------------------------------------------------------
Un o’r 4 prifysgol uchaf yn y DU a’r orau yng Nghymru am fodlonrwydd myfyrwyr.
(Arolwg Cenedlaethol y Myfyrwyr 2016)
www.aber.ac.uk

Top 4 UK university and best in Wales for student satisfaction
(National Student Survey 2016)
www.aber.ac.uk

Carlos Leandro Cordeiro

unread,
Apr 26, 2017, 2:46:24 PM4/26/17
to RSGISLib Support, nmtho...@gmail.com, carlosl...@gmail.com, p...@aber.ac.uk
Hi Nathan and Pete, we used this script and it worked.

import subprocess
import glob
#inDir = 'addressmyfolder'
#outDir = 'addressmyfolder'

infiles = glob.glob('adressmyfolder/*.tif') 
print(infiles)

for file in infiles:
outfile = file + '_90.tif'
print(file)
subprocess.call('gdalwarp -of GTiff -tr 90 90 -r bilinear ' + file + " " + outfile,shell=True)


Thank you soo much.
Reply all
Reply to author
Forward
0 new messages