[mapguide-users] RE: question Postgre Search tools php

MapasCatastro mapas at laplata.gov.ar
Tue May 8 15:23:21 EDT 2007


hi thks jason

i try to create a search tool, my script works this mode

1)my form pass a variables
2) consult this variables in posgres
3) this query result my filter

but dont work, showme this

'3912' is the echo from my filter

The specified object was not found.The specified object was not found.
Exception occurred in method GetItem at line 115 in file
.\Data\NamedCollection

this is my code:

///////////////

<style type="text/css">
<!--
body {
	background-color: #EBEBEB;
}
-->
</style>
<?php 

include 'appconstants.php';
include 'utilityfunctions.php';
$mapUpdated = false;
$mgSessionId = ($_SERVER['REQUEST_METHOD'] == "POST")? $_POST['SESSION']:
$_GET['SESSION'];
echo '<input type="hidden" name="SESSION" value="' . $mgSessionId . '">';


/////////////////////////////////////////////////////////
//////////////// Buscador por Alturas /////////
/////////////////////////////////////////////////////////

// Obtiene las Variables
$calle3 = $_GET['Calle3'];
$altura = $_GET['altura'];
$calle3 = strtoupper ($calle3);
$calle3=str_ireplace(' ','%',$calle3); 	
$calle3=trim($calle3);
// Nombre de la tabla de calles usada en la busqueda 
$tablacalle = "callesnodos";

// Comienza el html y el form
echo '<br>Buscar Calles por Altura (Test)<br>'; 
echo '<form action="buscaraltura.php" method="get" name="dos"
target="_self">';
echo 'Calle:<br>';
/////////
$mgSessionId = ($_SERVER['REQUEST_METHOD'] == "POST")? $_POST['SESSION']:
$_GET['SESSION'];
echo '<input type="hidden" name="SESSION" value="' . $mgSessionId . '">';

// Pone unas calles por defecto y deja las de la anterior busqueda
if ($calle3 == '')
{
echo '<input name="Calle3" type="text" value="mitre"/>';
}
else
{
echo '<input name="Calle3" type="text" value="' .$calle3. '"/>';
}
echo '<br>Altura:<br>';
if ($altura == '')
{
echo '<input name="altura" type="text" value="1234" />';
}
else
{
echo '<input name="altura" type="text" value="' .$altura. '" />';
}
echo "<br>";
echo '<input name="Aceptar2" type="submit" value="Buscar" />'; 
echo "</p>";
echo "</form>";

?>
<?php 
$mgSessionId = ($_SERVER['REQUEST_METHOD'] == "POST")? $_POST['SESSION']:
$_GET['SESSION'];
echo '<input type="hidden" name="SESSION" value="' . $mgSessionId . '">';

//////////////////////////////////////////////////////////////
/////////////// Hace la query /////////////////////////
//////////////////////////////////////////////////////////////
$queryalt = "select clave, nombreoriginal, alturas, desde_par, hasta_par
from " .$tablacalle. " where ( nombre like '%" .$calle3. "%' ) and (("
.$altura. " between desde_par and hasta_par) or ( " .$altura. " between
desde_impar and hasta_impar))";

// Conexion, seleccion de base de datos
$conexion_bd = pg_connect("host=localhost dbname=GIS user=admin
password=admin") or die('No pudo conectarse: ' . pg_last_error());





if ($calle3 != '' ) 
{ 	
	// Realizar una consulta SQL
	$consulta = $queryalt;
	
	// Ejecuta la query
	$resultado = pg_query($consulta) or die ('Consulta fallida: ' .
pg_last_error());
 
	// Impresion de resultados en HTML
//	echo "<br>TEST de Calles encontradas:<br>" ;
//	echo '<table border="5"><br>';

	$i=0;
	$j=0;
	$k=0;
	while ($linea = pg_fetch_array($resultado, null, PGSQL_ASSOC)) {
		$booleano = 'a';    	
    	//echo "\t<tr>\n";
    	foreach ($linea as $valor_col) {
    	   if($booleano=='a'){
    	   	$booleano='b';
    	   	$NODITO[$i] = $valor_col;
    	   	$i++;
			//echo "\t\t<td> $valor_col </td>\n";
			}
			elseif ($booleano=='b'){	
				$booleano='c';
    	   		$CALLECITA[$j] = $valor_col;
    	   		$j++;
		//		echo "\t\t<td> $valor_col </td>\n";
			} 
			elseif ($booleano=='c'){	
				$booleano='d';
    	   		$ALTURITA[$k] = $valor_col;
    	   		$j++;
		//		echo "\t\t<td> $valor_col </td>\n";
			} 
			else{		
			//	echo "\t\t<td> $valor_col </td>\n";
			}    	   	    	   
    	}
    //	echo "\t</tr>\n";
	}
	//echo "</table>\n";
			for($c = 0; $c < $i; $c++){
			//		echo $NODITO[$c]. ' y ' .$CALLECITA[$c]. '<br>';
					obtenerxyalt($NODITO[$c], $CALLECITA[$c], $ALTURITA[$c]);
			}	
  }
/////////////////////
///arranca mapguide//
/////////////////////
/// $nodito = idcalles
/////////////////////


function obtenerxyalt($NODITO,$CALLECITA,$ALTURITA  ){
    try
    {
         $mgSessionId = ($_SERVER['REQUEST_METHOD'] == "POST")?
$_POST['SESSION']: $_GET['SESSION'];
        $userInfo = new MgUserInformation($mgSessionId);
        $siteConnection = new MgSiteConnection();
        $siteConnection->Open($userInfo);

        $resourceService =
$siteConnection->CreateService(MgServiceType::ResourceService);
        $featureService =
$siteConnection->CreateService(MgServiceType::FeatureService);

        $map = new MgMap();
        
        $map->Open($resourceService, 'quilmes');

        $key = trim($NODITO);
		//echo "<br>el key es: " .$key. "<br>"; 
		
        if (strlen($key) > 0)
        {
           $filter = "clave = '" . $key. "'" ;
		  
           echo "el filter es " .$filter. "<br>" ; 
            $featureResId = new
MgResourceIdentifier("Library://quilmes/postgre/conectancia.FeatureSource");
            $queryOptions = new MgFeatureQueryOptions();
            $queryOptions->SetFilter($filter);

            $geometryReaderWriter = new MgAgfReaderWriter();

            $featureReader = $featureService->SelectFeatures($featureResId,
"OGRSchema:callesnodos", $queryOptions);

            $featureReader->ReadNext();
            
	    $name = $featureReader->GetString('clave');
            $byteReader = $featureReader->GetGeometry('the_geom');

            $geometry = $geometryReaderWriter->Read($byteReader);
            $point = $geometry->GetCentroid();
            $x = $point->GetCoordinate()->GetX();
            $y = $point->GetCoordinate()->GetY();
			//echo "x= " .$x. " Y= " .$y;
            
			// Add a row to the hyperlink table for this parcel.
            echo '<td class="NavItem">';
            echo ' images/flecha.png ';
echo "</td><td> \"gotopoint.php?X=$x&Y=$y&Scale=1300\" " .$CALLECITA. "-"
.$ALTURITA. "<br> </td>";

            $featureReader->Close();

        }
    }
    catch (MgException $e)
    {
        echo $filter;
        echo $e->GetMessage();
        echo $e->GetDetails();
    }

}
?>


///////////////////////////////





JasonBirch wrote:
> 
> Hi oscar,
> 
> What do you mean it doesn't work?
> 
> Do you have it wrapped in a try/catch ?  Is it reporting any errors?
> 
> Does it work when you don't pass a filter?
> 
> Jason 
> 
> -----Original Message-----
> From: MapasCatastro
> Subject: [mapguide-users] question Postgre Search tools php
> 
> hi i try to modify the part of this script in php  but dont workme, i
> try to create a search tool.
> 
> its ok this code to read from postgre??
> _______________________________________________
> mapguide-users mailing list
> mapguide-users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/mapguide-users
> 
> 

-- 
View this message in context: http://www.nabble.com/question-Postgre-Search-tools-php-tf3711540s16610.html#a10382306
Sent from the MapGuide Users mailing list archive at Nabble.com.



More information about the mapguide-users mailing list