MapTools.org

[Shapelib] Re: Information about ESRI ShapeFiles

shapelib@lists.maptools.org shapelib@lists.maptools.org
Thu, 15 Jan 2004 02:01:17 -0500
James Rowe wrote:
> Hi Frank,
> I'm working on implementing an ESRI ShapeFile utility in C++ for reading and
> writing ShapeFiles programmatically. I'm currently adding support for
> reading and writing attributes to an associated DBF file.  I'm using the
> Shapefile C Library version 1.2.10 as the file writer.
> My problem is that the ShapeFile C library does not seem to write out
> default values for attributes correctly. I'm assuming it's not doing it
> correctly because I'm using ESRI ArcExplorer 4.0.1 to try to read the
> ShapeFile and AreExplorer is complaining that it can't interpret it. I tried
> creating a ShapeFile using PCI Geomatica and ArcExplorer happily read it
> (even with default attribute values in it). Unfortunately, Geomatica does
> not correctly put default values in. I tried saving a ShapeFile that had no
> value for a real number field, but when read back using ArcExplorer the
> value showed up as 1.328753764365E+308. So even Geomatica isn't reliable.
> 
> What I'm looking for is if you have any insight into how to deal with
> default values in DBF files or if you can point to somewhere that I can find
> more information. Ideally I'd like to find a utility that checks if a
> ShapeFile is valid or not and tells why it's not valid. Or even if you have
> a lead on where I can find a proper specification for the DBF file. The
> whitesheet for the ESRI ShapeFile doesn't go into any depth on DBF files.
> Instead it refers to a dBASE file spec from IMPRISE Corp. that I can't find
> anymore.

James,

I am afraid I don't know the real answer for NULL handling in DBF files.  There
is a bunch of code built into DBFIsAttributeNULL() that says:

     switch(psDBF->pachFieldType[iField])
     {
       case 'N':
       case 'F':
         /* NULL numeric fields have value "****************" */
         return pszValue[0] == '*';

       case 'D':
         /* NULL date fields have value "00000000" */
         return strncmp(pszValue,"00000000",8) == 0;

       case 'L':
         /* NULL boolean fields have value "?" */
         return pszValue[0] == '?';

       default:
         /* empty string fields are considered NULL */
         return strlen(pszValue) == 0;
     }

So, here the impression is that different "null" values are used for each
type of field.  It looks like DBFWriteAttribute() tries to set values in
this manner when initializing a new record too.

You might want to verify that the fields in question are in fact being
written with these null values.  If so, then you might consider whether
ArcExplorer is really doing the right thing.  What does ArcView or ArcGIS do?

There are various dBase/xBase format specs available on wotsit:

   http://www.wotsit.org/search.asp?s=database

PS. I have taken the liberty of cc:ing this message to the shapelib list.
It is quite new, and so has very few members, but this question and any
followup conversation is of general interest so I would like it added to
the email archive.

Best regards,

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




This archive was generated by Pipermail.