Re: [gdal-dev] PGCLIENTENCODING in ogr2ogr (and QGIS)

2021-12-07 Thread matteo

Hi Even,

this is also a solution. If I get it correctly I can get the encoding 
from within QGIS and pass it to the Processing script that calls GDAL. 
In this way the encoding is taken upstream and ogr2ogr should be able to 
pass it to the PG database


Thanks!

Matteo
___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev


Re: [gdal-dev] PGCLIENTENCODING in ogr2ogr (and QGIS)

2021-12-03 Thread Even Rouault
Instead of turning Postgres client_encoding to LATIN1 (which won't work 
here because -f PostgreSQL goes through the CreateDataSource() OGR API, 
which will ignore destination dataset open options provided with -doo) , 
I would rather set the shapefile encoding with -oo 
ENCODING=ISO-8859-1,then the OGR shapefile reader will transcode 
internally from ISO-8859-1 to UTF-8, which should make Postgres API


Le 03/12/2021 à 14:55, matteo a écrit :

Hi Rahkonen,

sorry for the delay. The command, built with Processing in QGIS using 
the GdalUtils utility is at the end:


ogr2ogr -f PostgreSQL "PG:dbname='db' host=myhost port=myport 
user='myuser' password='mypassword' sslmode=disable schemas=myschema" 
shapefile.shp --config PG_USE_COPY YES -append -skipfailures -nlt 
PROMOTE_TO_MULTI -doo PRELUDE_STATEMENTS="SET client_encoding TO LATIN1"


a small file can be found here:

https://faunalia.eu/~matteo/shapefile.zip

and yes. The database encoding is:

HOW SERVER_ENCODING;
 server_encoding
-
 UTF8
(1 row)

while the encoding of the shapefile is ISO-8859-1

Thanks for any hint!

Matteo




--
http://www.spatialys.com
My software is free, but my time generally not.

___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev


Re: [gdal-dev] PGCLIENTENCODING in ogr2ogr (and QGIS)

2021-12-03 Thread matteo

Hi Rahkonen,

sorry for the delay. The command, built with Processing in QGIS using 
the GdalUtils utility is at the end:


ogr2ogr -f PostgreSQL "PG:dbname='db' host=myhost port=myport 
user='myuser' password='mypassword' sslmode=disable schemas=myschema" 
shapefile.shp --config PG_USE_COPY YES -append -skipfailures -nlt 
PROMOTE_TO_MULTI -doo PRELUDE_STATEMENTS="SET client_encoding TO LATIN1"


a small file can be found here:

https://faunalia.eu/~matteo/shapefile.zip

and yes. The database encoding is:

HOW SERVER_ENCODING;
 server_encoding
-
 UTF8
(1 row)

while the encoding of the shapefile is ISO-8859-1

Thanks for any hint!

Matteo



___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev


Re: [gdal-dev] PGCLIENTENCODING in ogr2ogr (and QGIS)

2021-11-30 Thread Rahkonen Jukka (MML)
Hi,

Would you mind to include your whole ogr2ogr command (no passwords etc.) and if 
possible, link to some small shapefile? And confirm that your aim is to save 
shapefiles with Latin1 encoding into PostGIS database that is using UTF-8 
encoding.

-Jukka Rahkonen-

-Alkuperäinen viesti-
Lähettäjä: matteo  
Lähetetty: tiistai 30. marraskuuta 2021 13.05
Vastaanottaja: Even Rouault ; Rahkonen Jukka (MML) 
; gdal-dev@lists.osgeo.org
Aihe: Re: [gdal-dev] PGCLIENTENCODING in ogr2ogr (and QGIS)

Hi Rahkonen and Even,

thanks for the answers. If I add -oo PRELUDE_STATEMENTS="SET client_encoding TO 
LATIN1" the I get this error:

Warning 6: driver ESRI Shapefile does not support open option PRELUDE_STATEMENTS

and I think it that makes sense because I want to put in a UTF8 DB some
LATIN1 shapefiles.

BTW: the shapefiles have been created with ogr2ogr from within QGIS (on a Linux 
computer), opened and edited on QGIS on Windows machines.

Other ideas are more than welcome!

Cheers!

Matteo
___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev


Re: [gdal-dev] PGCLIENTENCODING in ogr2ogr (and QGIS)

2021-11-30 Thread matteo

Hi Rahkonen and Even,

thanks for the answers. If I add -oo PRELUDE_STATEMENTS="SET 
client_encoding TO LATIN1" the I get this error:


Warning 6: driver ESRI Shapefile does not support open option 
PRELUDE_STATEMENTS


and I think it that makes sense because I want to put in a UTF8 DB some 
LATIN1 shapefiles.


BTW: the shapefiles have been created with ogr2ogr from within QGIS (on 
a Linux computer), opened and edited on QGIS on Windows machines.


Other ideas are more than welcome!

Cheers!

Matteo
___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev


Re: [gdal-dev] PGCLIENTENCODING in ogr2ogr (and QGIS)

2021-11-29 Thread Even Rouault

Hi,

I would try with that environmental variable first.


The thing is that there's no way in the vector format conversion tool of 
QGIS to specify pure environment variables (GDAL configuration options 
can be passed with --config key value, but PGCLIENTENCODING can't be 
specify that way). However it is possible to use the PRELUDE_STATEMENTS 
open option of the PostgreSQL driver, by adding (a bit abusively) in the 
additional creation option entry box:   -oo PRELUDE_STATEMENTS="SET 
client_encoding TO LATIN1"  (assuming that the need is to convert from 
PostgreSQL. )


Even



-Jukka Rahkonen-

-Alkuperäinen viesti-
Lähettäjä: gdal-dev  Puolesta matteo
Lähetetty: maanantai 29. marraskuuta 2021 18.52
Vastaanottaja: gdal-dev@lists.osgeo.org
Aihe: [gdal-dev] PGCLIENTENCODING in ogr2ogr (and QGIS)

Hi all,

I'm trying to run a command with the GdalUtils.runGdal utility of QGIS but I 
get some troubles because of the encoding.

Basically I need to set the encoding to PGCLIENTENCODING=LATIN1. If I call it 
in a console, no problem at all (of course :) ). Wondering if I can set the 
encoding also within QGIS (that is basically via the ogr2ogr command).

I know that this is a more QGIS question, but QGIS is calling ogr2ogr, so I 
think if there is a ogr2ogr way to do that then also within QGIS should be 
possible.

Cheers and thanks for any ideas!

Matteo
___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev
___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev


--
http://www.spatialys.com
My software is free, but my time generally not.

___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev


Re: [gdal-dev] PGCLIENTENCODING in ogr2ogr (and QGIS)

2021-11-29 Thread Rahkonen Jukka (MML)
Hi,

There is some text about client encoding in 
https://gdal.org/drivers/vector/pg.html

" By default it is assumed that text being sent to Postgres is in the UTF-8 
encoding. This is fine for plain ASCII, but can result in errors for extended 
characters (ASCII 155+, LATIN1, etc). While OGR provides no direct control over 
this, you can set the PGCLIENTENCODING environment variable to indicate the 
format being provided. For instance, if your text is LATIN1 you could set the 
environment variable to LATIN1 before using OGR and input would be assumed to 
be LATIN1 instead of UTF-8. An alternate way of setting the client encoding is 
to issue the following SQL command with ExecuteSQL() : "SET client_encoding TO 
encoding_name" where encoding_name is LATIN1, etc. Errors can be caught by 
enclosing this command with a CPLPushErrorHandler()/CPLPopErrorHandler() pair."

I would try with that environmental variable first.

-Jukka Rahkonen-

-Alkuperäinen viesti-
Lähettäjä: gdal-dev  Puolesta matteo
Lähetetty: maanantai 29. marraskuuta 2021 18.52
Vastaanottaja: gdal-dev@lists.osgeo.org
Aihe: [gdal-dev] PGCLIENTENCODING in ogr2ogr (and QGIS)

Hi all,

I'm trying to run a command with the GdalUtils.runGdal utility of QGIS but I 
get some troubles because of the encoding.

Basically I need to set the encoding to PGCLIENTENCODING=LATIN1. If I call it 
in a console, no problem at all (of course :) ). Wondering if I can set the 
encoding also within QGIS (that is basically via the ogr2ogr command).

I know that this is a more QGIS question, but QGIS is calling ogr2ogr, so I 
think if there is a ogr2ogr way to do that then also within QGIS should be 
possible.

Cheers and thanks for any ideas!

Matteo
___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev
___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev


[gdal-dev] PGCLIENTENCODING in ogr2ogr (and QGIS)

2021-11-29 Thread matteo

Hi all,

I'm trying to run a command with the GdalUtils.runGdal utility of QGIS 
but I get some troubles because of the encoding.


Basically I need to set the encoding to PGCLIENTENCODING=LATIN1. If I 
call it in a console, no problem at all (of course :) ). Wondering if I 
can set the encoding also within QGIS (that is basically via the ogr2ogr 
command).


I know that this is a more QGIS question, but QGIS is calling ogr2ogr, 
so I think if there is a ogr2ogr way to do that then also within QGIS 
should be possible.


Cheers and thanks for any ideas!

Matteo
___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev