[mapserver-users] Querying a dynamic layer

Jonathon Coombes jon at cybersite.com.au
Thu Sep 19 16:01:09 PDT 2002


Hi All,

i am relatively new to mapserver, and I have tried a number of ways to
solve this problem, but nothing seems to work. Here is the scenario:

I have a mapfile which defines a number of layers for cities, rivers
and water areas. These are standard shape files etc, and query fine.
I also create a dummy layer dynamically from data retrieved by sql
from a database. This returns the lat/longitude and some other data
relating to descriptions and numbers etc. It all seems to work fine,
but it does not query either by point or rectangle.

Here are the different approaches I have tried:

* Create the metadata directly using the setMetaData function.
* I have added the template line within the class, which I found was
  a necessary part of the query.
* I tried adding a labelitem.
* I created a shapefile using newShapeFileObj and adding data in.
* Set the data to the datafile name. (Creates the data files fine)

The basis of code is the standard GMap demo. It is running on a
Windows system (not my choice :) and PHP/Mapscript. Here is the
code I have to generate the data layer:

  // The query is run and it populates the sites[] array with
  // the data from the sql database.

  $dummy_layer = $gpoMap->getLayerByName('dummy');
  $dummyclass = ms_newClassObj($dummy_layer);
  $dummy_layer->set("labelitem", "NEAR_TOWN");
  $dummy_layer->set("template", "ttt.html");
  $dummy_layer->set("data","query");

  $figura = ms_newShapeObj(MS_SHAPE_LINE);
  $ponto_obj = ms_newLineObj();
  $numpoints = count($sites_1);
  for ($i=0; $i < $numpoints; $i++) {
     $point = ms_newPointObj();
     $point->setXY($sites[$i]['lon'],$sites[$i]['lat']);
     $ponto_obj->add($point);
     $figura->add($ponto_obj);
     $point->free();
  }

  // Create shape-file
  $shfile = ms_newShapefileObj("./data/query", MS_SHP_MULTIPOINT);
  $shfile->addShape($figura);
  $shfile->free();

  // Set all the necessary MetData for the points
  $dummy_layer->setMetaData("RESULT_FIELDS", "NEAR_TOWN NUMBER DATE");
  $dummy_layer->setMetaData("DESCRIPTION", "This is the Description");

  $dummy_layer = $gpoMap->getLayerByName("dummy");
  $dummy_layer->addFeature($figura);
  $dummy_layer->set("status", MS_ON);

My MAP file contains the following for the dummy layer:

LAYER
  NAME dummy

  TYPE POINT
  STATUS OFF
  CLASS
    NAME 'dummy'
    COLOR 255 0 0
    SYMBOL 'circle'
    SIZE 7
    TEMPLATE "ttt_query.html"
  END

  TOLERANCE 5

END

Also, is this the best way to do a dynamic layer? I want to be able
to create the dynamic layer and then use it for the session without
having to do the sql query every time the map is redrawn. Any better
way of doing this?

Any help here would be most appreciated.

Regards,
Jonathon




More information about the MapServer-users mailing list