[Gdal-dev] FIXED - OGR can't handle Null values in a Date field

Mateusz Loskot mateusz at loskot.net
Fri Jun 30 05:15:12 EDT 2006


Aaron Koning wrote:
> Is there anyway of getting OGR to output Null values into a Date 
> field when there is a Null value present in the input Date field?

Hi,

Last days, I fixed this issue but due to my Internet connection was
broken, I could not commit it.
So, now I can and I've committed my changes to CVS.

Changes:
- Fixed Shape driver - NULL/0 date value was converted to string without
zero fill for year, e.g. 0/00/00 instead of 0000/00/00.

- Fixed NULL handling in PG driver - now, if date field stores year of
0000, the value is considered as NULL, because there is no ZERO year
(this follows PostgreSQL/MySQL dates handling behaviour, interesting
reference:
http://groups.google.pl/group/mailing.database.pgsql-sql/browse_frm/thread/1685953a3ebf48c1

So, I was able to import Aaron's shapefile to PostgreSQL 8.1.4.
Here are my commands:

ogr2ogr -f PostgreSQL PG:dbname=gdal_nulldate bugs/null_date/dates.shp

NOTE: I renamed Aaron's shapefile to dates.shp
Here is what I got in my gdal_nulldate database:

gdal_nulldate=# \dt
        List of relations
 Schema | Name  | Type  |  Owner
--------+-------+-------+---------
 public | dates | table | mloskot
(1 row)

gdal_nulldate=# \d dates
                                  Table "public.dates"
    Column    |     Type      |                        Modifiers
--------------+---------------+---------------------------------------------------------
 ogc_fid      | integer       | not null default
nextval('dates_ogc_fid_seq'::regclass)
 wkb_geometry | bytea         |
 dstrbedate   | date          |
 dstrbsdate   | date          |
 licenceid    | character(50) |
 permitid     | character(50) |
 blknmbr      | character(50) |
Indexes:
    "dates_pk" PRIMARY KEY, btree (ogc_fid)

gdal_nulldate=# select dstrbedate, dstrbsdate from dates;
 dstrbedate | dstrbsdate
------------+------------
 2001-02-07 | 2001-02-07
 2001-02-08 | 2001-02-08
 2002-02-01 | 2002-02-01
 2002-01-05 | 2002-01-05
 1999-01-06 | 1999-01-06
 1997-12-24 | 1997-12-24
 1999-03-03 | 1999-03-03
 2001-11-01 | 2001-11-01
 1998-12-21 | 1998-12-21
 1998-09-10 | 1998-09-10
 1998-02-04 | 1998-02-04
 2001-01-08 | 2001-01-08
            |
 1996-12-23 | 1996-12-23
 1992-11-13 | 1992-11-13
 1996-01-05 | 1996-01-05
            |
 1990-01-01 | 1990-01-01
(18 rows)

gdal_nulldate=#

NOTE: As you can see, two records store null dates, just as in the input
shapefile.

So, I assume this issue is fixed, but there are small things I'd like to
explain/learn (regarding OGR Shape driver and dates).
Please, see my comment marked with 'XXX - mloskot' in the
ogr/ogrsf_frmts/shape/shape2ogr.cpp file.

Cheers
-- 
Mateusz Loskot
http://mateusz.loskot.net



More information about the Gdal-dev mailing list