Shapefile field problem

Ryan, Adam ARyan at CO.LINN.OR.US
Tue Dec 7 11:27:30 EST 2004


Abe,

Here's a routine I use to get the header information (field info) from a dbf
file.

//      ==========      iDbf_fields     ==============
//      $f is a dbf file path, returns an array of field arrays
function iDbf_fields($f){
        $h = fopen($f,"rb");
        $a =
unpack("cversion/cyy/cmm/cdd/inumrecs/sheadsize/srecsize",fread($h,12));
        fread($h,20);   //skip some reserved space
        for($i=0;$i<($a["headsize"]-33)/32;$i++){
                $fa = array();
                $fname = trim(fread($h,11));
                $fa["type"] = fread($h,1);
                fread($h,4);
                $fa = array_merge($fa,unpack("Clen/Cpre",fread($h,2)));
                fread($h,14);
                $flds[$fname] = $fa;
        }
        fclose($h);
        return $flds;
}

When I generate a result table I'll go through the array like this:  ($so is
the shape Object)

                        foreach($flds as $fname => $fA){
                                $val = $so->values[$fname];
                                if ($val==null)$val="&nbsp";
                                $val = str_replace("  "," &nbsp;",$val);
                                if ($fA["type"]=="D"){$val =
substr($val,4,2)."-".substr($val,6,2)."-".substr($val,0,4);}
                                echo "<td>$val</td>";}
                }


Cheers to all,

Adam

> -----Original Message-----
> From: Abe Gillespie [mailto:agillesp at VT.EDU]
> Sent: Monday, December 06, 2004 5:14 PM
> To: MAPSERVER-USERS at LISTS.UMN.EDU
> Subject: Re: [UMN_MAPSERVER-USERS] Shapefile field problem
>
>
> It's a regular shapefile.  I think I've mostly narrowed it
> down.  It seems to me (though I may be completely off) that
> MapServer loads the first record of the DBF in order to get
> the field definitions.  If the first record has a string
> field and the value is zero length it won't give me the field
> (though the field count is always correct).  In addition, it
> won't give me any fields after that either.  If, however, I
> make sure that field has some value (a dash, an "x",
> whatever) then the field definition will come in correctly.
> I still haven't narrowed down a problematic number field
> though.  Mind you, this is all done in MapServer PHP v. 4.2.0.
>
> -Abe
>
> On Dec 6, 2004, at 6:15 PM, Daniel Morissette wrote:
>
> > Abe Gillespie wrote:
> >> A good amount of fields aren't showing up in MapServer for
> me.  I use
> >> the following PHP script to dump out all layers and their
> fields for
> >> debugging.  Does MapServer have problems with certain data
> types or
> >> certain values in a row?
> >>
> >
> > Are you using a tiled shapefile layer or is this a regular
> shapefile
> > layer?
> >
> > --
> > ------------------------------------------------------------
> >  Daniel Morissette               dmorissette at dmsolutions.ca
> >  DM Solutions Group              http://www.dmsolutions.ca/
> > ------------------------------------------------------------
> >
>



More information about the mapserver-users mailing list