[Gdal-dev] shp,dbf export and field (type,length) problem

Frank Warmerdam fwarmerdam at gmail.com
Wed Jan 26 12:57:44 EST 2005


On Wed, 26 Jan 2005 18:07:44 +0100, Lionel Bargeot
<l.bargeot at educagri.fr> wrote:
> With ogr2ogr :
> ----------------------
> simple export :
> ----------------------
> ogr2ogr -f "ESRI Shapefile" temp PG:"dbname=form user=lionel" -nln test
> -sql "SELECT * from tb_exemple"
> dbfdump -i temp/test.dbf
>  ...
> Field info:
> Num Name Type Len Decimal
> 1. OBJECTID C 80 0
> 2. NUMERO C 80 0
> 3. OTHER_ID C 80 0
> 4. ID_ILOT C 80 0
> 5. AN_AREA C 80 0

Lionel,

Looking through the OGR PG driver details, I see that very
different logic is used to build the OGRFeatureSchema (the
attribute definitions for a layer) depending on whether the
data is coming directly from a table, or is the result of an
SQL query.  

If the result is from an SQL query I only have the output
of the PQftype() function as a description of the type.  It
returns an enumerated field type but to the best of my
knowledge there is no way for me to get field types.  
Furthermore, I am not aware of a special code for "decimal"
types so I fallback to treating them as strings. 

When I read directly from a table, I query the type information
from the pg_class table and should provide a more correct
width and precision for decimal fields. 

So, you might want to contrast your results with the results of
a direct dump of the table.  Also you can dig through the
ReadTableDefinition() and ReadResultDefinition() methods in
ogrpgtablelayer.cpp and ogrpgresultlayer.cpp respectively to 
see if you can see some useful fixes or even local hacks
sufficient for your own purposes. 

If you see a good solution please submit an enhancement
request via bugzilla. 

Best regards,

-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | Geospatial Programmer for Rent



More information about the Gdal-dev mailing list