[Mapserver-users] drawing lines with mapscript
blaise
bpicinbono at worldonline.fr
Wed Mar 31 00:29:53 PST 2004
hi jeff,
I hope that this will help. This is a php-function that draw a line
(according to several parameters). It is working fine with MS 3.6.2;
perhaps you have to make some changes for MS 4.0. Try to put your own
parameters and it should work fine.
Blaise
/****************************************************/
/* function line_save(tx,ty,layername,id,type,close,kt) */
/* make a line out of arrays tx and ty, */
/* if id=0->newid else id=id */
/* type : line=3, poly=5 if close, */
/* add the first point at the end */
/****************************************************/
function line_save($tx,$ty,$sln,$sid,$stype,$sclose,$kt)
{
$shapepath="/var/www/html/ms/data";
$numpoint=count($tx);
if ( (($numpoint>1) and ($stype==3)) or (($numpoint>2) and ($stype=="5")) )
{
$stmp="/$sln";
$lineshpFileName="$shapepath"."$stmp";
$lineshpFile = ms_newShapefileObj($lineshpFileName,-2);
$newShp = ms_newShapeObj(MS_SHP_ARC);
$aLine = ms_newLineObj();
for ($ipoint=0; $ipoint<$numpoint;$ipoint++)
{
$aLine->addXY($tx[$ipoint], $ty[$ipoint]);
}
if ($sclose==1)
{
$aLine->addXY($tx[0], $ty[0]);
}
$newShp->add($aLine);
$lineshpFile->addShape($newShp);
$aLine->free();
$newShp->free();
$dbFile = dbase_open($lineshpFileName,2);
if ($sid==0)
{
$idfn=$sln.".id";
$filename="$shapepath"."/$idfn";
$fp=fopen($filename,"r") or die ("not able to open $filename in read
mode");
$id=fgets($fp,1024);
fclose($fp);
$id=$id+1;
$fp=fopen($filename,"w") or die ("not able to open $filename in write
mode");
fwrite ($fp,$id);
fclose($fp);
$c[0]=$id;
}
else
{
$c[0]=$sid;
dbase_add_record($dbFile,$c);
dbase_close($dbFile);
$lineshpFile->free();
}
}
}
//***************** end line_save ***************************
More information about the MapServer-users
mailing list