2

I have few tables those have some unicode value of different language. When I am trying to export the data from PostGIS to GeoJSON using ogr2ogr the returned GeoJSON showing wrong unicode language like this

ბáƒáƒœáƒ’ლáƒáƒ“ეშáƒ

I am using the following command to the export job

ogr2ogr -f GeoJSON /opt//data.geojson PG:"host=localhost dbname=test user=postgres port=5432 password=12345678 tables=data" -t_srs EPSG:4326 -lco ENCODING=UTF-8 
4
  • 1
    How are the strings encoded in PostGIS? How does ogr2ogr find that out? How does it then map those encoded strings to Unicode code points and hence UTF-8 encoding? The ENCODING=UTF-8 does nothing in your example because that's not an option for the geoJSON driver.
    – Spacedman
    Commented Oct 21, 2018 at 13:02
  • The database was encoded in UTF-8. When viewing the table its showing accurate value. Even when doing the query through php it also returned accurate value. Commented Oct 22, 2018 at 5:46
  • 1
    Can you create a reproducible example using a tiny table - maybe one row should suffice - such that you can paste a dump of that table somewhere for us to reproduce your problem?
    – Spacedman
    Commented Oct 22, 2018 at 7:12
  • Please download the file drive.google.com/open?id=1bGkKu2rYhqBcxfc6Ngo188D_SeDpBlpE. Store it in Postgis and export GeoJSON with ogr2ogr. If you open the JSON file you can see if there any Unicode language rather than english that will be broken as stated in the question. Its an osm file hstore extension will be needed Commented Oct 22, 2018 at 11:57

1 Answer 1

3
+25

The layer creation option (LCO) ENCODING=UTF-8 does not apply when creating GeoJSON layers. (In fact, it applies to few OGR-supported drivers, including ESRI Shapefile and MapInfo TAB.) So that option is being silently ignored.

According the GIS.SE question GeoJSON attributes encoding limitation, GeoJSON only supports UTF (including UTF-8, -16, and -32). In the reverse direction, the PostGIS database will only support whatever encoding was used when the database was created. ogr2ogr will automatically convert between encodings where necessary, but in this case your database is in UTF-8 and GeoJSON only supports UTF-x. Therefore you should run this command without the -lco switch, and you get what you get.

If you are not viewing the UTF letters as expected, this is an issue of your viewer, whether that be a text editor, desktop GIS, or programming language, not handling the UTF-8 characters correctly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.