Dear Mapserver users,
I have problem in creating a polygon shapefile. I am trying
to write a PHP script aiming to add a polygon to a newly
created shapefile by using the method addShape:

        $my_line = ms_newLineObj();
        $my_line->addXY($x_1,$y_1);
        $my_line->addXY($x_2,$y_2);
                 .
                 .
                 .
        $my_shape=ms_newShapeObj(MS_SHAPE_POLYGON);
        $my_shape->add($my_line);
        $file_name="C://my:shape//shape";
        $my_file=ms_newShapefileObj("$file_name",MS_SHP_POLYGON);
        $dbfFile = dbase_create( $file_name.".dbf",
array(array("ID", "N", 5,0)));
        $ft=$my_file->addShape($my_shape);//PROBLEM
        dbase_add_record($dbfFile, array(1));
        dbase_close($dbfFile);
        $my_file->free();

return value of $ft is 0 which means that method addShape
has been succesfully implemented. However, the members
values of my Shapefileobj are 0 for numshapes and  not
available for source and bounds. I checked my polygon and
all member variables are OK, so I am not sure what addShape
function actually does and if it is necessary to add each
point to the shapefile with the method addPoint. Where do I
go wrong?


2. After I added points in the line and then the line to
the shape (the coordinates of the last and first point are
same), I realised that member variable bounds of the shape
is not provided. I went around this problem by finding the
smallest and greates x and y coordinates of the points I
added to the line i.e. the shape which I then used to set
boundaries:
        $my_shape->bounds->set(minx,$x_min);
        $my_shape->bounds->set(maxx,$x_max);
        $my_shape->bounds->set(miny,$y_min);
        $my_shape->bounds->set(maxy,$y_max);

Is this right thing to do and why have not these bounds
calculated automatically?

Thanking in advance

Reply via email to