[mapserver-users] ms_newLineObj()

Jean-François MONY jef.mony at free.fr
Wed Oct 31 03:33:16 EST 2001


I have a little problem with the ms_newLineObj() command.
As you can see below I create some points and the goal is to make a polygon 
with those points, then I create a line.
With the print_r function I'm sure that the points are well created, but I 
can't create the line and I don't understand why.
If somebody have an idea.
I use mapserver 3.5 (nightly build from the begining of september) with php 
4.05.


Thanks, Jef



CODE
=====

<?
session_start();

require("../config.php");

function split_string($sql, $delimiter)
{
  $sql = trim($sql);
  $buffer = array();
  $ret = array();
  $in_string = false;
  for($i=0; $i<strlen($sql); $i++)
  {
    if($sql[$i] == $delimiter && !$in_string)
    {
      $ret[] = substr($sql, 0, $i);
      $sql = substr($sql, $i + 1);
      $i = 0;
    }
    if($in_string && ($sql[$i] == $in_string) && $buffer[0] != "\\")
    {
      $in_string = false;
    }
    elseif(!$in_string && ($sql[$i] == "\"" || $sql[$i] == "'") && $buffer[0] !
= "\\")
    {
      $in_string = $sql[$i];
    }
    $buffer[0] = $buffer[1];
    $buffer[1] = $sql[$i];
  }
  if (!empty($sql))
  {
    $ret[] = $sql;
  }
  return($ret);
}

$polyarray=split_string($poly, ";");

print("$poly<br>");
$ligne = ms_newLineObj();
for ($i=1; $i<$polyarray[0]+1;$i++)
{
  $j=2*$i-1;
  $k=2*$i;
  $point=ms_newPointObj();
  $point->setXY($polyarray[$j], $polyarray[$k]);
  print_r($point);
  print("<br>");
  $ligne->add($point);
  print_r($ligne);
  print("<br>");
}
$shape = ms_newShapeObj(MS_SHAPE_POLYGON);
$shape->add($ligne);
  print_r($shape);
  print("<br>");
?>


RESULT
=======

4;907249;2505661;909472;2486354;934669;2483012;919847;2504547;
point Object ( [_handle_] => Resource id #2 [x] => 907249 [y] => 2505661 ) 
line Object ( [_handle_] => Resource id #1 [numpoints] => 0 ) 
point Object ( [_handle_] => Resource id #3 [x] => 909472 [y] => 2486354 ) 
line Object ( [_handle_] => Resource id #1 [numpoints] => 0 ) 
point Object ( [_handle_] => Resource id #4 [x] => 934669 [y] => 2483012 ) 
line Object ( [_handle_] => Resource id #1 [numpoints] => 0 ) 
point Object ( [_handle_] => Resource id #5 [x] => 919847 [y] => 2504547 ) 
line Object ( [_handle_] => Resource id #1 [numpoints] => 0 ) 
shape Object ( [_handle_] => Resource id #6 [numlines] => 0 [type] => 2 [index] 
=> -1 [tileindex] => -1 [classindex] => 0 [numvalues] => 0 [text] => [bounds] 
=> rect Object ( [_handle_] => Resource id #7 [minx] => -1 [miny] => -1 [maxx] 
=> -1 [maxy] => -1 ) ) 



More information about the mapserver-users mailing list