Add polygon in shapefile

blaise bpicinbono at WORLDONLINE.FR
Thu Feb 9 11:36:52 EST 2006


Should work although I don't remember exactly how. I think you have to define 
only one newLineObj and add to it all the vertex of your polygon PLUS the 
first vertex. Then put this single closed line into your new shape.
Something like :
$line_a = ms_newLineObj();
$line_a->add($ecluse_sel_a);
$line_a->add($ecluse_sel_b);
$line_a->add($ecluse_sel_c);
$line_a->add($ecluse_sel_d);
$line_a->add($ecluse_sel_a);
$shape->add($line_a);
$zone_shp->addShape($shape);
$shape->free();
$zone_shp->free();

Hope it'll help.
Blaise


On Thursday 09 February 2006 15:36, LAGACHE Alexandre - VNF/Dir. 
Infrastructure-Environnement/Div. Géo Carto wrote:
> Hello All,
>
> I'd like to dynamically add polygons to a shapefile (php mapscript 4.80b).
> Here is what I do :
>
> $zone_shp = ms_newShapefileObj("zone_shp", MS_SHP_POLYGON);
> $shape = ms_newShapeObj(MS_SHAPE_POLYGON);
> $ecluse_sel_a = ms_newPointObj();
> $ecluse_sel_a-> setxy($mix,$miy);
> $ecluse_sel_b = ms_newPointObj();
> $ecluse_sel_b-> setxy($mix,$may);
> $ecluse_sel_c = ms_newPointObj();
> $ecluse_sel_c-> setxy($max,$may);
> $ecluse_sel_d = ms_newPointObj();
> $ecluse_sel_d-> setxy($max,$miy);
> $line_a = ms_newLineObj();
> $line_a->add($ecluse_sel_a);
> $line_a->add($ecluse_sel_b);
> $line_b = ms_newLineObj();
> $line_b->add($ecluse_sel_b);
> $line_b->add($ecluse_sel_c);
> $line_c = ms_newLineObj();
> $line_c->add($ecluse_sel_c);
> $line_c->add($ecluse_sel_d);
> $line_d = ms_newLineObj();
> $line_d->add($ecluse_sel_d);
> $line_d->add($ecluse_sel_a);
> $shape->add($line_a);
> $shape->add($line_b);
> $shape->add($line_c);
> $shape->add($line_d);
> $zone_shp->addShape($shape);
> $shape->free();
> $zone_shp->free();
>
> It seems to work fine but when I look at the layer, objects are multiline
> instead of polygons...
> Any idea ??? What am I doing wrong ?
>
> Thanks !
>
> Alexandre LAGACHE



More information about the mapserver-users mailing list