[mapserver-users] PHP Mapscript Layer object´s Open method

Daniel Morissette morissette at dmsolutions.ca
Sun Jun 23 13:30:22 EDT 2002


Nicolau,

How is this layer defined in your mapfile?  Did you set the "DATA" value
in the layer?  The open() method opens the layer as defined in the
mapfile and you cannot pass it a different shapefile filename.  The
argument you pass to $lyr->open() should be the value of
$map->shapepath.

So assuming your mapfile says:

  MAP...
    SHAPEPATH "../geo"
    ...
    LAYER
      NAME "brest"
      DATA "brest" 
      ...
    END
  END

Then you should be able to access the ../geo/brest.shp file using the
following calls:

 $lyr=$map->getLayerByName("brest");
 $lyr->open($map->shapepath);
 $shp=$lyr->getShape(-1, 1);
 echo $shp->values["UF"]."<BR>";
 $lyr->close();


Note that if all you want is to open a shapefile independent of a
mapfile layer then you can use the shapefileObj class... see the
MapScript docs.

I hope that helps,

Daniel


Nicolau Werneck wrote:
> 
> Hello, people
> 
> Some time ago I sent a message here because of this
> piece of code:
> 
> $lyr=$map->getLayerByName("brest");
> //$lyr->open("..\\geo\\brest.shp");
> $shp=$lyr->getShape(-1, 1);
> echo $shp->values["UF"]."<BR>";
> 
> Well, I finally started to work on that part of the
> project again, and I must open this layer and find the
> limits of specific shapes, so i can render maps
> "closed" on them.
> 
> I´m trying to use the getShape function, and it needs
> that the open() function be called before it.
> 
> I´m not shure I understand the process, and worse:
> I´m not able to execute the Open function! Mapscript
> returns:
> 
> Fatal error: MapServer Error in msOpenSHPFile(): No
> (NULL) filename provided.
> 
> I´ve tried total and relative paths, with slash and
> backslash, but it just can´t find it!
> 
> The documentation didn´t help me... I hope I can
> receive some light from the PHP Mapscript gurus out
> there! :)  How would be a "paragraph" of code that
> opens a layer, finds a shape from it and reads it´s
> extents?
> 
> Thanks!
> 
> ++Nicolau
> 
> PS: One workaround it to have the extents on the
> database I use... Thinking about it make me shiver!...
> :Q
> 
> _______________________________________________________________________
> Copa 2002
> Yahoo! - Patrocinador oficial da Copa do Mundo da FIFA 2002
> http://br.sports.yahoo.com/fifaworldcup/



More information about the mapserver-users mailing list