A long time to render a white picture with PHP/Mapscript...

Philippe Gondek philippe.gondek at GMAIL.COM
Fri May 13 05:04:06 EDT 2005


Hi,

Here is my script :

<?php

//
//  Philippe GONDEK 
//
//  SCRIPT PHP QUI SE CONNECTE A UNE BASE POSTGRESQL AFIN DE RECUPERER
//  DONNEES SPATIALES POUR ENSUITE PERMETTRE A MAPSERVER DE CALCULER 
//  L'IMAGE QUE NOUS AFFICHERONS.
//

// PARAMETRES POUR LA CONNEXION AU SERVEUR POSTGRESQL

	dl('php_mapscript.so');

	$hote = "localhost";			//OK
	$base_de_donnees = "lemiam";		//OK
	$utilisateur = "phil";			//OK
	$mot_de_passe = "1707loulou442";	//OK
	$table_choisie = "regions";		//OK

// PARAMETRES POUR PhpMapScript

	$Path_Mapfile = "/var/www/localhost/htdocs/miam/";
	$Nom_Mapfile = "miam.map";
	//longueur de l'image a generer. La hauteur de l'image sera calculee 
	//selon la longueur
	$longueur_image_mapfile = "500";
	//chemin d'acces absolu vers le repertoire contenant l'image a generer
	$mapserver_imagepath = "/var/www/localhost/htdocs/miam/tmp/";
	//URL locale selon le chemin d'acces specifie pour l'image
	$mapserver_imageurl = "/miam/tmp/";
	//nom de la donnee attributaire a afficher
	//celle-ci correspond a une colonne dans la table choisie
	$mapserver_labelitem = "region";	//OK

// CONNEXIONS AU SERVEUR POSTGRESQL

	$db_handle = pg_Connect ("host=localhost port=5432 dbname=lemiam
user=phil password=1707loulou442");
	
	/*pg_connect("host="$hote 
				" dbname="$base_de_donnees 
			        " user="$utilisateur
				" password="$mot_de_passe);*/
	
	//selectionner le champ spatial associe a la table choisie
	$pgsql_colonne_spatiale = " 
		select f_geometry_column,type 
		from geometry_columns
		where f_table_name like '".$table_choisie."'";
	$pgsql_resultat = pg_exec($db_handle,$pgsql_colonne_spatiale);
	
	$colonne_spatiale = pg_result($pgsql_resultat,0,0);
	$type_donnee = pg_result($pgsql_resultat,0,1);
	
	$type_donnee_pour_mapserver = str_replace("LINESTRING",
		     MS_LAYER_LINE,
		     str_replace("MULTILINESTRING",
			  	  MS_LAYER_LINE,
				  str_replace("MULTIPOLYGON",
				  	       MS_LAYER_POLYGON,
					       pg_result($pgsql_resultat,0,1))));
				
	// Calcul de l'extent pour MapServer
	// et de la hauteur de l'image

	$pgsql_extent = "select 
				xmin(extent(".$colonne_spatiale.")),
				ymin(extent(".$colonne_spatiale.")),
				xmax(extent(".$colonne_spatiale.")),
				ymax(extent(".$colonne_spatiale.")) from 
				".$table_choisie;

	

	$resultat_extent = pg_exec($db_handle,$pgsql_extent);
	$xmin = pg_result($resultat_extent,0,0);
	$ymin = pg_result($resultat_extent,0,1);
	$xmax = pg_result($resultat_extent,0,2);
	$ymax = pg_result($resultat_extent,0,3);
	$longueur_extent = abs($xmax-$xmin);
	$hauteur_extent = abs($ymax-$ymin);
	$rapport_extent = $longueur_extent / $hauteur_extent;
	$hauteur_image_mapfile = $longueur_image_mapfile / $rapport_extent;

// CREATION DE LA MAP

$map = ms_newMapObj("miam.map");


//echo nl2br("\n ms_newMapObj :
$map->name");////////////////////////////////////////////////////////

$map->setextent($xmin,$ymin,$xmax,$ymax);
$map->web->set("imagepath",$mapserver_imagepath);
$map->web->set("imageurl",$mapserver_imageurl);
$map->set("width",$longueur_image_mapfile);
$map->set("height",$hauteur_image_mapfile);

	// Ajout d'une couche
	$layer = ms_newLayerObj($map);
        // Nom de la couche conforme a celui de la base de donnees
	$layer->set("name",$base_de_donnees);
        $layer->set("status",MS_ON);
        // Connexion a la base de donnees PostGIS
        $layer->set("connectiontype",MS_POSTGIS);
        $layer->set("connection","host=localhost port=5432
dbname=lemiam user=phil password=1707loulou442");
        // Requete spatiale utilisee
	$layer->set("data","the_geom from regions");
        // Precision sur le type de donnee spatiale a prendre en compte: 
	//LINE, POINT...
	$layer->set("type",$type_donnee_geometrique_pour_mapserver);
        // Nom de la colonne de donnees attributaires a afficher
        $layer->set("labelitem",$mapserver_labelitem);

        // Ajout de la class
        $class = ms_newClassObj($layer);
            // Ajout du Label
            $label = $class->label;
                // Precision sur l'affichage de la donnee de type attributaire
                // la couleur, la taille de la donnee ...
                $label->set("position",MS_CC);
                $label->color->setRGB(0,0,0);
                $label->outlinecolor->setRGB(255,255,255);
                $label->shadowcolor->setRGB(255,255,255);
                $label->backgroundcolor->setRGB(255,255,255);
                $label->backgroundshadowcolor->setRGB(255,255,255);
		// Ajout du style
		$style = ms_newStyleObj($class);
		// Precision sur l'affichage des donn?es spatiales
		// couleur de bourdure en code 128 0  0 pour RGB
		$style->set("size",4);
		$style->outlinecolor->setRGB(128,0,0);

		// Utilisation de PhpMapScript
		// pour generer l'image associee a la  mapfile au format PNG
		$image = $map->draw();
		$image_url = $image->saveWebImage(MS_PNG,1,1,0);

// Fermeture de la connexion a PostgreSQL
    pg_close($db_handle);

?>

<html>
<body>

<!-- AFFICHAGE DE L'IMAGE -->

<img src=<?php echo "'http://localhost".$image_url."' width='".$map->width.
	"px' height='".$map->height."px'";?>/>

</body>
</html>

I dont know why but the picture I render is white and it takes a long
time... Approximately 2 minutes... Is there a reason???



More information about the mapserver-users mailing list