orbisgis / h2gis

A spatial extension of the H2 database.
http://www.h2gis.org
GNU Lesser General Public License v3.0
207 stars 63 forks source link

GeoJSONWrite / GeoJSONRead - fileEncoding error #1130

Closed gpetit closed 3 years ago

gpetit commented 3 years ago

I have a problem when trying to write a GeoJSON file, using the fileEncoding parameter

I have the following TEST table

CREATE TABLE TEST(ID INT PRIMARY KEY, THE_GEOM GEOMETRY(POINT));
INSERT INTO TEST VALUES (1, 'POINT(0 1)');
INSERT INTO TEST VALUES (2, 'POINT(2 4)');

Now I export this table into a geojson file

CALL GeoJsonWrite('/home/user/test.geojson', 'TEST');

It works well.

Now, the same but specifying the fileEncoding

CALL GeoJsonWrite('/home/user/test.geojson', 'TEST', 'UTF-8');

The test.geojson is created but is empty and I have this error message

Only UTF-8, UTF-16BE, UTF-16LE, UTF-32BE, UTF-32LE encoding is supported; SQL statement:
CALL GeoJsonWrite('/home/gpetit/test.geojson', 'TEST', 'utf-8') [0-200] null/0 (Aide)

I also tried writing the encoding in lower case, but it's the same

Remark : it means that in this driver we test the encoding ? If yes, in other drivers (such as TSVWrite) we don't do the same since it's possible to write weird encoding (e.g 'utf-ofhjzofh')

SPalominos commented 3 years ago

@ebocher I'm on it

gpetit commented 3 years ago

I have the same problem with GeoJsonRead

katzyn commented 3 years ago

Section 8.1 of RFC 8259 strongly requires UTF-8 as the only one encoding for data exchange. Obsolete RFC 7159 and older specifications allowed UTF-8, UTF-16, and UTF-32, but all these 5 encodings (including BE/LE variants) can be auto-detected in JSON text easily. Therefore I don't see any good reasons to have encoding parameter in these two functions, read function can accept all of them and write function may use UTF-8 unconditionally.

ISO-8859-1 as documented default also looks wrong, because this encoding may not be legally used for JSON text.

ebocher commented 3 years ago

I'm in favor of @katzyn comments even if I introduce some of the last bad encoding support. It was necessary for a project but we must be compliant with standards.

ebocher commented 3 years ago

@ebocher I'm on it

Would be better to push it in https://github.com/ebocher/H2GIS/tree/update_jtsversion because there will have to many changes

ebocher commented 3 years ago

@SPalominos Fixed ?

ebocher commented 3 years ago

Fixed GeoJson and Json write use only utf-8