PHP MapScript queries

Stephen Lime steve.lime at dnr.state.mn.us
Thu Feb 1 17:16:23 EST 2001


Here's a perl sample that does a rectangle query on a layer. I assume the PHP/MapScript
code would look *very* similar. Note that this will get easier in the upcoming release since
result objects are gone and the results of a query are part of a layer.

#
# This function uses an arbitrary rectangle object to query against
# a USGS map series (e.g. 24k, 100k, or 250k) to compile a list of
# all maps that cover a certain area. Once the query is done the results
# are stepped through and a field from the shapefile .dbf file is extracted
# for each matching record.
#
# (taken from drgs.pl - http://maps.dnr.state.mn.us/tomo/)
#
sub maplist() {
  my($extent, $layername) = @_;

  my $map = new mapObj($searchmap) or &error('Unable to load $searchmap.');

  my $layer = $map->getLayerByName($layername) or &error("Layer $layername not found in $searchmap.");
  $layer->{status} = $mapscript::MS_ON;

  my $results = $layer->queryUsingRect($map, $extent) or &error('Query failed.');

  my $table = '';
  my @list = '';
  for(my $i=0; $i<$results->{numresults}; $i++) {
    my $data = $results->next();
    
    if(!$table) {
      $table = new XBase $map->{shapepath}.'/'.$layer->{data}.'.dbf' or &error(XBase->errstr);
    }
    
    (my $deleted, $list[$i]) = $table->get_record($data->{shape}, 'TILE_NAME');
  }

  $table->close();
  $results->free();
  undef $map;

  return(join(', ', @list));
}

Hope this helps.

Steve

Stephen Lime
Internet Applications Analyst

Minnesota DNR
500 Lafayette Road
St. Paul, MN 55155
651-297-2937

>>> Thorsten Fischer <frosch at cs.tu-berlin.de> 02/01/01 04:06PM >>>

Maybe I should clarify my question: I already have a 
rectObj, and I got a mapObj with a layer and a shapefile loaded.

What do I have to build into the map file and/or my php mapscript to
get hold on a queryResultObj that answers the question: what shapes are 
visible in that rectangle?

I am quite clueless at that point right now, and I know there must
be a - simple? - way to make it work.


Thorsten





More information about the mapserver-users mailing list