[Mapserver-users] Getting Dbf Field Type

Eduin Yesid Carriillo yecarrillo@hotmail.com
Mon, 12 May 2003 11:16:12 -0500


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>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>$qLayer =3D=20
$gpoMap-&gt;getLayerByName($_REQUEST["Layer"]);<BR>$qLayer-&gt;open($gpoM=
ap-&gt;shapepath);<BR>$qFields=20
=3D $qLayer-&gt;getItems();<BR>$qLayer-&gt;close;</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>$dbfFile =3D=20
$gpoMap-&gt;shapepath."/".$qLayer-&gt;data.".dbf";<BR>if (!file_exists=20
($dbfFile)) {<BR>&nbsp; echo "No se ha encontrado el archivo=20
$dbfFile.\n";<BR>&nbsp; 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>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>for ($iField =3D 0; $iField &lt; =
sizeof($qFields);=20
$iField++) {</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp; $Lsup =3D $qRecords;<BR>&nbsp; =
if ($qRecords=20
&gt; 600) $Lsup =3D 600;<BR>&nbsp; $Records =3D array();<BR>&nbsp; for =
($i =3D 0; $i=20
&lt; $Lsup; $i++) {<BR>&nbsp;&nbsp;&nbsp; $oShape =3D =
$qLayer-&gt;getShape(-1,=20
$i);<BR>&nbsp;&nbsp;&nbsp; array_push($Records,=20
$oShape-&gt;values[$qFields[$iField]]);<BR>&nbsp; }<BR>&nbsp; natsort=20
($Records);<BR>&nbsp; $Records =3D&nbsp; array_unique =
($Records);<BR>&nbsp;=20
$Records =3D array_slice ($Records, 0, 300);<BR>&nbsp; $totalRec =3D=20
count($Records);</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</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
--&gt;second&lt;-- value and getting it's type:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp; if (!is_null($Records[1]) and=20
!is_numeric($Records[1])) {<BR>&nbsp;&nbsp;&nbsp; $quote =3D=20
"'";&nbsp;</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp; } else {<BR>&nbsp;&nbsp;&nbsp; =
$quote =3D=20
"";<BR>&nbsp; }</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</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&nbsp;field type =
of attibutes=20
table?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Thank You</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Eduin</FONT></DIV>
<DIV>&nbsp;</DIV></BODY></HTML>

------=_NextPart_000_0006_01C31877.E56D0D50--
_______________________________________________
Mapserver-users mailing list
Mapserver-users@lists.gis.umn.edu
http://lists.gis.umn.edu/mailman/listinfo/mapserver-users