method to retrieve field types

Ryan, Adam ARyan at CO.LINN.OR.US
Mon Aug 16 15:06:06 EDT 2004


Mark,

This is kind of ugly but it spits back an array of information from the dbf
header file.


//      $f is a dbf file path, returns an array of field arrays
function dbf_fields($file){
        $h = fopen($file,"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++){
                $f = array();
                $fname = trim(fread($h,11));
                $f["type"] = fread($h,1);
                fread($h,4);
                $f = array_merge($f,unpack("Clen/Cpre",fread($h,2)));
                fread($h,14);
                $flds[$fname] = $f;
        }
        fclose($h);
        return $flds;
}

Hope it helps,

Adam

-----Original Message-----
From: Mark Adams [mailto:markadams at CUESTASYS.COM]
Sent: Monday, August 16, 2004 11:39 AM
To: MAPSERVER-USERS at LISTS.UMN.EDU
Subject: [UMN_MAPSERVER-USERS] method to retrieve field types


Hi all, is there a way with mapscript/mapserver to get the field types for
fields in a shape file? We can get the field names using PHP, and if we were
able to use PHP 5 we could get the types that way too, but since we're using
mapscript we can't use PHP 5. Any suggestions?

Thanks in advance.

------------------------------
Mark Adams
Business & Systems Analyst
Cuesta Systems Inc.
5230 South Service Road
Burlington, ON L7L 5K2
Phone: 905-333-4544 x14
Fax: 905-333-0455
Email: markadams at cuestasys.com



More information about the mapserver-users mailing list