Problem calling gdalwarp from within python script

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

Problem calling gdalwarp from within python script

Simon Proud
Hi,
I wish to call gdalwarp from within a python script but I cannot get it to work.

The command I wish to run is:

gdalwarp -q -multi -r cubicspline -t_srs '+proj=geos +lon_0=0.0 +h=35785831' -te -5568748.2758 -5568748.4774 5568748.2758 5568748.2758 -tr 3000.40316582 3000.40316582 -srcnodata 65535 TEST.tiff TEST2.tiff

I'm running on Ubuntu 12.04. The above command works perfectly when called from a terminal window and produces a good output image.

But when I run from python I get problems.
First, I tried to run with subprocess.call(["gdalwarp","-q -multi ... TEST2.tiff"]) then all I see is the default usage instructions. No file is created. Same if I use popen.

If I use: os.system("gdalwarp -q -multi ... TEST2.tiff") then it does run and I see the expected text on the screen. However, in this case the output file is blank - it is the right size and contains the right georeferencing information but every pixel in the image has a value of zero.

Does anyone have an idea what could be the problem here?
Thanks!
Reply | Threaded
Open this post in threaded view
|

Re: Problem calling gdalwarp from within python script

Kurt Schwehr-2
try

> subprocess.call(["gdalwarp", "-q",  "-multi",   ...   "TEST2.tiff"])


Each arg must be an element in the list.

-kurt

On Jan 19, 2014, at 2:27 PM, Simon Proud <[hidden email]> wrote:

> Hi,
> I wish to call gdalwarp from within a python script but I cannot get it to
> work.
>
> The command I wish to run is:
>
> gdalwarp -q -multi -r cubicspline -t_srs '+proj=geos +lon_0=0.0 +h=35785831'
> -te -5568748.2758 -5568748.4774 5568748.2758 5568748.2758 -tr 3000.40316582
> 3000.40316582 -srcnodata 65535 TEST.tiff TEST2.tiff
>
> I'm running on Ubuntu 12.04. The above command works perfectly when called
> from a terminal window and produces a good output image.
>
> But when I run from python I get problems.
> First, I tried to run with subprocess.call(["gdalwarp","-q -multi ...
> TEST2.tiff"]) then all I see is the default usage instructions. No file is
> created. Same if I use popen.
>
> If I use: os.system("gdalwarp -q -multi ... TEST2.tiff") then it does run
> and I see the expected text on the screen. However, in this case the output
> file is blank - it is the right size and contains the right georeferencing
> information but every pixel in the image has a value of zero.
>
> Does anyone have an idea what could be the problem here?
> Thanks!
>
>
>
> --
> View this message in context: http://osgeo-org.1560.x6.nabble.com/Problem-calling-gdalwarp-from-within-python-script-tp5098902.html
> Sent from the GDAL - Dev mailing list archive at Nabble.com.
> _______________________________________________
> gdal-dev mailing list
> [hidden email]
> http://lists.osgeo.org/mailman/listinfo/gdal-dev

_______________________________________________
gdal-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: Problem calling gdalwarp from within python script

Simon Proud
Hi, thanks for the reply.

I tried changing the call to this:
process.call(["gdalwarp","-q","-multi","-r cubicspline","-t_srs '+proj=geos +lon_0=0.0 +h=35785831'","-te -5568748.2758 -5568748.4774 5568748.2758 5568748.2758","-tr 3000.40316582 3000.40316582","-srcnodata 65535","TEST.tiff","TEST2.tiff"])

But still receive just the usage instructions, I can't see any other arguments that can be divided into an element. Setting the "shell=True" option also has no effect.

/Simon

________________________________________
Fra: Kurt Schwehr [[hidden email]]
Sendt: 19. januar 2014 17:47
Til: Simon Richard Proud
Cc: [hidden email] dev
Emne: Re: [gdal-dev] Problem calling gdalwarp from within python script

try

> subprocess.call(["gdalwarp", "-q",  "-multi",   ...   "TEST2.tiff"])


Each arg must be an element in the list.

-kurt

On Jan 19, 2014, at 2:27 PM, Simon Proud <[hidden email]> wrote:

> Hi,
> I wish to call gdalwarp from within a python script but I cannot get it to
> work.
>
> The command I wish to run is:
>
> gdalwarp -q -multi -r cubicspline -t_srs '+proj=geos +lon_0=0.0 +h=35785831'
> -te -5568748.2758 -5568748.4774 5568748.2758 5568748.2758 -tr 3000.40316582
> 3000.40316582 -srcnodata 65535 TEST.tiff TEST2.tiff
>
> I'm running on Ubuntu 12.04. The above command works perfectly when called
> from a terminal window and produces a good output image.
>
> But when I run from python I get problems.
> First, I tried to run with subprocess.call(["gdalwarp","-q -multi ...
> TEST2.tiff"]) then all I see is the default usage instructions. No file is
> created. Same if I use popen.
>
> If I use: os.system("gdalwarp -q -multi ... TEST2.tiff") then it does run
> and I see the expected text on the screen. However, in this case the output
> file is blank - it is the right size and contains the right georeferencing
> information but every pixel in the image has a value of zero.
>
> Does anyone have an idea what could be the problem here?
> Thanks!
>
>
>
> --
> View this message in context: http://osgeo-org.1560.x6.nabble.com/Problem-calling-gdalwarp-from-within-python-script-tp5098902.html
> Sent from the GDAL - Dev mailing list archive at Nabble.com.
> _______________________________________________
> gdal-dev mailing list
> [hidden email]
> http://lists.osgeo.org/mailman/listinfo/gdal-dev


_______________________________________________
gdal-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: Problem calling gdalwarp from within python script

Kurt Schwehr-2
> ,"-r cubicspline",


becomes

"-r", "cubicspline",

and so forth

On Jan 19, 2014, at 3:00 PM, Simon Richard Proud <[hidden email]> wrote:

> Hi, thanks for the reply.
>
> I tried changing the call to this:
> process.call(["gdalwarp","-q","-multi","-r cubicspline","-t_srs '+proj=geos +lon_0=0.0 +h=35785831'","-te -5568748.2758 -5568748.4774 5568748.2758 5568748.2758","-tr 3000.40316582 3000.40316582","-srcnodata 65535","TEST.tiff","TEST2.tiff"])
>
> But still receive just the usage instructions, I can't see any other arguments that can be divided into an element. Setting the "shell=True" option also has no effect.
>
> /Simon
>
> ________________________________________
> Fra: Kurt Schwehr [[hidden email]]
> Sendt: 19. januar 2014 17:47
> Til: Simon Richard Proud
> Cc: [hidden email] dev
> Emne: Re: [gdal-dev] Problem calling gdalwarp from within python script
>
> try
>
>> subprocess.call(["gdalwarp", "-q",  "-multi",   ...   "TEST2.tiff"])
>
>
> Each arg must be an element in the list.
>
> -kurt
>
> On Jan 19, 2014, at 2:27 PM, Simon Proud <[hidden email]> wrote:
>
>> Hi,
>> I wish to call gdalwarp from within a python script but I cannot get it to
>> work.
>>
>> The command I wish to run is:
>>
>> gdalwarp -q -multi -r cubicspline -t_srs '+proj=geos +lon_0=0.0 +h=35785831'
>> -te -5568748.2758 -5568748.4774 5568748.2758 5568748.2758 -tr 3000.40316582
>> 3000.40316582 -srcnodata 65535 TEST.tiff TEST2.tiff
>>
>> I'm running on Ubuntu 12.04. The above command works perfectly when called
>> from a terminal window and produces a good output image.
>>
>> But when I run from python I get problems.
>> First, I tried to run with subprocess.call(["gdalwarp","-q -multi ...
>> TEST2.tiff"]) then all I see is the default usage instructions. No file is
>> created. Same if I use popen.
>>
>> If I use: os.system("gdalwarp -q -multi ... TEST2.tiff") then it does run
>> and I see the expected text on the screen. However, in this case the output
>> file is blank - it is the right size and contains the right georeferencing
>> information but every pixel in the image has a value of zero.
>>
>> Does anyone have an idea what could be the problem here?
>> Thanks!
>>
>>
>>
>> --
>> View this message in context: http://osgeo-org.1560.x6.nabble.com/Problem-calling-gdalwarp-from-within-python-script-tp5098902.html
>> Sent from the GDAL - Dev mailing list archive at Nabble.com.
>> _______________________________________________
>> gdal-dev mailing list
>> [hidden email]
>> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>
>

_______________________________________________
gdal-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: Problem calling gdalwarp from within python script

Simon Proud
Ok, that gets things a little closer - now it gives an error: "ERROR 1: Translating source or target SRS failed"
I tried with '+proj=geos +lon_0=0.0 +h=35785831' as one argument and as three. Same result.
I also tried including the -te and -tr arguments in the one argument along with the proj details - no luck with that either.

/Simon
________________________________________
Fra: Kurt Schwehr [[hidden email]]
Sendt: 19. januar 2014 18:05
Til: Simon Richard Proud
Cc: [hidden email] dev
Emne: Re: [gdal-dev] Problem calling gdalwarp from within python script

> ,"-r cubicspline",


becomes

"-r", "cubicspline",

and so forth

On Jan 19, 2014, at 3:00 PM, Simon Richard Proud <[hidden email]> wrote:

> Hi, thanks for the reply.
>
> I tried changing the call to this:
> process.call(["gdalwarp","-q","-multi","-r cubicspline","-t_srs '+proj=geos +lon_0=0.0 +h=35785831'","-te -5568748.2758 -5568748.4774 5568748.2758 5568748.2758","-tr 3000.40316582 3000.40316582","-srcnodata 65535","TEST.tiff","TEST2.tiff"])
>
> But still receive just the usage instructions, I can't see any other arguments that can be divided into an element. Setting the "shell=True" option also has no effect.
>
> /Simon
>
> ________________________________________
> Fra: Kurt Schwehr [[hidden email]]
> Sendt: 19. januar 2014 17:47
> Til: Simon Richard Proud
> Cc: [hidden email] dev
> Emne: Re: [gdal-dev] Problem calling gdalwarp from within python script
>
> try
>
>> subprocess.call(["gdalwarp", "-q",  "-multi",   ...   "TEST2.tiff"])
>
>
> Each arg must be an element in the list.
>
> -kurt
>
> On Jan 19, 2014, at 2:27 PM, Simon Proud <[hidden email]> wrote:
>
>> Hi,
>> I wish to call gdalwarp from within a python script but I cannot get it to
>> work.
>>
>> The command I wish to run is:
>>
>> gdalwarp -q -multi -r cubicspline -t_srs '+proj=geos +lon_0=0.0 +h=35785831'
>> -te -5568748.2758 -5568748.4774 5568748.2758 5568748.2758 -tr 3000.40316582
>> 3000.40316582 -srcnodata 65535 TEST.tiff TEST2.tiff
>>
>> I'm running on Ubuntu 12.04. The above command works perfectly when called
>> from a terminal window and produces a good output image.
>>
>> But when I run from python I get problems.
>> First, I tried to run with subprocess.call(["gdalwarp","-q -multi ...
>> TEST2.tiff"]) then all I see is the default usage instructions. No file is
>> created. Same if I use popen.
>>
>> If I use: os.system("gdalwarp -q -multi ... TEST2.tiff") then it does run
>> and I see the expected text on the screen. However, in this case the output
>> file is blank - it is the right size and contains the right georeferencing
>> information but every pixel in the image has a value of zero.
>>
>> Does anyone have an idea what could be the problem here?
>> Thanks!
>>
>>
>>
>> --
>> View this message in context: http://osgeo-org.1560.x6.nabble.com/Problem-calling-gdalwarp-from-within-python-script-tp5098902.html
>> Sent from the GDAL - Dev mailing list archive at Nabble.com.
>> _______________________________________________
>> gdal-dev mailing list
>> [hidden email]
>> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>
>


_______________________________________________
gdal-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: Problem calling gdalwarp from within python script

Kurt Schwehr-2
have not tested this, but I would guess something like this...

['gdalwarp','-q','-multi','-r', 'cubicspline','-t_srs', '+proj=geos +lon_0=0.0 +h=35785831', '-te', '-5568748.2758 -5568748.4774 5568748.2758 5568748.2758','-tr', '3000.40316582 3000.40316582', '-srcnodata', '65535','TEST.tiff', 'TEST2.tiff']


On Jan 19, 2014, at 3:13 PM, Simon Richard Proud <[hidden email]> wrote:

> Ok, that gets things a little closer - now it gives an error: "ERROR 1: Translating source or target SRS failed"
> I tried with '+proj=geos +lon_0=0.0 +h=35785831' as one argument and as three. Same result.
> I also tried including the -te and -tr arguments in the one argument along with the proj details - no luck with that either.
>
> /Simon
> ________________________________________
> Fra: Kurt Schwehr [[hidden email]]
> Sendt: 19. januar 2014 18:05
> Til: Simon Richard Proud
> Cc: [hidden email] dev
> Emne: Re: [gdal-dev] Problem calling gdalwarp from within python script
>
>> ,"-r cubicspline",
>
>
> becomes
>
> "-r", "cubicspline",
>
> and so forth
>
> On Jan 19, 2014, at 3:00 PM, Simon Richard Proud <[hidden email]> wrote:
>
>> Hi, thanks for the reply.
>>
>> I tried changing the call to this:
>> process.call(["gdalwarp","-q","-multi","-r cubicspline","-t_srs '+proj=geos +lon_0=0.0 +h=35785831'","-te -5568748.2758 -5568748.4774 5568748.2758 5568748.2758","-tr 3000.40316582 3000.40316582","-srcnodata 65535","TEST.tiff","TEST2.tiff"])
>>
>> But still receive just the usage instructions, I can't see any other arguments that can be divided into an element. Setting the "shell=True" option also has no effect.
>>
>> /Simon
>>
>> ________________________________________
>> Fra: Kurt Schwehr [[hidden email]]
>> Sendt: 19. januar 2014 17:47
>> Til: Simon Richard Proud
>> Cc: [hidden email] dev
>> Emne: Re: [gdal-dev] Problem calling gdalwarp from within python script
>>
>> try
>>
>>> subprocess.call(["gdalwarp", "-q",  "-multi",   ...   "TEST2.tiff"])
>>
>>
>> Each arg must be an element in the list.
>>
>> -kurt
>>
>> On Jan 19, 2014, at 2:27 PM, Simon Proud <[hidden email]> wrote:
>>
>>> Hi,
>>> I wish to call gdalwarp from within a python script but I cannot get it to
>>> work.
>>>
>>> The command I wish to run is:
>>>
>>> gdalwarp -q -multi -r cubicspline -t_srs '+proj=geos +lon_0=0.0 +h=35785831'
>>> -te -5568748.2758 -5568748.4774 5568748.2758 5568748.2758 -tr 3000.40316582
>>> 3000.40316582 -srcnodata 65535 TEST.tiff TEST2.tiff
>>>
>>> I'm running on Ubuntu 12.04. The above command works perfectly when called
>>> from a terminal window and produces a good output image.
>>>
>>> But when I run from python I get problems.
>>> First, I tried to run with subprocess.call(["gdalwarp","-q -multi ...
>>> TEST2.tiff"]) then all I see is the default usage instructions. No file is
>>> created. Same if I use popen.
>>>
>>> If I use: os.system("gdalwarp -q -multi ... TEST2.tiff") then it does run
>>> and I see the expected text on the screen. However, in this case the output
>>> file is blank - it is the right size and contains the right georeferencing
>>> information but every pixel in the image has a value of zero.
>>>
>>> Does anyone have an idea what could be the problem here?
>>> Thanks!
>>>
>>>
>>>
>>> --
>>> View this message in context: http://osgeo-org.1560.x6.nabble.com/Problem-calling-gdalwarp-from-within-python-script-tp5098902.html
>>> Sent from the GDAL - Dev mailing list archive at Nabble.com.
>>> _______________________________________________
>>> gdal-dev mailing list
>>> [hidden email]
>>> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>>
>>
>
>

_______________________________________________
gdal-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: Problem calling gdalwarp from within python script

Simon Proud
Hi,
Unfortunately that produces a file not found error with filename "65535". If I remove both arguments "-srcnodata" and "65535" then I go back to getting the usage guidelines.

/Simon
________________________________________
Fra: Kurt Schwehr [[hidden email]]
Sendt: 19. januar 2014 19:00
Til: Simon Richard Proud
Cc: [hidden email] dev
Emne: Re: [gdal-dev] Problem calling gdalwarp from within python script

have not tested this, but I would guess something like this...

['gdalwarp','-q','-multi','-r', 'cubicspline','-t_srs', '+proj=geos +lon_0=0.0 +h=35785831', '-te', '-5568748.2758 -5568748.4774 5568748.2758 5568748.2758','-tr', '3000.40316582 3000.40316582', '-srcnodata', '65535','TEST.tiff', 'TEST2.tiff']


On Jan 19, 2014, at 3:13 PM, Simon Richard Proud <[hidden email]> wrote:

> Ok, that gets things a little closer - now it gives an error: "ERROR 1: Translating source or target SRS failed"
> I tried with '+proj=geos +lon_0=0.0 +h=35785831' as one argument and as three. Same result.
> I also tried including the -te and -tr arguments in the one argument along with the proj details - no luck with that either.
>
> /Simon
> ________________________________________
> Fra: Kurt Schwehr [[hidden email]]
> Sendt: 19. januar 2014 18:05
> Til: Simon Richard Proud
> Cc: [hidden email] dev
> Emne: Re: [gdal-dev] Problem calling gdalwarp from within python script
>
>> ,"-r cubicspline",
>
>
> becomes
>
> "-r", "cubicspline",
>
> and so forth
>
> On Jan 19, 2014, at 3:00 PM, Simon Richard Proud <[hidden email]> wrote:
>
>> Hi, thanks for the reply.
>>
>> I tried changing the call to this:
>> process.call(["gdalwarp","-q","-multi","-r cubicspline","-t_srs '+proj=geos +lon_0=0.0 +h=35785831'","-te -5568748.2758 -5568748.4774 5568748.2758 5568748.2758","-tr 3000.40316582 3000.40316582","-srcnodata 65535","TEST.tiff","TEST2.tiff"])
>>
>> But still receive just the usage instructions, I can't see any other arguments that can be divided into an element. Setting the "shell=True" option also has no effect.
>>
>> /Simon
>>
>> ________________________________________
>> Fra: Kurt Schwehr [[hidden email]]
>> Sendt: 19. januar 2014 17:47
>> Til: Simon Richard Proud
>> Cc: [hidden email] dev
>> Emne: Re: [gdal-dev] Problem calling gdalwarp from within python script
>>
>> try
>>
>>> subprocess.call(["gdalwarp", "-q",  "-multi",   ...   "TEST2.tiff"])
>>
>>
>> Each arg must be an element in the list.
>>
>> -kurt
>>
>> On Jan 19, 2014, at 2:27 PM, Simon Proud <[hidden email]> wrote:
>>
>>> Hi,
>>> I wish to call gdalwarp from within a python script but I cannot get it to
>>> work.
>>>
>>> The command I wish to run is:
>>>
>>> gdalwarp -q -multi -r cubicspline -t_srs '+proj=geos +lon_0=0.0 +h=35785831'
>>> -te -5568748.2758 -5568748.4774 5568748.2758 5568748.2758 -tr 3000.40316582
>>> 3000.40316582 -srcnodata 65535 TEST.tiff TEST2.tiff
>>>
>>> I'm running on Ubuntu 12.04. The above command works perfectly when called
>>> from a terminal window and produces a good output image.
>>>
>>> But when I run from python I get problems.
>>> First, I tried to run with subprocess.call(["gdalwarp","-q -multi ...
>>> TEST2.tiff"]) then all I see is the default usage instructions. No file is
>>> created. Same if I use popen.
>>>
>>> If I use: os.system("gdalwarp -q -multi ... TEST2.tiff") then it does run
>>> and I see the expected text on the screen. However, in this case the output
>>> file is blank - it is the right size and contains the right georeferencing
>>> information but every pixel in the image has a value of zero.
>>>
>>> Does anyone have an idea what could be the problem here?
>>> Thanks!
>>>
>>>
>>>
>>> --
>>> View this message in context: http://osgeo-org.1560.x6.nabble.com/Problem-calling-gdalwarp-from-within-python-script-tp5098902.html
>>> Sent from the GDAL - Dev mailing list archive at Nabble.com.
>>> _______________________________________________
>>> gdal-dev mailing list
>>> [hidden email]
>>> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>>
>>
>
>


_______________________________________________
gdal-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: Problem calling gdalwarp from within python script

Even Rouault
Selon Simon Richard Proud <[hidden email]>:

> Hi,
> Unfortunately that produces a file not found error with filename "65535". If
> I remove both arguments "-srcnodata" and "65535" then I go back to getting
> the usage guidelines.

You need to separate also the numerical values after -te and -tr

['gdalwarp','-q','-multi','-r', 'cubicspline','-t_srs', '+proj=geos +lon_0=0.0
+h=35785831', '-te', '-5568748.2758', '-5568748.4774', '5568748.2758',
'5568748.2758','-tr', '3000.40316582', '3000.40316582', '-srcnodata',
'65535','TEST.tiff', 'TEST2.tiff']

>
> /Simon
> ________________________________________
> Fra: Kurt Schwehr [[hidden email]]
> Sendt: 19. januar 2014 19:00
> Til: Simon Richard Proud
> Cc: [hidden email] dev
> Emne: Re: [gdal-dev] Problem calling gdalwarp from within python script
>
> have not tested this, but I would guess something like this...
>
> ['gdalwarp','-q','-multi','-r', 'cubicspline','-t_srs', '+proj=geos
> +lon_0=0.0 +h=35785831', '-te', '-5568748.2758 -5568748.4774 5568748.2758
> 5568748.2758','-tr', '3000.40316582 3000.40316582', '-srcnodata',
> '65535','TEST.tiff', 'TEST2.tiff']
>
>
> On Jan 19, 2014, at 3:13 PM, Simon Richard Proud <[hidden email]> wrote:
>
> > Ok, that gets things a little closer - now it gives an error: "ERROR 1:
> Translating source or target SRS failed"
> > I tried with '+proj=geos +lon_0=0.0 +h=35785831' as one argument and as
> three. Same result.
> > I also tried including the -te and -tr arguments in the one argument along
> with the proj details - no luck with that either.
> >
> > /Simon
> > ________________________________________
> > Fra: Kurt Schwehr [[hidden email]]
> > Sendt: 19. januar 2014 18:05
> > Til: Simon Richard Proud
> > Cc: [hidden email] dev
> > Emne: Re: [gdal-dev] Problem calling gdalwarp from within python script
> >
> >> ,"-r cubicspline",
> >
> >
> > becomes
> >
> > "-r", "cubicspline",
> >
> > and so forth
> >
> > On Jan 19, 2014, at 3:00 PM, Simon Richard Proud <[hidden email]> wrote:
> >
> >> Hi, thanks for the reply.
> >>
> >> I tried changing the call to this:
> >> process.call(["gdalwarp","-q","-multi","-r cubicspline","-t_srs
> '+proj=geos +lon_0=0.0 +h=35785831'","-te -5568748.2758 -5568748.4774
> 5568748.2758 5568748.2758","-tr 3000.40316582 3000.40316582","-srcnodata
> 65535","TEST.tiff","TEST2.tiff"])
> >>
> >> But still receive just the usage instructions, I can't see any other
> arguments that can be divided into an element. Setting the "shell=True"
> option also has no effect.
> >>
> >> /Simon
> >>
> >> ________________________________________
> >> Fra: Kurt Schwehr [[hidden email]]
> >> Sendt: 19. januar 2014 17:47
> >> Til: Simon Richard Proud
> >> Cc: [hidden email] dev
> >> Emne: Re: [gdal-dev] Problem calling gdalwarp from within python script
> >>
> >> try
> >>
> >>> subprocess.call(["gdalwarp", "-q",  "-multi",   ...   "TEST2.tiff"])
> >>
> >>
> >> Each arg must be an element in the list.
> >>
> >> -kurt
> >>
> >> On Jan 19, 2014, at 2:27 PM, Simon Proud <[hidden email]> wrote:
> >>
> >>> Hi,
> >>> I wish to call gdalwarp from within a python script but I cannot get it
> to
> >>> work.
> >>>
> >>> The command I wish to run is:
> >>>
> >>> gdalwarp -q -multi -r cubicspline -t_srs '+proj=geos +lon_0=0.0
> +h=35785831'
> >>> -te -5568748.2758 -5568748.4774 5568748.2758 5568748.2758 -tr
> 3000.40316582
> >>> 3000.40316582 -srcnodata 65535 TEST.tiff TEST2.tiff
> >>>
> >>> I'm running on Ubuntu 12.04. The above command works perfectly when
> called
> >>> from a terminal window and produces a good output image.
> >>>
> >>> But when I run from python I get problems.
> >>> First, I tried to run with subprocess.call(["gdalwarp","-q -multi ...
> >>> TEST2.tiff"]) then all I see is the default usage instructions. No file
> is
> >>> created. Same if I use popen.
> >>>
> >>> If I use: os.system("gdalwarp -q -multi ... TEST2.tiff") then it does run
> >>> and I see the expected text on the screen. However, in this case the
> output
> >>> file is blank - it is the right size and contains the right
> georeferencing
> >>> information but every pixel in the image has a value of zero.
> >>>
> >>> Does anyone have an idea what could be the problem here?
> >>> Thanks!
> >>>
> >>>
> >>>
> >>> --
> >>> View this message in context:
>
http://osgeo-org.1560.x6.nabble.com/Problem-calling-gdalwarp-from-within-python-script-tp5098902.html

> >>> Sent from the GDAL - Dev mailing list archive at Nabble.com.
> >>> _______________________________________________
> >>> gdal-dev mailing list
> >>> [hidden email]
> >>> http://lists.osgeo.org/mailman/listinfo/gdal-dev
> >>
> >>
> >
> >
>
>
> _______________________________________________
> gdal-dev mailing list
> [hidden email]
> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>






_______________________________________________
gdal-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: Problem calling gdalwarp from within python script

Pietro Zambelli
In reply to this post by Simon Proud
On Sunday 19 Jan 2014 14:27:49 Simon Proud wrote:

> Hi,
> I wish to call gdalwarp from within a python script but I cannot get
> it to work.
>
> The command I wish to run is:
>
> gdalwarp -q -multi -r cubicspline -t_srs '+proj=geos +lon_0=0.0
> +h=35785831' -te -5568748.2758 -5568748.4774 5568748.2758
> 5568748.2758 -tr 3000.40316582 3000.40316582 -srcnodata 65535
> TEST.tiff TEST2.tiff

You can run the command directly with:

{{{
cmd = "gdalwarp -q -multi -r cubicspline -t_srs '+proj=geos +lon_0=0.0
 +h=35785831' -te -5568748.2758 -5568748.4774 5568748.2758
 5568748.2758 -tr 3000.40316582 3000.40316582 -srcnodata 65535
 TEST.tiff TEST2.tiff"

Subprocess.Popen(cmd, shell=True)
}}}

See the doc:
http://docs.python.org/2/library/subprocess.html#using-the-subprocess-module

Pietro
_______________________________________________
gdal-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: Problem calling gdalwarp from within python script

Sean Gillies-3
In reply to this post by Even Rouault
On 1/20/14, 1:57 AM, Even Rouault wrote:

> Selon Simon Richard Proud <[hidden email]>:
>
>> Hi,
>> Unfortunately that produces a file not found error with filename "65535". If
>> I remove both arguments "-srcnodata" and "65535" then I go back to getting
>> the usage guidelines.
>
> You need to separate also the numerical values after -te and -tr
>
> ['gdalwarp','-q','-multi','-r', 'cubicspline','-t_srs', '+proj=geos +lon_0=0.0
> +h=35785831', '-te', '-5568748.2758', '-5568748.4774', '5568748.2758',
> '5568748.2758','-tr', '3000.40316582', '3000.40316582', '-srcnodata',
> '65535','TEST.tiff', 'TEST2.tiff']

The shlex.split() function is handy for turning strings that you would
have passed to os.system() into a list of args for subprocess functions.

     >>> import shlex
     >>> shlex.split('gdalwarp -q -multi -r cubicspline -te
-5568748.2758 -5568748.4774 5568748.2758 5568748.2758')
     ['gdalwarp', '-q', '-multi', '-r', 'cubicspline', '-te',
'-5568748.2758', '-5568748.4774', '5568748.2758', '5568748.2758']

...

--
Sean Gillies
[hidden email]
_______________________________________________
gdal-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: Problem calling gdalwarp from within python script

Simon Proud
Does anyone have any other ideas as to what would be causing gdalwarp to output entire blank images when called from a python script?
I can get it to run using os.system and subprocess.call (using both shell=True and shell=False) but always just get a blank image (all pixels=0). This does not happen if I run exactly the same command from a terminal window.

Thanks,
Simon

________________________________________
Fra: [hidden email] [[hidden email]] p&#229; vegne af Sean Gillies [[hidden email]]
Sendt: 20. januar 2014 11:56
Til: [hidden email]
Emne: Re: [gdal-dev] Problem calling gdalwarp from within python script

On 1/20/14, 1:57 AM, Even Rouault wrote:

> Selon Simon Richard Proud <[hidden email]>:
>
>> Hi,
>> Unfortunately that produces a file not found error with filename "65535". If
>> I remove both arguments "-srcnodata" and "65535" then I go back to getting
>> the usage guidelines.
>
> You need to separate also the numerical values after -te and -tr
>
> ['gdalwarp','-q','-multi','-r', 'cubicspline','-t_srs', '+proj=geos +lon_0=0.0
> +h=35785831', '-te', '-5568748.2758', '-5568748.4774', '5568748.2758',
> '5568748.2758','-tr', '3000.40316582', '3000.40316582', '-srcnodata',
> '65535','TEST.tiff', 'TEST2.tiff']

The shlex.split() function is handy for turning strings that you would
have passed to os.system() into a list of args for subprocess functions.

     >>> import shlex
     >>> shlex.split('gdalwarp -q -multi -r cubicspline -te
-5568748.2758 -5568748.4774 5568748.2758 5568748.2758')
     ['gdalwarp', '-q', '-multi', '-r', 'cubicspline', '-te',
'-5568748.2758', '-5568748.4774', '5568748.2758', '5568748.2758']

...

--
Sean Gillies
[hidden email]
_______________________________________________
gdal-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/gdal-dev


_______________________________________________
gdal-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: Problem calling gdalwarp from within python script

Even Rouault
Le vendredi 24 janvier 2014 21:46:50, Simon Richard Proud a écrit :
> Does anyone have any other ideas as to what would be causing gdalwarp to
> output entire blank images when called from a python script? I can get it
> to run using os.system and subprocess.call (using both shell=True and
> shell=False) but always just get a blank image (all pixels=0). This does
> not happen if I run exactly the same command from a terminal window.

I can't see any rational reason for that... Just in case : are you sure you
are running the same GDAL lib and binary in the terminal and from Python ?

>
> Thanks,
> Simon
>
> ________________________________________
> Fra: [hidden email] [[hidden email]]
> p&#229; vegne af Sean Gillies [[hidden email]] Sendt: 20. januar 2014
> 11:56
> Til: [hidden email]
> Emne: Re: [gdal-dev] Problem calling gdalwarp from within python script
>
> On 1/20/14, 1:57 AM, Even Rouault wrote:
> > Selon Simon Richard Proud <[hidden email]>:
> >> Hi,
> >> Unfortunately that produces a file not found error with filename
> >> "65535". If I remove both arguments "-srcnodata" and "65535" then I go
> >> back to getting the usage guidelines.
> >
> > You need to separate also the numerical values after -te and -tr
> >
> > ['gdalwarp','-q','-multi','-r', 'cubicspline','-t_srs', '+proj=geos
> > +lon_0=0.0 +h=35785831', '-te', '-5568748.2758', '-5568748.4774',
> > '5568748.2758', '5568748.2758','-tr', '3000.40316582', '3000.40316582',
> > '-srcnodata', '65535','TEST.tiff', 'TEST2.tiff']
>
> The shlex.split() function is handy for turning strings that you would
> have passed to os.system() into a list of args for subprocess functions.
>
>      >>> import shlex
>      >>> shlex.split('gdalwarp -q -multi -r cubicspline -te
>
> -5568748.2758 -5568748.4774 5568748.2758 5568748.2758')
>      ['gdalwarp', '-q', '-multi', '-r', 'cubicspline', '-te',
> '-5568748.2758', '-5568748.4774', '5568748.2758', '5568748.2758']
>
> ...
>
> --
> Sean Gillies
> [hidden email]
> _______________________________________________
> gdal-dev mailing list
> [hidden email]
> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>
>
> _______________________________________________
> gdal-dev mailing list
> [hidden email]
> http://lists.osgeo.org/mailman/listinfo/gdal-dev

--
Geospatial professional services
http://even.rouault.free.fr/services.html
_______________________________________________
gdal-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/gdal-dev
Reply | Threaded
Open this post in threaded view
|

Re: Problem calling gdalwarp from within python script

Simon Proud
Hi,
>>I can't see any rational reason for that... Just in case : are you sure you
>>are running the same GDAL lib and binary in the terminal and from Python ?

Yes, there's only one GDAL lib installed on the system - the default one that can be installed from the Ubuntu package manager.

Anyway, I changed to use the internal gdal.ReprojectImage() commands (rather than calling gdalwarp) and those work well. So from my perspective there is no problem, although it'd be nice to know what happened in gdalwarp!

Cheers,
Simon

________________________________________
Fra: Even Rouault [[hidden email]]
Sendt: 24. januar 2014 16:17
Til: [hidden email]
Cc: Simon Richard Proud; Sean Gillies
Emne: Re: [gdal-dev] Problem calling gdalwarp from within python script

Le vendredi 24 janvier 2014 21:46:50, Simon Richard Proud a écrit :
> Does anyone have any other ideas as to what would be causing gdalwarp to
> output entire blank images when called from a python script? I can get it
> to run using os.system and subprocess.call (using both shell=True and
> shell=False) but always just get a blank image (all pixels=0). This does
> not happen if I run exactly the same command from a terminal window.

I can't see any rational reason for that... Just in case : are you sure you
are running the same GDAL lib and binary in the terminal and from Python ?

>
> Thanks,
> Simon
>
> ________________________________________
> Fra: [hidden email] [[hidden email]]
> p&#229; vegne af Sean Gillies [[hidden email]] Sendt: 20. januar 2014
> 11:56
> Til: [hidden email]
> Emne: Re: [gdal-dev] Problem calling gdalwarp from within python script
>
> On 1/20/14, 1:57 AM, Even Rouault wrote:
> > Selon Simon Richard Proud <[hidden email]>:
> >> Hi,
> >> Unfortunately that produces a file not found error with filename
> >> "65535". If I remove both arguments "-srcnodata" and "65535" then I go
> >> back to getting the usage guidelines.
> >
> > You need to separate also the numerical values after -te and -tr
> >
> > ['gdalwarp','-q','-multi','-r', 'cubicspline','-t_srs', '+proj=geos
> > +lon_0=0.0 +h=35785831', '-te', '-5568748.2758', '-5568748.4774',
> > '5568748.2758', '5568748.2758','-tr', '3000.40316582', '3000.40316582',
> > '-srcnodata', '65535','TEST.tiff', 'TEST2.tiff']
>
> The shlex.split() function is handy for turning strings that you would
> have passed to os.system() into a list of args for subprocess functions.
>
>      >>> import shlex
>      >>> shlex.split('gdalwarp -q -multi -r cubicspline -te
>
> -5568748.2758 -5568748.4774 5568748.2758 5568748.2758')
>      ['gdalwarp', '-q', '-multi', '-r', 'cubicspline', '-te',
> '-5568748.2758', '-5568748.4774', '5568748.2758', '5568748.2758']
>
> ...
>
> --
> Sean Gillies
> [hidden email]
> _______________________________________________
> gdal-dev mailing list
> [hidden email]
> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>
>
> _______________________________________________
> gdal-dev mailing list
> [hidden email]
> http://lists.osgeo.org/mailman/listinfo/gdal-dev

--
Geospatial professional services
http://even.rouault.free.fr/services.html


_______________________________________________
gdal-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/gdal-dev