[Mapserver-users] Which is better: PHPMapScript query engine or PHP dBase functions?

Ryan, Adam ARyan at co.linn.or.us
Wed May 5 09:02:39 PDT 2004


Norbert writes...

>//this first part is a separate form but it should work also in one
>
>$recs = dbase_numrecords($dbi);//opened dbf
>
>$q_index_array = array();//save the indexes from the .dbf in this array
>
>for ($i = 1; $i < $recs; $i++)
>{
>   $s_field = dbase_get_record_with_names($dbi, ($i + 1));
>
>   if (!(strpos(strtolower($s_field[$qitem]), strtolower($qstring))) === 
>false))
>   {
>     $q_index_array[] = $i;
>   }
>}

This is too slow and limited.  You should try the ODBC functions in PHP.
You can run SQL queries on a dbf file by regarding the directory in which
the file resides as the database.  This gives you all the flexibility of SQL
statements. 

>for ($i = 0; $i < count($q_index_array); $i++)
>{
>   if (@$map->queryByIndex($qlayer->index, 0, $q_index_array[$i], 
>MS_FALSE) == MS_SUCCESS)
>   {
>     $q_img  = $map->drawquery();
>     $q_path = $q_img->savewebimage();
>     echo "<img src=".$q_path.">";
>   }
>}

I'm not sure I get this code.  Seems like your stepping through a list of
index numbers, setting them with queryByIndex, but then drawing the map
after every index?  I don't get it.  The map should be drawn after iterating
through the whole array, no?  

Anyway, I think the two routines above are flawed in that the index values
in the shapefile and in the dBase file and not be assumed to be equal.  If
I'm wrong about this I hope someone will correct me.  They usually are the
same, but the whole point of the *.shx file is to reconcile differences in
the indexing.  So you're taking the indexing from the dBase and applying
this to the shapefile and I think on careful examination on some of larger
file sets you'll find that what you're displaying textually and graphically
don't match.

By the way, I've found that queryByIndex is way too slow.  It works fine for
a small set of records, but with large selection sets I've found it's too
slow.  I use save and load query as much as I can.

Adam


-----Original Message-----
From: Norbert Thieme [mailto:norbert.thieme at ilmenau.baw.de] 
Sent: Tuesday, May 04, 2004 1:20 AM
To: Ryan, Adam; eduardo at consultoria.eti.br
Cc: mapserver-users at lists.gis.umn.edu
Subject: Re: [Mapserver-users] Which is better: PHPMapScript query engine or
PHP dBase functions?


Ryan, Adam schrieb:
> Eduardo,
> 
> I might be off track but...
> 
> I thought about this myself.  In order to display the result shapes 
> you need to have a query result either from doing the query in 
> mapscript or loading a saved query file.  The former defeats the point 
> of querying the dBase since you're duplicating your steps, and the 
> later requires you to manually build a query file but you can't do 
> that unless you can get at the dBase record - shapefile index 
> relationship which I don't know how to do.
> 
> Again, I may be off track, but querying the dBase file may not be 
> feasible.
> 
> Adam
> 
> -----Original Message-----
> From: Eduardo Patto Kanegae [mailto:eduardo at consultoria.eti.br]
> Sent: Monday, May 03, 2004 11:06 AM
> To: mapserver-users at lists.gis.umn.edu
> Subject: [Mapserver-users] Which is better: PHPMapScript query engine or
PHP
> dBase functions?
> 
> 
> I have a mapserver+php+mapscript that will query on a shapefile 
> database on a single layer, through its atributes.
> 
> The system will give as result a set of items on a result list as a 
> first step. Then as a second step a map displaying these results 
> should be given.
> 
> my doubt is: to create this result list which will be best strategy:
> - use PHPMapScript to query against the mapfile ?
> or
> - simply use PHP dBase functions to query against dBase files of the
> mapfile?
> 
> which one is the best/fastest alternative?
> 
> best regards.
> 
> Eduardo Patto Kanegae
> http://www.consultoria.eti.br
> UIN: 303747254
> 
> I Encontro Nacional de Usuários MapServer - 
> http://mapserver.cttmar.univali.br/encontro2004
> Projeto MapServer Brasil - http://mapserver.cttmar.univali.br
> 
> ***Fim da Mensagem / End of Message ***
> 
> 
> 
> 
> _______________________________________________
> Mapserver-users mailing list Mapserver-users at lists.gis.umn.edu
> http://lists.gis.umn.edu/mailman/listinfo/mapserver-users
> 
> _______________________________________________
> Mapserver-users mailing list Mapserver-users at lists.gis.umn.edu
> http://lists.gis.umn.edu/mailman/listinfo/mapserver-users
> 
> 


Hi,

I think you can use both. If you use querybyattributes then you use the 
ability of the mapserver to search only in your current extent. But you 
have the problem that the qstring must be exactly the same (case 
sensitive). If anyone knows a way (without much own code) to search with 
the mapserver after only parts of words and case ignoring it would be 
great if he shares it. Because that would work with all kinds of types 
of data not only for shapes.

For the other case I use the following code to search the way described 
above - I cut it a bit:

//this first part is a seperate form but it should work also in one

$recs = dbase_numrecords($dbi);//opened dbf

$q_index_array = array();//save the indexes from the .dbf in this array

for ($i = 1; $i < $recs; $i++)
{
   $s_field = dbase_get_record_with_names($dbi, ($i + 1));

   if (!(strpos(strtolower($s_field[$qitem]), strtolower($qstring))) === 
false))
   {
     $q_index_array[] = $i;
   }
}

//second part - map

for ($i = 0; $i < count($q_index_array); $i++)
{
   if (@$map->queryByIndex($qlayer->index, 0, $q_index_array[$i], 
MS_FALSE) == MS_SUCCESS)
   {
     $q_img  = $map->drawquery();
     $q_path = $q_img->savewebimage();
     echo "<img src=".$q_path.">";
   }
}

Regards,
Norbert



More information about the MapServer-users mailing list