[mapserver-users] RE: dynamically allocated points for MAP w/ PHP

E Perik erwin at perik.nu
Wed Apr 3 16:22:33 EST 2002


Hi Scott,

There is nothing wrong with the PHP code, except it does not create a
layer, but it creates a new shapefile ;-)

So you want to create a layer, dynamicly, or .....

Example of creating a layer from a shapefile:

0) Create map-object
1) Get object/points from existing-shapefile or from database
2) Put it in new-shapefile (as you did in your php-script)
3) Create dbf-file with name of new-shapefile
4) Clear new-shapefile (as you did)
5) Add new-layer to map-object (default of this layer is set to OFF)
6) Show new-layer (turn it ON)
7) Draw the map (now includes newly created shapefile ;-) )

Explanation:

*** In 0) you use like: $Map = ms_newMapObj("blabla.map");

*** In 1) you determine input. This could be the 3 points you have in
your example, but also could be a shape or lat/lon from a database (eg.
dbf/MySQL)

*** Option 2) and 3) and 4) you have in your mapscript. This creates a
shapefile + corresponding dbf-file.

*** Option 5) and 6) is best done using a dummy-layer which is set to
OFF in your map-file. You turn it on AND attach the new shapefile-data
from by using:
	$Dummylayer = ms_newLayerObj($Map);  // a new layerobject
	$Dummylayer = $Map->getLayerByName("MapLayer");  
	$Dummylayer->set("status", 1);	       // Turn it on 
	$Dummylayer->set("data", $shpFname);       // Add your created
data

	While your map-layer looks something like:

	LAYER
	  NAME "MapLayer"
	  TYPE POINT
	  STATUS OFF
	  CLASS
	    SYMBOL 'circle'
	    COLOR 0 0 0
	    SIZE 3
	  END
	END

*** Option 7) is something like:

$ImgMap = $Map->draw();

This should do the trick.

Erwin



-----Original Message-----
From: Scott D Cogan [mailto:cogansco at msu.edu] 
Sent: Wednesday, April 03, 2002 10:28 PM
To: Consult IT!, E. Perik; mapserver-users at lists.gis.umn.edu
Subject: dynamically allocated points for MAP w/ PHP

what is wrong with this PHP code?  i am trying to create a layer of
points
using mapscript.  i had this working previously, then somehow deleted
the
file.  now i cant figure it out again:

if ($init==1) {
// recreate the site layer
  $shpFname = "C:\\Program Files\\Apache\\htdocs\\mich\\data\\shptest";
  $shpFile = ms_newShapeFileObj($shpFname, MS_SHP_POINT);
  $def =  array(array("PROG_ID", "N", 5, 0));
  $dbfFile = dbase_create($shpFname . ".dbf", $def);
  createPoint( 14, 34, 111);
  createPoint( 33, 14, 222);
  createPoint( 10, 20, 333);
// done... cleanup
  $shpFile->free();
  dbase_close($dbfFile);
}


function createPoint($x, $y, $name){
    GLOBAL $shpFile, $dbfFile;
    // Create shape
    $oShp = ms_newShapeObj(MS_SHP_POINT);
    $oLine = ms_newLineObj();
    $oLine->addXY($x, $y);
    $oShp->add( $oLine );
    $shpFile->addShape($oShp);
    // Write attribute record
    dbase_add_record($dbfFile, array($name));
}




More information about the mapserver-users mailing list