Query by Point with php mapscript
Un piccolo script per eseguire le query puntuali con PHP/Mapscript
Lo script riceve alcuni parametri via GET e legge due variabili (il mapfile e il nome dell’estensione mapscript da un file di configurazione), può essere facilmente modificato per adattarlo ad altre esigenze.
Il codice javascript serve a impostare i valori di x e y in un form che ha aperto il webgis
< ?php
/**
* Query by point
*/
require_once 'config.php';
// Warning: this override system locale (here it_IT) and avoids ugly DOUBLE errors
setlocale(LC_NUMERIC,'en');
$mapfile = $aszMapFiles[$_REQUEST['map']][1];
if (!extension_loaded('MapScript'))
{
dl( $szPHPMapScriptModule );
}
$formfield = $_REQUEST['formfield'];
$x = floatval($_REQUEST['mX']);
$y = floatval($_REQUEST['mY']);
$point = ms_newPointObj();
$point->setXY($x, $y);
$map = ms_newMapObj($mapfile);
$numlayers = $map->numlayers;
$html = '';
$results = array();
for($i = 0; $i < $numlayers; $i++){
$layer = $map->getLayer( $i );
if($layer->type == MS_LAYER_POINT){
//echo 'Querying ' . $layer->name . "
";
if(@$layer->queryByPoint($point, MS_MULTIPLE, -1) == MS_SUCCESS){
// get the number of results
$layer->open();
$numresults = intval($layer->getNumResults());
if($numresults){
// meta data
$glayer = $layer->getMetaData('DBTABLE');
$layerdesc = $layer->getMetaData('DESCRIPTION');
$html .= '
' ."\n";
$html .= '
' ."\n";
}
// add element to results array for each result row
for ($j=0; $j < $numresults; $j++)
{
// get next shape row
$result = $layer->getResult($j);
$shape = $layer->getShape($result->tileindex, $result->shapeindex);
// push the row array onto the results array
$aTmp = $shape->values;
$aTmp = array_merge( $aTmp ,
array('x' => $shape->bounds->minx,'y' => $shape->bounds->miny, 'glayer' => $glayer, 'layerdesc'=>$layerdesc));
array_push( $results, $aTmp );
$html .= "
" ."\n";
// end for loop
}
$layer->close();
}
}
}
$html = "
| Posizione cliccata | $x | $y |
' ."\n";
$html = < <
$html
EOT;
echo $html;
?>



