mapscript new functionality

Daniel Morissette morissette at dmsolutions.on.ca
Fri Nov 3 10:27:06 EST 2000


> >>> <peter.jacobs at javel.nl> 11/03/00 05:34 AM >>>
> 
> New functionlity that we need are
> --> To implement the delete method in many of the obects in the mapscript
> and php_mapscript  (self constructed layers, shapes, etc. must be deleted)
> 
> Does anyone have a sugestion how to handle this. Do other people need this
> functionality as well? Is this a good suggestion for the official versions
> of mapscript and php_mapscript.
> 

Peter,

I have to admit that the best way to delete objects during script
execution in PHP is still a bit of a mystery for me.  However, I have
verified that all objects are properly destroyed at the end of the
execution of a script, so PHP MapScript should not leak any memory in
theory.  (But it's possible that it may leak some memory and we'll try
to fix any leak someone may find)

However, if you create lots of objects during your script execution,
like shapes, lines, etc. then you might want to free them right away and
not wait for the cleanup at the end of the PHP script execution.  Some
classes have a free() method that releases memory used by the object...
hopefully it does the right thing but this is a poorly documented part
of PHP so I'm not 100% sure.

Only a few classes used to have a free() method in previous versions of
PHP MapScript, but the current CVS version (from 2 days ago) has free()
methods on all the classes where it makes sense.


> Another issue we want to deal with is the possibility to port major parts
> of the mapscript into Java. With the growing usage of enterprise java
> beans, we are planning to start such a conversion. Are there people who
> agree on this conversion? Are there people interested in joining this?
> 

We would also be interested in seeing how SWIG-based Java MapScript
would behave... if you do anything on that front then please keep us
posted.

> I still have one php_mapscript question
> After I query a point and get the shape integer, what is the best way to
> get the relating dbf values on screen.
> 

You have to use the PHP "dbase" module.  It is not linked in by default
on Unix so you may have to recompile your PHP using --with-dbase.  On
Windows a PHP3_DBASE.DLL usually comes with the PHP distribution.

An important note is that MapScript returns 0-based shape indices, but
the dbase module expects 1-based record numbers.  So you have to use
$oResult->shape+1 as the DBF record index.

I attached below the function GMapDumpQueryResults() from our GMap demo
that outputs a HTML table with sub-sections for each layer that contains
results.  Of course if you query only one layer then you don't need
something that complicated.

-- 
------------------------------------------------------------
 Daniel Morissette             morissette at dmsolutions.on.ca
               http://www.dmsolutions.on.ca/
------------------------------------------------------------
  Don't put for tomorrow what you can do today, because if 
      you enjoy it today you can do it again tomorrow.


function GMapDumpQueryResults()
{
    GLOBAL $gpoMap, $gpoQueryResults;

    if (! $gpoQueryResults )
    {
        printf("&nbsp;");
        return;
    }

    printf("<TABLE>\n");

//    printf("NumResults = %d, NumQueryLayers = %d\n", 
//           $gpoQueryResults->numresults,
$gpoQueryResults->numquerylayers);

    $iCurLayer = -1;
    $aFields = "";

    $gpoQueryResults->rewind();

    for($iRes=0; $iRes < $gpoQueryResults->numresults; $iRes++)
    {
        $oResult = $gpoQueryResults->next();

        if ($oResult->layer == -1)
            break;

        if ($iCurLayer != $oResult->layer)
        {
	    $iCurLayer = $oResult->layer;
            $oLayer = $gpoMap->GetLayer($iCurLayer);
            $dbfname = $gpoMap->shapepath . "/". $oLayer->data . ".dbf";

            if ($db)
                dbase_close($db);
            $db = dbase_open($dbfname, 0);

// We use the LAYER HEADER parameter to store the list of field names
// to display for each layer.  (small hack!)
            $selFields = explode(" ", $oLayer->header);
	    
	    if ($iCurLayer != -1)
		printf("</TABLE>\n");

	    printf("<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=2
WIDTH=100%%>\n");
	    printf("<TR>\n");
	    printf("<TD COLSPAN=%d BGCOLOR=#C1D8E3>", sizeof($selFields));
	    printf("<CENTER> %s </CENTER>", $oLayer->description);
	    printf("</TR>\n");
	    
/* --------------------------------------------------------------------
*/
/*      name of the attributes.                                        
*/
/* --------------------------------------------------------------------
*/
	    printf("<TR>\n");	
	    for ($iField=0; $iField < sizeof($selFields); $iField++)
	    {
		printf("<TD BGCOLOR=#E2EFF5>");
		printf("%s",$selFields[$iField]);
		printf("</TD>");
	    }
	    printf("</TR>\n");	
	    
        }
	
	
        $rec = dbase_get_record_with_names($db, $oResult->shape+1);

	printf("<TR>\n");	
	    
        for($iField=0; $iField < sizeof($selFields); $iField++)
        {
	    printf("<TD BGCOLOR=#FFFFFF>");
            printf("%s",trim($rec[strtoupper($selFields[$iField])]));
	    printf("</TD>");
        }
	printf("</TR>\n");	
    }

    if ($db)
        dbase_close($db);

    printf("</TABLE>\n");
}




More information about the mapserver-users mailing list