User Tools

Site Tools


tecnica:gps_cartografia_gis:php_mapscript_recipes

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
tecnica:gps_cartografia_gis:php_mapscript_recipes [2010/02/26 19:28] niccolotecnica:gps_cartografia_gis:php_mapscript_recipes [2010/02/26 23:46] (current) niccolo
Line 77: Line 77:
 ===== Make a query ===== ===== Make a query =====
  
-Open an existing map file and perform a query-by-rectangle on a layer.+Open an existing map file and perform a **query by rectangle** on a layer, print results with a **template**.
  
 <code php> <code php>
 <?php <?php
- 
 $map = ms_newMapObj("/var/www/demo.map"); $map = ms_newMapObj("/var/www/demo.map");
- 
 $selrect = ms_newrectObj(); $selrect = ms_newrectObj();
 $selrect->setextent(1681023, 4850413, 1681906, 4851167); $selrect->setextent(1681023, 4850413, 1681906, 4851167);
Line 120: Line 118:
 <!-- MapServer Template --> <!-- MapServer Template -->
 <tr><td>[item name=objectid]</td><td>[item name=field1]</td><td>[item name=field2]</td></tr> <tr><td>[item name=objectid]</td><td>[item name=field1]</td><td>[item name=field2]</td></tr>
 +</code>
 +
 +This example does not use the template, it **iterates through the query results**:
 +
 +<code php>
 +<?php
 +$map = ms_newMapObj("/var/www/demo.map");
 +$selrect = ms_newrectObj();
 +$selrect->setextent(1681023.81515592, 4850413.68207817, 1681906.91185973, 4851167.76185515);
 +
 +$map->queryByRect($selrect);
 +$layer = $map->getLayerByName('layer_name');
 +$count = $layer->getNumResults();
 +
 +print "Query result count: " . $count . "<br>\n";
 +print "<pre>\n";
 +for ($i = 0; $i < $count; $i++) {
 +    $qRes = $layer->getResult($i);
 +    print_r($qRes);
 +}
 +print "</pre>\n";
 +?>
 </code> </code>
tecnica/gps_cartografia_gis/php_mapscript_recipes.1267208929.txt.gz · Last modified: 2010/02/26 19:28 by niccolo