No subject

Matthew Roberson matt at MSILEADS.COM
Thu Jul 7 16:56:35 EDT 2005


Hi,

I have a problem with some PHP/Mapscript.

I get am getting the following warning and error:


Warning: [MapServer Error]: msSaveImageGD(): Unable to open file / 
Library/WebServer/Documents/test/11207659884551.png for writing in / 
Library/WebServer/Documents/JW8020/machine.php on line 194

Fatal error: Failed writing image to /Library/WebServer/Documents/ 
test/11207659884551.png in /Library/WebServer/Documents/JW8020/ 
machine.php on line 194

The php and the map file are listed below:


//require('/Library/WebServer/Documents/fpdf.php');
//require('/Library/WebServer/Documents/create8020PDF.php');
ini_set("display_errors","1");
//$username = "sa";
$username = "admin";
//$password = "s1q2l3S1";
$password = "w3xp2BA5";
$hostName = "localhost";
$databaseName = "8020Machine";
$sQVal = "";
$jID8020 = 3;

function get8020CountPercent($val,
                              $iTotalVal)
{
       if($iTotalVal>0)
        {
            $dPercent=($val/$iTotalVal)*100;
            $dPercent = number_format($dPercent, 2, '.', '');
        }// ($iTotalVal>0)
        else
        {
            $dPercent = 0.0;
            //print "{$iTotalVal} is iTotalVal<br>";
        }// end if ($iTotalVal>0)

        return $dPercent;
}

function create8020OutputRecord($query,
                                 $zip_array,
                                 $adPercents)
{

      // Run the query on the server
      if (!($result = @ mysql_query ($query)))

      if ($result)
      {
          $jobID = mysql_insert_id();
      }

      //return $jobID;

} // end of function

mysql_connect ($hostName,$username,$password);
mysql_select_db($databaseName);


$address_query = mysql_query("select distinct ZipCode from  
eightytwentyinput where ZipCode <> '' and ZipCode is not NULL");
$address_rows = mysql_num_rows($address_query);

for($i=0; $i<$address_rows; $i++)
{
     $address_array = mysql_fetch_array($address_query);
     $temp_zip = $address_array['ZipCode'];
     $zip_array[$temp_zip] =0;
     $adPercents[$temp_zip]=0;
        $data[$i][0]=0;
        $data[$i][1]=0;
        $data[$i][2]=0;
}

$address_query2 = mysql_query("select ZipCode from eightytwentyinput  
where ZipCode <> '' and ZipCode is not NULL");
$address_rows2 = mysql_num_rows($address_query2);


for($i=0;$i<$address_rows2;$i++)
{
     $address_array2 = mysql_fetch_array($address_query2);
     $temp_zip2 = $address_array2['ZipCode'];
     $zip_array[$temp_zip2] += 1;


}

arsort($zip_array);
arsort($adPercents);

//mapserver stuff
dl("php_mapscript.so");

$map_file="/Library/WebServer/Documents/test/TX.map";
$map = ms_newMapObj($map_file);

$oZipLayer = $map->getLayerByName("TX Highlighted zip code boundaries");

$sAttrName = 'ZCTA';

//print_r($zip_array);
print("There are <strong>$address_rows</strong> total unique zip  
codes<BR>");

$iTotalVal = array_sum($zip_array);
$percent_num = $address_rows*.20;
$i=0;
print("<table border=\"1\"><tr><td class=\"bold\">Zip Code</td><td  
class=\"bold\">Count</td><td class=\"bold\">Percent</td></tr>");

while (list($key, $val) = each($zip_array))
{

    $i++;

    if($i <= $percent_num)
    {
        $dPercent = get8020CountPercent($val,$iTotalVal);
        $qry8020Output = mysql_query("INSERT INTO EightyTwentyOutput  
VALUES (NULL,'{$jID8020}','{$key}','{$val}','{$dPercent}')");
        create8020OutputRecord($qry8020Output, $zip_array, $adPercents);
        echo "<tr><td class=\"red\">$key</td><td class=\"red\">$val</ 
td><td class=\"red\">$dPercent</td></tr>";
        //pdf stuff
        $data[$i][0]=$key;
        $data[$i][1]=$val;
        $data[$i][2]=$dPercent;
        //mapserver stuff
        if(strlen($key)<=5)
        {
            if(strncmp($key, "77", 2)== 0)
            {
                //$qresult = @$oZipLayer->queryByAttributes 
($sAttrName,$key,MS_MULTIPLE);
                //var_dump($key);
                //$oZipLayerRed->set("labelitem", 'ZCTA');
                printf("%s %s\n",$i, $key);
                $sQVal=$sQVal.$key."|";
                $oZipClassRed = ms_newClassObj($oZipLayer);
                $oZipClassRed->setexpression($key);
                $oZipStyleRed = ms_newStyleObj($oZipClassRed);
                $oZipStyleRed->color->setRGB(255,0,0);

            }
        }
    } // ($i <= $percent_num)
    else
    {
        $dPercent = get8020CountPercent($val,$iTotalVal);
        $qry8020Output = mysql_query("INSERT INTO EightyTwentyOutput  
VALUES (NULL,'{$jID8020}','{$key}','{$val}','{$dPercent}')");
        create8020OutputRecord($qry8020Output, $zip_array, $adPercents);
        echo "<tr><td class=\"black\">$key</td><td class=\"black\"> 
$val</td><td class=\"black\">$dPercent</td></tr>";
        //pdf stuff
        $data[$i][0]=$key;
        $data[$i][1]=$val;
        $data[$i][2]=$dPercent;
        //mapserver stuff
        if(strlen($key)==5)
        {
            if(strncmp($key, "77", 2)== 0)
            {
                //$qresult = @$oZipLayer->queryByAttributes 
($sAttrName,$key,MS_MULTIPLE);
                //var_dump($key);
                //$oZipLayerBlue->set("labelitem", 'ZCTA');
                printf("%s %s\n",$i, $key);
                $sQVal=$sQVal.$key."|";
                $oZipClassBlue = ms_newClassObj($oZipLayer);
                $oZipClassBlue->setexpression($key);
                $oZipStyleBlue = ms_newStyleObj($oZipClassBlue);
                $oZipStyleBlue->color->setRGB(255,0,0);
            }
        }
    }// end if ($i <= $percent_num)
    $adPercents[$key] = $dPercent;
}// end while

print("</table>");



//more mapserver stuff
$sQVal = substr($sQVal, 0, strlen($sQVal)-1);

//Do query
$qresult = @$oZipLayer->queryByAttributes($sAttrName,"/". 
$sQVal."/",MS_MULTIPLE);

$image = $map->drawQuery();
$image_url = $image->saveWebImage();
$error = ms_GetErrorObj();
while($error && $error->code != MS_NOERR)
{
     printf("Error in %s: %s \n", $error-routine, $error->messaage);
     $error = $error->next();
}

?php echo $image_url?>">
<p>This is an unprojected map of the 5 digit zip code boundries for  
the state of Texas,
from the <a href="http://www.census.gov/geo/www/cob/z52000.html"> US  
Census Bureau</a>.</p>
<p>To find the categories for the legend, I used the <code>ogrinfo</ 
code> utility twice.
<code>ogrinfo -a -summary zt48_d00.shp</code> let me see what fields  
were available, and
<code>ogrinfo -a zt48_d00.shp|grep SYMBOL|sort -u</code> told me what  
all of the unique values were so that
I could build my <code>CLASS</code> definitions in <code>TX.map</code>.

?php
//print_r($oZipLayer);
print_r($qresult);
if ($oZipLayerRed->getNumResults() > 0)
     echo $oZipLayerRed->getNumResults()." zips found.";
else
     echo "No zips found."

?

--------------------------------------- map file  
-------------------------------

MAP
     NAME TX
     IMAGETYPE PNG
     SIZE 600 600
     IMAGECOLOR 255 255 255
     SHAPEPATH "/Library/WebServer/Documents/data"
     FONTSET "/Library/fonts/fonts.list"
     EXTENT -106.645646 25.837377 -93.516407 36.500704
     UNITS METERS
     WEB
         IMAGEPATH "/Library/WebServer/Documents/test/"
         IMAGEURL "/test/"
     END

     LEGEND
         STATUS EMBED
         POSITION UR
     END

     SCALEBAR
         TRANSPARENT ON
         BACKGROUNDCOLOR 0 0 0
         STATUS EMBED
         POSITION LR
         STYLE 1
     END
         LAYER
             NAME "TX zip code boundaries"
             TYPE POLYGON
             STATUS DEFAULT
             DATA "zt48_d00"
             CLASS
                 COLOR 255 255 255
                 OUTLINECOLOR 0 0 0
             END
             TEMPLATE "x"
         END

         LAYER
             NAME "TX Highlighted zip code boundaries"
             TYPE POLYGON
             STATUS DEFAULT
             DATA "zt48_d00R"
             CLASS
                 COLOR 255 255 255
                 OUTLINECOLOR 0 0 0
             END
             TEMPLATE "y"
         END

         LAYER
             NAME "credits"
             STATUS DEFAULT
             TRANSFORM FALSE
             TYPE ANNOTATION
             FEATURE
                 POINTS
                     10 480
                 END
                 TEXT 'Made with Mapserver.'
             END

             CLASS
                 LABEL
                     TYPE BITMAP
                     POSITION CR
                     COLOR 0 0 0
                 END
             END
         END
END

Is this error being caused by a problem in my PHP or MAP file, or is  
it perhaps something with
my apache configuration? I would appreciate any help anyone could  
offer in helping me find the source of this error.

Thanks,

Matt



More information about the mapserver-users mailing list