[gdal-dev] VRT/CSV to PostgreSQL - Convert Missing/Blank Values to NULL?

Jason Greenlaw - NOAA Affiliate jason.greenlaw at noaa.gov
Thu Jan 24 13:54:48 PST 2013


When loading into a PostgreSQL/PostGIS database, can the VRT/CSV driver
convert missing values (for a "Real" field) to NULL instead of defaulting
to 0.00?

Example:

I'm attempting to load a CSV file into PostgreSQL using the following
simple VRT file:

--------------------------------------------------------
<OGRVRTDataSource>
    <OGRVRTLayer name="sfcdump">
        <SrcDataSource relativeToVRT="1">sfcdump.csv</SrcDataSource>
        <GeometryType>wkbPoint</GeometryType>
        <LayerSRS>WGS84</LayerSRS>
        <GeometryField encoding="PointFromColumns" x="longitude"
y="latitude"/>
        <Field name="stnid" src="stnid" type="String"/>
        <Field name="latitude" src="latitude" type="Real"/>
        <Field name="longitude" src="longitude" type="Real"/>
        <Field name="td" src="td" type="Real"/>
        <Field name="t" src="t" type="Real"/>
    </OGRVRTLayer>
</OGRVRTDataSource>
--------------------------------------------------------

Some of the records do not have any value for the "td" column; for example,
this single-record CSV:

--------------------------------------------------------
stnid,lat,lon,td,t
KOVE,39.490002,-121.620003,,283.0019
--------------------------------------------------------

When records such as these are loaded into the database using ogr2ogr, the
missing value becomes 0.00 rather than NULL.

Is this expected behavior?  Is there any way to tell the VRT/CSV driver how
to handle missing/null values for numeric fields?

Additionally, I've noticed that blank/missing values for String columns get
imported as empty strings rather than NULL (but perhaps that's the expected
behavior in this case).

Thanks,
Jason
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20130124/ccd81fd0/attachment.html>


More information about the gdal-dev mailing list