[Mapserver-users] PHP/Mapscript: Searching for Attributes

Norbert Thieme norbert.thieme at ilmenau.baw.de
Thu Jun 10 08:20:00 EDT 2004


Frank Broniewski schrieb:
> Hello all
> 
> I'm still trying to find a way to search for attributes of a shapefile
> and center on the found locations or items. To be more precise, I will
> describe my data. I have a point shapefile with location names. Through
> a web interface, I want to enable the user to search for a location by
> name.
> The entry in my .map file for the point-shp is as followed:
> 
> LAYER
>     Name "Bezeichnung"
>     Data maps/toponyme
>     Status ON
>     Type Point
> 
>     LabelItem "toponyme"
>     ClassItem "Nature"
> 
>     CLASS
>       Name "Communes"
>       Expression "Commune"
>       Color 255 0 0
>       LABEL
>         Color 25 25 25
>         ShadowColor 225 225 225
>         ShadowSize 1 1
>         Type TRUETYPE
>         Font arial
>         Size 10
>         AntiAlias TRUE
>         Position CC
>         Partials FALSE
>       END
>     END
> END
> 
> 1) First thing is, I didn't enter a TEMPLATE expression, because I don't
> know how to enter it with the correct values. As my homepage is created
> dynamically like:
> 
> $image = $map->draw();
> $image_url = $image->saveWebImage();
> 
> When you enter a .html file as a parameter to TEMPLATE, how do I deal
> with this as I use a .php? Looking at the the gmap - demo, they use a
> nonexisting file as TEMPLATE parameter (ttt_query.html). But how can I
> use the values provided to the .html file?
> 
> 2) In my .php file I used the queryByAttribute method to query my layer.
> With the kind help of this list I managed to make it perform my query.
> But I'm not sure, if I used it correctly for my purpose. The code is as
> followed:
> 
>   $mySearchLayer = $MapObj->getLayerByName("Toponyme");
>   if (
> $mySearchLayer->queryByAttributes("TOPONYME","BERTRANGE","MS_SINGLE") ==
> "MS_SUCCESS" ) {
>     $myErgQuery = $MapObj->drawQuery();
>     $QueryImage = $myErgQuery->saveWebImage("MS_PNG",1,1,0);
>   } else {
>     $fehler = "Nicht gefunden";
>     echo $fehler;
>   }
> 
> It returns me, whatever searchparameter I enter, the whole map without
> marked points. The query thing is keeping me busy quite a few days now
> and I'm getting more and more confused. I did a search on the
> mailing-list archives but the few informations provided there just don't
> get me on the right path, as I seem to lack the ability to understand
> the methods like querybyattribute right.
> 
> Can some kind reader show me in a general manner how I can perform an
> attribute query on a shapefile and get some coordinate values returned?
> 
> Many thanks in advance
> 
>                                                       
> Frank Broniewski
> Musée National d'Histoire et d'Art
> Section Préhistoire / Projet EPC
>     Tél: +352 260 281-21
> 241, Rue de Luxembourg
> L-8077 Bertrange
> 
> 
> _______________________________________________
> Mapserver-users mailing list
> Mapserver-users at lists.gis.umn.edu
> http://lists.gis.umn.edu/mailman/listinfo/mapserver-users
> 
> 

Hi,

your querybyattributes seem fine on the first look.

TEMPLATE is a keyword in the mapfile that tells the mapserver that the 
layer can be queried. You can use some kind of dummy you don't need that 
to be a special file when using php.

For the hiliting you have to define it in your mapfile under querymap.
(http://mapserver.gis.umn.edu/doc40/mapfile-reference.html#querymap)

I don't know if this is a good way but you can use th following for the 
zooming and so on.
(http://mapserver.gis.umn.edu/doc40/phpmapscript-class-guide.html)

With layer->getnumresults you get the number of results and then you can 
loop through the resultcache and use $layer->getresult($i) to get each 
resultcachemember with shape- and tileindex.

Then you can use layer->open and then the getshape function to get a 
shapeobj with all items, values and a rectobj with coordinates.

With the coordinates you can make a new extent in the size you want.Then 
you have to get the map extent and save it somewhere then put the new 
extent to the map and then draw the query. After that you can set the 
normal extent back to your map.

Hope it helps,
Norbert



More information about the mapserver-users mailing list