[gdal-dev] Python feature.SetField() fails with unicode strings

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

[gdal-dev] Python feature.SetField() fails with unicode strings

Roger André
Good morning,

I've been working on a simple script to load GeoJSON into PostGIS.  I'm encountering an error that has me scratching my head, it seems that unicode strings cannot be used with the feature.SetField() function in Python.  Is that really true?

I've tested this by re-writing the variable inline from my test record and can confirm that when it is type <str> it works, and when it is type <unicode> it fails with the following error.

 NotImplementedError: Wrong number of arguments for overloaded function 'Feature_SetField'.

I foind an old ticket that talks about this, https://trac.osgeo.org/gdal/ticket/4608, but I'm not having any luck getting this to work.

My GDAL version info is GDAL 1.11.0, released 2014/04/16.

To reiterate, I'm simply parsing a field from a UTF-8 encoded JSON record and trying to push it into PostGIS.

Thank you for your time.

Roger

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

Re: Python feature.SetField() fails with unicode strings

Even Rouault-2

On lundi 24 juillet 2017 08:43:02 CEST Roger André wrote:

> Good morning,

>

> I've been working on a simple script to load GeoJSON into PostGIS. I'm

> encountering an error that has me scratching my head, it seems that unicode

> strings cannot be used with the feature.SetField() function in Python. Is

> that really true?

>

> I've tested this by re-writing the variable inline from my test record and

> can confirm that when it is type <str> it works, and when it is type

> <unicode> it fails with the following error.

>

> *NotImplementedError: Wrong number of arguments for overloaded function

> 'Feature_SetField'.*

>

> I foind an old ticket that talks about this,

> https://trac.osgeo.org/gdal/ticket/4608, but I'm not having any luck

> getting this to work.

 

This ticket was fixed in GDAL 2.0. There might have been other fixes since. So basically you should try upgrading. Or as a workaround use your_string.encode('utf-8') to transform from Unicode to UTF-8 encoded string.

 

Even

 

--

Spatialys - Geospatial professional services

http://www.spatialys.com


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

Re: Python feature.SetField() fails with unicode strings

Roger André
Hi Even,

Thank you for this information.  I'll see about getting the latest version of GDAL installed on my system.  I tried using the string.encode('utf-8') workaround and continue to get the same error.

Roger

On Mon, Jul 24, 2017 at 8:46 AM, Even Rouault <[hidden email]> wrote:

On lundi 24 juillet 2017 08:43:02 CEST Roger André wrote:

> Good morning,

>

> I've been working on a simple script to load GeoJSON into PostGIS. I'm

> encountering an error that has me scratching my head, it seems that unicode

> strings cannot be used with the feature.SetField() function in Python. Is

> that really true?

>

> I've tested this by re-writing the variable inline from my test record and

> can confirm that when it is type <str> it works, and when it is type

> <unicode> it fails with the following error.

>

> *NotImplementedError: Wrong number of arguments for overloaded function

> 'Feature_SetField'.*

>

> I foind an old ticket that talks about this,

> https://trac.osgeo.org/gdal/ticket/4608, but I'm not having any luck

> getting this to work.

 

This ticket was fixed in GDAL 2.0. There might have been other fixes since. So basically you should try upgrading. Or as a workaround use your_string.encode('utf-8') to transform from Unicode to UTF-8 encoded string.

 

Even

 

--

Spatialys - Geospatial professional services

http://www.spatialys.com



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