[Mapserver-users] Getting Dbf Field Type
Eduin Yesid Carriillo
yecarrillo at hotmail.com
Mon May 12 09:16:12 PDT 2003
This is a multi-part message in MIME format.
------=_NextPart_000_0006_01C31877.E56D0D50
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
I develop my own Query Builder with Javascript/Php.
$qLayer =3D $gpoMap->getLayerByName($_REQUEST["Layer"]);
$qLayer->open($gpoMap->shapepath);
$qFields =3D $qLayer->getItems();
$qLayer->close;
$dbfFile =3D $gpoMap->shapepath."/".$qLayer->data.".dbf";
if (!file_exists ($dbfFile)) {
echo "No se ha encontrado el archivo $dbfFile.\n";
exit;
}
$Dbfid =3D dbase_open ($dbfFile, 0);
$qRecords =3D dbase_numrecords ($Dbfid);
dbase_close ($Dbfid);
for ($iField =3D 0; $iField < sizeof($qFields); $iField++) {
$Lsup =3D $qRecords;
if ($qRecords > 600) $Lsup =3D 600;
$Records =3D array();
for ($i =3D 0; $i < $Lsup; $i++) {
$oShape =3D $qLayer->getShape(-1, $i);
array_push($Records, $oShape->values[$qFields[$iField]]);
}
natsort ($Records);
$Records =3D array_unique ($Records);
$Records =3D array_slice ($Records, 0, 300);
$totalRec =3D count($Records);
It works fine, but I need to know the field type to enclose the field =
name and field value with ' when the field type is "string".
My first solution was reading the -->second<-- value and getting it's =
type:
if (!is_null($Records[1]) and !is_numeric($Records[1])) {
$quote =3D "'";=20
} else {
$quote =3D "";
}
But sometimes, numeric values are stored as strings.=20
Can MapScript read the field type of attibutes table?
Thank You
Eduin
------=_NextPart_000_0006_01C31877.E56D0D50
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2600.0" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>I develop my own Query Builder with=20
Javascript/Php.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>$qLayer =3D=20
$gpoMap->getLayerByName($_REQUEST["Layer"]);<BR>$qLayer->open($gpoM=
ap->shapepath);<BR>$qFields=20
=3D $qLayer->getItems();<BR>$qLayer->close;</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2>$dbfFile =3D=20
$gpoMap->shapepath."/".$qLayer->data.".dbf";<BR>if (!file_exists=20
($dbfFile)) {<BR> echo "No se ha encontrado el archivo=20
$dbfFile.\n";<BR> exit;<BR>}<BR>$Dbfid =3D dbase_open ($dbfFile,=20
0);<BR>$qRecords =3D dbase_numrecords ($Dbfid);<BR>dbase_close=20
($Dbfid);<BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>for ($iField =3D 0; $iField < =
sizeof($qFields);=20
$iField++) {</FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=3DArial size=3D2> $Lsup =3D $qRecords;<BR> =
if ($qRecords=20
> 600) $Lsup =3D 600;<BR> $Records =3D array();<BR> for =
($i =3D 0; $i=20
< $Lsup; $i++) {<BR> $oShape =3D =
$qLayer->getShape(-1,=20
$i);<BR> array_push($Records,=20
$oShape->values[$qFields[$iField]]);<BR> }<BR> natsort=20
($Records);<BR> $Records =3D array_unique =
($Records);<BR> =20
$Records =3D array_slice ($Records, 0, 300);<BR> $totalRec =3D=20
count($Records);</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>It works fine, but I need to know the =
field type to=20
enclose the field name and field value with ' when the field type is=20
"string".</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>My first solution was reading the=20
-->second<-- value and getting it's type:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2> if (!is_null($Records[1]) and=20
!is_numeric($Records[1])) {<BR> $quote =3D=20
"'"; </FONT></DIV>
<DIV><FONT face=3DArial size=3D2> } else {<BR> =
$quote =3D=20
"";<BR> }</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>But sometimes, numeric values are =
stored as=20
strings. </FONT></DIV>
<DIV><FONT face=3DArial size=3D2>Can MapScript read the field type =
of attibutes=20
table?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Thank You</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT> </DIV>
<DIV><FONT face=3DArial size=3D2>Eduin</FONT></DIV>
<DIV> </DIV></BODY></HTML>
------=_NextPart_000_0006_01C31877.E56D0D50--
More information about the MapServer-users
mailing list