Re: [gdal-dev] ogr2ogr changes field length

2021-10-12 Thread matteo

Hi Jukka,


GDAL has the internal default of 80 characters. GDAL users do not really need 
other options because fields are automatically expanded when longer strings are 
appended afterwards but if the shapefile is used in some other software it does 
happen that it is impossible to insert long strings because there is no room 
for that in the table. I suppose that you also know that by using the field 
width of 254 you are also maximizing the size of the .dbf file because it 
reserves the same fixed amount of disk space for each cell.


got it! Yes, I'm aware of the disk space :)

Cheers and thanks

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


Re: [gdal-dev] ogr2ogr changes field length

2021-10-08 Thread Rahkonen Jukka (MML)
Hi,

GDAL has the internal default of 80 characters. GDAL users do not really need 
other options because fields are automatically expanded when longer strings are 
appended afterwards but if the shapefile is used in some other software it does 
happen that it is impossible to insert long strings because there is no room 
for that in the table. I suppose that you also know that by using the field 
width of 254 you are also maximizing the size of the .dbf file because it 
reserves the same fixed amount of disk space for each cell.

-Jukka Rahkonen-

-Alkuperäinen viesti-
Lähettäjä: matteo  
Lähetetty: perjantai 8. lokakuuta 2021 12.29
Vastaanottaja: Rahkonen Jukka (MML) ; Even 
Rouault ; gdal-dev@lists.osgeo.org
Aihe: Re: [gdal-dev] ogr2ogr changes field length

Hi Jukka,

works perfectly, thanks!

so no default options to impose the field length but it is alterable after

Cheers!

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


Re: [gdal-dev] ogr2ogr changes field length

2021-10-08 Thread matteo

Hi Jukka,

works perfectly, thanks!

so no default options to impose the field length but it is alterable after

Cheers!

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


Re: [gdal-dev] ogr2ogr changes field length

2021-10-08 Thread Rahkonen Jukka (MML)
Hi,

The best I can suggest to do by using just GDAL utilities is to run this kind 
of ogrinfo command for each text field that you have in the shapefile schema:

ogrinfo my_shape.shp -sql "alter table my_shape alter column STRING_1 TYPE 
character(254)"

(right, the max length is 254).

-Jukka Rahkonen-
 
-Alkuperäinen viesti-
Lähettäjä: matteo  
Lähetetty: perjantai 8. lokakuuta 2021 11.20
Vastaanottaja: Rahkonen Jukka (MML) ; Even 
Rouault ; gdal-dev@lists.osgeo.org
Aihe: Re: [gdal-dev] ogr2ogr changes field length

Hi Jukka,

> The strings fields are created by default with width 80. If there are longer 
> strings in the data the width is automatically extended up till 255 
> characters that is the maximum that dBase format supports. If strings are 
> shorter than 80 charaters it is possible to use RESIZE and shrink the width 
> to match the longest string used in that field.
> 
> If you need better control on field widths I suppose you must create an empty 
> shapefile for ogr2ogr to append by your own code.
> 
> # Add a new field.
>  field_defn = ogr.FieldDefn('NEWFLD', ogr.OFTString)
>  field_defn.SetWidth(12)
> 
> Do you have some concrete problem with field widths that you want to resolve?

I'm "dumping" empty tables of a schema to shapefile and actually yes, I need 
that the fields with unlimited text set up in PG should be the maximum (so 254) 
in the final shapefiles.

All the tables are empty so I guess this is the "problem" I have

Cheers and thanks

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


Re: [gdal-dev] ogr2ogr changes field length

2021-10-08 Thread matteo

Hi Jukka,


The strings fields are created by default with width 80. If there are longer 
strings in the data the width is automatically extended up till 255 characters 
that is the maximum that dBase format supports. If strings are shorter than 80 
charaters it is possible to use RESIZE and shrink the width to match the 
longest string used in that field.

If you need better control on field widths I suppose you must create an empty 
shapefile for ogr2ogr to append by your own code.

# Add a new field.
 field_defn = ogr.FieldDefn('NEWFLD', ogr.OFTString)
 field_defn.SetWidth(12)

Do you have some concrete problem with field widths that you want to resolve?


I'm "dumping" empty tables of a schema to shapefile and actually yes, I 
need that the fields with unlimited text set up in PG should be the 
maximum (so 254) in the final shapefiles.


All the tables are empty so I guess this is the "problem" I have

Cheers and thanks

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


Re: [gdal-dev] ogr2ogr changes field length

2021-10-07 Thread Rahkonen Jukka (MML)
Hi,

The strings fields are created by default with width 80. If there are longer 
strings in the data the width is automatically extended up till 255 characters 
that is the maximum that dBase format supports. If strings are shorter than 80 
charaters it is possible to use RESIZE and shrink the width to match the 
longest string used in that field.

If you need better control on field widths I suppose you must create an empty 
shapefile for ogr2ogr to append by your own code.

# Add a new field.
field_defn = ogr.FieldDefn('NEWFLD', ogr.OFTString)
field_defn.SetWidth(12)

Do you have some concrete problem with field widths that you want to resolve?

-Jukka Rahkonen-

-Alkuperäinen viesti-
Lähettäjä: gdal-dev  Puolesta matteo
Lähetetty: perjantai 8. lokakuuta 2021 9.11
Vastaanottaja: Even Rouault ; 
gdal-dev@lists.osgeo.org
Aihe: Re: [gdal-dev] ogr2ogr changes field length

Hi Even,

> If you add -lco RESIZE=YES fields will be resized to their minimum size. 
> See 
> https://gdal.org/drivers/vector/shapefile.html#layer-creation-options

yep I see. I also read

* String fields without an assigned width are treated as 80 characters

does it mean that if a field is set as TEXT in PG (without length
definition) the conversion to shapefile is automatically set to 80 and what we 
can do is to resize the field length only to have less characters?

Cheers!

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


Re: [gdal-dev] ogr2ogr changes field length

2021-10-07 Thread matteo

Hi Even,

If you add -lco RESIZE=YES fields will be resized to their minimum size. 
See https://gdal.org/drivers/vector/shapefile.html#layer-creation-options


yep I see. I also read

* String fields without an assigned width are treated as 80 characters

does it mean that if a field is set as TEXT in PG (without length 
definition) the conversion to shapefile is automatically set to 80 and 
what we can do is to resize the field length only to have less characters?


Cheers!

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


Re: [gdal-dev] ogr2ogr changes field length

2021-10-07 Thread Even Rouault
If you add -lco RESIZE=YES fields will be resized to their minimum size. 
See https://gdal.org/drivers/vector/shapefile.html#layer-creation-options


Le 07/10/2021 à 17:40, matteo a écrit :

Even,

still a weird issue with the command. I'm using this command

ogr2ogr -f "ESRI Shapefile" /home/matteo/myfolder "PG:dbname='mydb' 
host=myhost port=5432 user='myuser' password='mypws' sslmode=disable 
schemas='dati'" --config PG_USE_COPY YES --config PG_LIST_ALL_TABLES 
YES -progress'


so without any append or overwrite (dumping a whole schema in a folder).

I've both spatial and not spatial tables and for all of them the text 
fields are created in PG like:


CREATE TABLE mytable (
    ID SERIAL PRIMARY KEY,
    .
    NOTE text
)

and all these fields are 80 characters long in the newly created 
shapefiles...


I don't know if I can give some more information..

Cheers and thanks

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] ogr2ogr changes field length

2021-10-07 Thread matteo

Even,

still a weird issue with the command. I'm using this command

ogr2ogr -f "ESRI Shapefile" /home/matteo/myfolder "PG:dbname='mydb' 
host=myhost port=5432 user='myuser' password='mypws' sslmode=disable 
schemas='dati'" --config PG_USE_COPY YES --config PG_LIST_ALL_TABLES YES 
-progress'


so without any append or overwrite (dumping a whole schema in a folder).

I've both spatial and not spatial tables and for all of them the text 
fields are created in PG like:


CREATE TABLE mytable (
ID SERIAL PRIMARY KEY,
.
NOTE text
)

and all these fields are 80 characters long in the newly created 
shapefiles...


I don't know if I can give some more information..

Cheers and thanks

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


Re: [gdal-dev] ogr2ogr changes field length

2021-10-07 Thread matteo

Hi Even,

thanks for the hint :) it si just an additional step

Cheers!

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


Re: [gdal-dev] ogr2ogr changes field length

2021-10-06 Thread Even Rouault

Matteo,

When overwriting, a fresh new file/table is creating, without keeping 
anything from the existing version.


You could probably just blank your target with

ogrinfo target.shp -sql "DELETE FROM target" -dialect SQLITE

and then ogr2ogr -append target.shp PG:   -nln target

Even

Le 06/10/2021 à 17:37, matteo a écrit :

Hi list,

I've a script that uses ogr2ogr to copy, actually overwrite, tables 
from PG to shapfiles.


The PG fields are all text (without a specified length) and the target 
shapefile that will be overwritten have all text field length equals 
to 254.


When overwriting the length is changes to 80. Is there any specific 
option to keep the original field length?


Cheers and thanks

Matteo
___
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


[gdal-dev] ogr2ogr changes field length

2021-10-06 Thread matteo

Hi list,

I've a script that uses ogr2ogr to copy, actually overwrite, tables from 
PG to shapfiles.


The PG fields are all text (without a specified length) and the target 
shapefile that will be overwritten have all text field length equals to 254.


When overwriting the length is changes to 80. Is there any specific 
option to keep the original field length?


Cheers and thanks

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