python GDAL 'GetDriverByName', argument 1 of type 'char const *'

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
3
down vote

favorite












i want to use python GDAL to convert some rasters files but i take error in the create new tiff image and specific in the line driver= gdal.GetDriverByName('GTiff')



update :



python version 2.7 64 bit



GDAL version 2020100



os: windows



i use it and before this version and all work fine
code :



inputfile = 'input.tif'
input = gdal.Open(inputfile )
inputProj = input.GetProjection()
inputTrans = input.GetGeoTransform()

referencefile = 'ref.tif'
reference = gdal.Open(referencefile )
referenceProj = reference.GetProjection()
referenceTrans = reference.GetGeoTransform()
bandreference = reference.GetRasterBand(1)
x = reference.RasterXSize
y = reference.RasterYSize


outputfile = tempfile.NamedTemporaryFile(suffix='.tif').name
driver= gdal.GetDriverByName('GTiff')
output = driver.Create(outputfile,x,y,1,bandreference.DataType)
output.SetGeoTransform(referenceTrans)
output.SetProjection(referenceProj)

gdal.ReprojectImage(input,output,inputProj,referenceProj,gdalconst.GRA_Bilinear)


error :



 return _gdal.GetDriverByName(*args)
TypeError: in method 'GetDriverByName', argument 1 of type 'char const *'


update 2:



that error show when i use this limes:



from __future__ import absolute_import
from __future__ import unicode_literals


but that i need it because i use python 2.7



any idea how to fix it ?










share|improve this question























  • What's your codepage? It looks like your 'GTiff' is being interpreted as unicode or other multibyte and being passed as const wchar_t*. Have a read of stackoverflow.com/questions/27127413/… and see if that helps.
    – Michael Stimson
    5 hours ago










  • Next time you ask a question, please include the relevant info right from the start. For coding questions like this, write a code snippet that actually demonstrates the issue. If we'd run your original code snippet with the same Python/GDAL versions it would have worked fine...! And please don't include all of your script. The code in your question could be shortened to the first 3 lines in my answer below. And lastly, always include the entire exception traceback, not just the last line.
    – Luke
    3 hours ago
















up vote
3
down vote

favorite












i want to use python GDAL to convert some rasters files but i take error in the create new tiff image and specific in the line driver= gdal.GetDriverByName('GTiff')



update :



python version 2.7 64 bit



GDAL version 2020100



os: windows



i use it and before this version and all work fine
code :



inputfile = 'input.tif'
input = gdal.Open(inputfile )
inputProj = input.GetProjection()
inputTrans = input.GetGeoTransform()

referencefile = 'ref.tif'
reference = gdal.Open(referencefile )
referenceProj = reference.GetProjection()
referenceTrans = reference.GetGeoTransform()
bandreference = reference.GetRasterBand(1)
x = reference.RasterXSize
y = reference.RasterYSize


outputfile = tempfile.NamedTemporaryFile(suffix='.tif').name
driver= gdal.GetDriverByName('GTiff')
output = driver.Create(outputfile,x,y,1,bandreference.DataType)
output.SetGeoTransform(referenceTrans)
output.SetProjection(referenceProj)

gdal.ReprojectImage(input,output,inputProj,referenceProj,gdalconst.GRA_Bilinear)


error :



 return _gdal.GetDriverByName(*args)
TypeError: in method 'GetDriverByName', argument 1 of type 'char const *'


update 2:



that error show when i use this limes:



from __future__ import absolute_import
from __future__ import unicode_literals


but that i need it because i use python 2.7



any idea how to fix it ?










share|improve this question























  • What's your codepage? It looks like your 'GTiff' is being interpreted as unicode or other multibyte and being passed as const wchar_t*. Have a read of stackoverflow.com/questions/27127413/… and see if that helps.
    – Michael Stimson
    5 hours ago










  • Next time you ask a question, please include the relevant info right from the start. For coding questions like this, write a code snippet that actually demonstrates the issue. If we'd run your original code snippet with the same Python/GDAL versions it would have worked fine...! And please don't include all of your script. The code in your question could be shortened to the first 3 lines in my answer below. And lastly, always include the entire exception traceback, not just the last line.
    – Luke
    3 hours ago












up vote
3
down vote

favorite









up vote
3
down vote

favorite











i want to use python GDAL to convert some rasters files but i take error in the create new tiff image and specific in the line driver= gdal.GetDriverByName('GTiff')



update :



python version 2.7 64 bit



GDAL version 2020100



os: windows



i use it and before this version and all work fine
code :



inputfile = 'input.tif'
input = gdal.Open(inputfile )
inputProj = input.GetProjection()
inputTrans = input.GetGeoTransform()

referencefile = 'ref.tif'
reference = gdal.Open(referencefile )
referenceProj = reference.GetProjection()
referenceTrans = reference.GetGeoTransform()
bandreference = reference.GetRasterBand(1)
x = reference.RasterXSize
y = reference.RasterYSize


outputfile = tempfile.NamedTemporaryFile(suffix='.tif').name
driver= gdal.GetDriverByName('GTiff')
output = driver.Create(outputfile,x,y,1,bandreference.DataType)
output.SetGeoTransform(referenceTrans)
output.SetProjection(referenceProj)

gdal.ReprojectImage(input,output,inputProj,referenceProj,gdalconst.GRA_Bilinear)


error :



 return _gdal.GetDriverByName(*args)
TypeError: in method 'GetDriverByName', argument 1 of type 'char const *'


update 2:



that error show when i use this limes:



from __future__ import absolute_import
from __future__ import unicode_literals


but that i need it because i use python 2.7



any idea how to fix it ?










share|improve this question















i want to use python GDAL to convert some rasters files but i take error in the create new tiff image and specific in the line driver= gdal.GetDriverByName('GTiff')



update :



python version 2.7 64 bit



GDAL version 2020100



os: windows



i use it and before this version and all work fine
code :



inputfile = 'input.tif'
input = gdal.Open(inputfile )
inputProj = input.GetProjection()
inputTrans = input.GetGeoTransform()

referencefile = 'ref.tif'
reference = gdal.Open(referencefile )
referenceProj = reference.GetProjection()
referenceTrans = reference.GetGeoTransform()
bandreference = reference.GetRasterBand(1)
x = reference.RasterXSize
y = reference.RasterYSize


outputfile = tempfile.NamedTemporaryFile(suffix='.tif').name
driver= gdal.GetDriverByName('GTiff')
output = driver.Create(outputfile,x,y,1,bandreference.DataType)
output.SetGeoTransform(referenceTrans)
output.SetProjection(referenceProj)

gdal.ReprojectImage(input,output,inputProj,referenceProj,gdalconst.GRA_Bilinear)


error :



 return _gdal.GetDriverByName(*args)
TypeError: in method 'GetDriverByName', argument 1 of type 'char const *'


update 2:



that error show when i use this limes:



from __future__ import absolute_import
from __future__ import unicode_literals


but that i need it because i use python 2.7



any idea how to fix it ?







python raster gdal python-2.7






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 6 hours ago

























asked 7 hours ago









Mar

42919




42919











  • What's your codepage? It looks like your 'GTiff' is being interpreted as unicode or other multibyte and being passed as const wchar_t*. Have a read of stackoverflow.com/questions/27127413/… and see if that helps.
    – Michael Stimson
    5 hours ago










  • Next time you ask a question, please include the relevant info right from the start. For coding questions like this, write a code snippet that actually demonstrates the issue. If we'd run your original code snippet with the same Python/GDAL versions it would have worked fine...! And please don't include all of your script. The code in your question could be shortened to the first 3 lines in my answer below. And lastly, always include the entire exception traceback, not just the last line.
    – Luke
    3 hours ago
















  • What's your codepage? It looks like your 'GTiff' is being interpreted as unicode or other multibyte and being passed as const wchar_t*. Have a read of stackoverflow.com/questions/27127413/… and see if that helps.
    – Michael Stimson
    5 hours ago










  • Next time you ask a question, please include the relevant info right from the start. For coding questions like this, write a code snippet that actually demonstrates the issue. If we'd run your original code snippet with the same Python/GDAL versions it would have worked fine...! And please don't include all of your script. The code in your question could be shortened to the first 3 lines in my answer below. And lastly, always include the entire exception traceback, not just the last line.
    – Luke
    3 hours ago















What's your codepage? It looks like your 'GTiff' is being interpreted as unicode or other multibyte and being passed as const wchar_t*. Have a read of stackoverflow.com/questions/27127413/… and see if that helps.
– Michael Stimson
5 hours ago




What's your codepage? It looks like your 'GTiff' is being interpreted as unicode or other multibyte and being passed as const wchar_t*. Have a read of stackoverflow.com/questions/27127413/… and see if that helps.
– Michael Stimson
5 hours ago












Next time you ask a question, please include the relevant info right from the start. For coding questions like this, write a code snippet that actually demonstrates the issue. If we'd run your original code snippet with the same Python/GDAL versions it would have worked fine...! And please don't include all of your script. The code in your question could be shortened to the first 3 lines in my answer below. And lastly, always include the entire exception traceback, not just the last line.
– Luke
3 hours ago




Next time you ask a question, please include the relevant info right from the start. For coding questions like this, write a code snippet that actually demonstrates the issue. If we'd run your original code snippet with the same Python/GDAL versions it would have worked fine...! And please don't include all of your script. The code in your question could be shortened to the first 3 lines in my answer below. And lastly, always include the entire exception traceback, not just the last line.
– Luke
3 hours ago










1 Answer
1






active

oldest

votes

















up vote
4
down vote













Because you imported unicode_literals, you're passing a unicode literal to GDAL which is expecting a string literal.



So, explicitly cast the 'GTiff' arg to a str.



E.g.



>>> from __future__ import unicode_literals
>>> from osgeo import gdal
>>> gdal.GetDriverByName('GTiff')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:Tempcondaenvstest27libsite-packagesosgeogdal.py", line 3019, in GetDriverByName
return _gdal.GetDriverByName(*args)
TypeError: in method 'GetDriverByName', argument 1 of type 'char const *'
>>> type('GTiff')
<type 'unicode'>
>>> gdal.GetDriverByName(str('GTiff'))
<osgeo.gdal.Driver; proxy of <Swig Object of type 'GDALDriverShadow *' at 0x0000000002A9ED80> >





share|improve this answer






















    Your Answer







    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "79"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f297054%2fpython-gdal-getdriverbyname-argument-1-of-type-char-const%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    4
    down vote













    Because you imported unicode_literals, you're passing a unicode literal to GDAL which is expecting a string literal.



    So, explicitly cast the 'GTiff' arg to a str.



    E.g.



    >>> from __future__ import unicode_literals
    >>> from osgeo import gdal
    >>> gdal.GetDriverByName('GTiff')
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "C:Tempcondaenvstest27libsite-packagesosgeogdal.py", line 3019, in GetDriverByName
    return _gdal.GetDriverByName(*args)
    TypeError: in method 'GetDriverByName', argument 1 of type 'char const *'
    >>> type('GTiff')
    <type 'unicode'>
    >>> gdal.GetDriverByName(str('GTiff'))
    <osgeo.gdal.Driver; proxy of <Swig Object of type 'GDALDriverShadow *' at 0x0000000002A9ED80> >





    share|improve this answer


























      up vote
      4
      down vote













      Because you imported unicode_literals, you're passing a unicode literal to GDAL which is expecting a string literal.



      So, explicitly cast the 'GTiff' arg to a str.



      E.g.



      >>> from __future__ import unicode_literals
      >>> from osgeo import gdal
      >>> gdal.GetDriverByName('GTiff')
      Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "C:Tempcondaenvstest27libsite-packagesosgeogdal.py", line 3019, in GetDriverByName
      return _gdal.GetDriverByName(*args)
      TypeError: in method 'GetDriverByName', argument 1 of type 'char const *'
      >>> type('GTiff')
      <type 'unicode'>
      >>> gdal.GetDriverByName(str('GTiff'))
      <osgeo.gdal.Driver; proxy of <Swig Object of type 'GDALDriverShadow *' at 0x0000000002A9ED80> >





      share|improve this answer
























        up vote
        4
        down vote










        up vote
        4
        down vote









        Because you imported unicode_literals, you're passing a unicode literal to GDAL which is expecting a string literal.



        So, explicitly cast the 'GTiff' arg to a str.



        E.g.



        >>> from __future__ import unicode_literals
        >>> from osgeo import gdal
        >>> gdal.GetDriverByName('GTiff')
        Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
        File "C:Tempcondaenvstest27libsite-packagesosgeogdal.py", line 3019, in GetDriverByName
        return _gdal.GetDriverByName(*args)
        TypeError: in method 'GetDriverByName', argument 1 of type 'char const *'
        >>> type('GTiff')
        <type 'unicode'>
        >>> gdal.GetDriverByName(str('GTiff'))
        <osgeo.gdal.Driver; proxy of <Swig Object of type 'GDALDriverShadow *' at 0x0000000002A9ED80> >





        share|improve this answer














        Because you imported unicode_literals, you're passing a unicode literal to GDAL which is expecting a string literal.



        So, explicitly cast the 'GTiff' arg to a str.



        E.g.



        >>> from __future__ import unicode_literals
        >>> from osgeo import gdal
        >>> gdal.GetDriverByName('GTiff')
        Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
        File "C:Tempcondaenvstest27libsite-packagesosgeogdal.py", line 3019, in GetDriverByName
        return _gdal.GetDriverByName(*args)
        TypeError: in method 'GetDriverByName', argument 1 of type 'char const *'
        >>> type('GTiff')
        <type 'unicode'>
        >>> gdal.GetDriverByName(str('GTiff'))
        <osgeo.gdal.Driver; proxy of <Swig Object of type 'GDALDriverShadow *' at 0x0000000002A9ED80> >






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 23 mins ago

























        answered 5 hours ago









        Luke

        27.2k25199




        27.2k25199



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f297054%2fpython-gdal-getdriverbyname-argument-1-of-type-char-const%23new-answer', 'question_page');

            );

            Post as a guest













































































            Comments

            Popular posts from this blog

            Long meetings (6-7 hours a day): Being “babysat” by supervisor

            Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

            Confectionery