final class layerObj (View source)

Layer Objects can be returned by the mapObj_ class, or can be created using: A second optional argument can be given to ms_newLayerObj() to create the new layer as a copy of an existing layer. If a layer is given as argument then all members of a this layer will be copied in the new layer created.

Properties

int $annotate
hashTableObj $bindvals
string $classgroup
string $classitem
clusterObj $cluster
string $connection
int $connectiontype

read-only, use setConnectionType() to set it

string $data
int $debug
int $dump

deprecated since 6.0

string $filteritem
$footer
gridObj $grid

only available on a layer defined as grid (MS_GRATICULE)

string $group
string $header
int $index read-only
int $labelcache
string $labelitem
float $labelmaxscaledenom
float $labelminscaledenom
string $labelrequires
string $mask
int $maxfeatures
float $maxscaledenom
hashTableObj $metadata
float $minscaledenom
string $name
int $num_processing
int $numclasses read-only
colorObj $offsite
int $opacity
projectionObj $projection
int $postlabelcache
string $requires
int $sizeunits
int $startindex
int $status

MS_ON, MS_OFF, MS_DEFAULT or MS_DELETE

string $styleitem
float $symbolscaledenom
string $template
string $tileindex
string $tileitem
float $tolerance
int $toleranceunits
int $transform
int $type

Methods

ms_newLayerObj(mapObj $map, layerObj $layer)

Old style constructor

int
addFeature(shapeObj $shape)

Add a new feature in a layer. Returns MS_SUCCESS or MS_FAILURE on error.

int
applySLD(string $sldxml, string $namedlayer)

Apply the :ref:SLD <sld> document to the layer object.

int
applySLDURL(string $sldurl, string $namedlayer)

Apply the :ref:SLD <sld> document pointed by the URL to the layer object. The matching between the sld document and the layer will be done using the layer's name. If a namedlayer argument is passed (argument is optional), the NamedLayer in the sld that matchs it will be used to style the layer. See :ref:SLD HowTo <sld> for more information on the SLD support.

void
clearProcessing()

Clears all the processing strings.

void
close()

Close layer previously opened with open().

string
convertToString()

Saves the object to a string. Provides the inverse option for updateFromString.

int
draw(imageObj $image)

Draw a single layer, add labels to cache if required.

int
drawQuery(imageObj $image)

Draw query map for a single layer.

void
free()

Free the object properties and break the internal references.

string
generateSLD()

Returns an SLD XML string based on all the classes found in the layer (the layer must have STATUS on).

getClass(int $classIndex)

Returns a classObj from the layer given an index value (0=first class)

int
getClassIndex($shape, $classgroup, $numclasses)

Get the class index of a shape for a given scale. Returns -1 if no class matches. classgroup is an array of class ids to check (Optional). numclasses is the number of classes that the classgroup array contains. By default, all the layer classes will be checked.

getExtent()

Returns the layer's data extents or NULL on error.

string|null
getFilterString()

Returns the :ref:expression <expressions> for this layer or NULL on error.

array
getGridIntersectionCoordinates()

Returns an array containing the grid intersection coordinates. If there are no coordinates, it returns an empty array.

array
getItems()

Returns an array containing the items. Must call open function first.

int
getMetaData(string $name)

Fetch layer metadata entry by name. Returns "" if no entry matches the name. Note that the search is case sensitive.

int
getNumResults()

Returns the number of results in the last query.

array
getProcessing()

Returns an array containing the processing strings.

string
getProjection()

Returns a string representation of the :ref:projection <projection>.

getResult(int $index)

Returns a resultObj by index from a layer object with index in the range 0 to numresults-1.

getResultsBounds()

Returns the bounding box of the latest result.

getShape(resultObj $result)

If the resultObj passed has a valid resultindex, retrieve shapeObj from a layer's resultset. (You get it from the resultObj returned by getResult() for instance). Otherwise, it will do a single query on the layer to fetch the shapeindex .. code-block:: php $map = new mapObj("gmap75.map"); $l = $map->getLayerByName("popplace"); $l->queryByRect($map->extent); for ($i = 0; $i < $l->getNumResults(); $i++) { $s = $l->getShape($l->getResult($i)); echo $s->getValue($l,"Name"); echo "\n"; }

string
getWMSFeatureInfoURL(int $clickX, int $clickY, int $featureCount, string $infoFormat)

Returns a WMS GetFeatureInfo URL (works only for WMS layers) clickX, clickY is the location of to query in pixel coordinates with (0,0) at the top left of the image.

bool
isVisible()

Returns MS_TRUE/MS_FALSE depending on whether the layer is currently visible in the map (i.e. turned on, in scale, etc.).

int
moveclassdown(int $index)

The class specified by the class index will be moved down into the array of layers. Returns MS_SUCCESS or MS_FAILURE.

int
moveclassup(int $index)

The class specified by the class index will be moved up into the array of layers. Returns MS_SUCCESS or MS_FAILURE.

int
open()

Open the layer for use with getShape().

nextShape()

Called after msWhichShapes has been called to actually retrieve shapes within a given area. Returns a shape object or NULL on error.

int
queryByAttributes(string $qitem, string $qstring, int $mode)

Query layer for shapes that intersect current map extents. qitem is the item (attribute) on which the query is performed, and qstring is the expression to match. The query is performed on all the shapes that are part of a :ref:CLASS that contains a :ref:TEMPLATE <template> value or that match any class in a layer that contains a :ref:LAYER :ref:TEMPLATE <template> value. Note that the layer's FILTER/FILTERITEM are ignored by this function. Mode is MS_SINGLE or MS_MULTIPLE depending on number of results you want. Returns MS_SUCCESS if shapes were found or MS_FAILURE if nothing was found or if some other error happened (note that the error message in case nothing was found can be avoided in PHP using the '@' control operator).

int
queryByFeatures(int $slayer)

Perform a query set based on a previous set of results from another layer. At present the results MUST be based on a polygon layer.

int
queryByPoint(pointObj $point, int $mode, float $buffer)

Query layer at point location specified in georeferenced map coordinates (i.e. not pixels).

int
queryByRect(rectObj $rect)

Query layer using a rectangle specified in georeferenced map coordinates (i.e. not pixels).

int
queryByShape(shapeObj $shape)

Query layer based on a single shape, the shape has to be a polygon at this point.

classObj|null
removeClass(int $index)

Removes the class indicated and returns a copy, or NULL in the case of a failure. Note that subsequent classes will be renumbered by this operation. The numclasses field contains the number of classes available.

int
removeMetaData(string $name)

Remove a metadata entry for the layer. Returns MS_SUCCESS/MS_FAILURE.

int
set(string $property_name, $new_value)

Set object property to a new value.

int
setConnectionType(int $connectiontype, string $plugin_library)

Changes the connectiontype of the layer and recreates the vtable according to the new connection type. This method should be used instead of setting the connectiontype parameter directly.

int
setFilter(string $expression)

Set layer filter :ref:expression <expressions>.

int
setMetaData(string $name, string $value)

Set a metadata entry for the layer. Returns MS_SUCCESS/MS_FAILURE.

int
setProjection(string $proj_params)

Set layer :ref:projection <projection> and coordinate system.

int
setWKTProjection(string $proj_params)

Same as setProjection(), but takes an OGC WKT projection definition string as input.

int
updateFromString(string $snippet)

Update a layer from a string snippet. Returns MS_SUCCESS/MS_FAILURE.

Details

final layerObj ms_newLayerObj(mapObj $map, layerObj $layer)

Old style constructor

Parameters

mapObj $map
layerObj $layer

Return Value

layerObj

final int addFeature(shapeObj $shape)

Add a new feature in a layer. Returns MS_SUCCESS or MS_FAILURE on error.

Parameters

shapeObj $shape

Return Value

int

final int applySLD(string $sldxml, string $namedlayer)

Apply the :ref:SLD <sld> document to the layer object.

The matching between the sld document and the layer will be done using the layer's name. If a namedlayer argument is passed (argument is optional), the NamedLayer in the sld that matchs it will be used to style the layer. See :ref:SLD HowTo <sld> for more information on the SLD support.

Parameters

string $sldxml
string $namedlayer

Return Value

int

final int applySLDURL(string $sldurl, string $namedlayer)

Apply the :ref:SLD <sld> document pointed by the URL to the layer object. The matching between the sld document and the layer will be done using the layer's name. If a namedlayer argument is passed (argument is optional), the NamedLayer in the sld that matchs it will be used to style the layer. See :ref:SLD HowTo <sld> for more information on the SLD support.

Parameters

string $sldurl
string $namedlayer

Return Value

int

final void clearProcessing()

Clears all the processing strings.

Return Value

void

final void close()

Close layer previously opened with open().

Return Value

void

final string convertToString()

Saves the object to a string. Provides the inverse option for updateFromString.

Return Value

string

final int draw(imageObj $image)

Draw a single layer, add labels to cache if required.

Returns MS_SUCCESS or MS_FAILURE on error.

Parameters

imageObj $image

Return Value

int

final int drawQuery(imageObj $image)

Draw query map for a single layer.

string executeWFSGetfeature() Executes a GetFeature request on a WFS layer and returns the name of the temporary GML file created. Returns an empty string on error.

Parameters

imageObj $image

Return Value

int

final void free()

Free the object properties and break the internal references.

Note that you have to unset the php variable to free totally the resources.

Return Value

void

final string generateSLD()

Returns an SLD XML string based on all the classes found in the layer (the layer must have STATUS on).

Return Value

string

final classObj getClass(int $classIndex)

Returns a classObj from the layer given an index value (0=first class)

Parameters

int $classIndex

Return Value

classObj

final int getClassIndex($shape, $classgroup, $numclasses)

Get the class index of a shape for a given scale. Returns -1 if no class matches. classgroup is an array of class ids to check (Optional). numclasses is the number of classes that the classgroup array contains. By default, all the layer classes will be checked.

Parameters

$shape
$classgroup
$numclasses

Return Value

int

final rectObj getExtent()

Returns the layer's data extents or NULL on error.

If the layer's EXTENT member is set then this value is used, otherwise this call opens/closes the layer to read the extents. This is quick on shapefiles, but can be an expensive operation on some file formats or data sources. This function is safe to use on both opened or closed layers: it is not necessary to call open()/close() before/after calling it.

Return Value

rectObj

final string|null getFilterString()

Returns the :ref:expression <expressions> for this layer or NULL on error.

Return Value

string|null

final array getGridIntersectionCoordinates()

Returns an array containing the grid intersection coordinates. If there are no coordinates, it returns an empty array.

Return Value

array

final array getItems()

Returns an array containing the items. Must call open function first.

If there are no items, it returns an empty array.

Return Value

array

final int getMetaData(string $name)

Fetch layer metadata entry by name. Returns "" if no entry matches the name. Note that the search is case sensitive.

.. note:: getMetaData's query is case sensitive.

Parameters

string $name

Return Value

int

final int getNumResults()

Returns the number of results in the last query.

Return Value

int

final array getProcessing()

Returns an array containing the processing strings.

If there are no processing strings, it returns an empty array.

Return Value

array

final string getProjection()

Returns a string representation of the :ref:projection <projection>.

Returns NULL on error or if no projection is set.

Return Value

string

final resultObj getResult(int $index)

Returns a resultObj by index from a layer object with index in the range 0 to numresults-1.

Returns a valid object or FALSE(0) if index is invalid.

Parameters

int $index

Return Value

resultObj

final rectObj getResultsBounds()

Returns the bounding box of the latest result.

Return Value

rectObj

final shapeObj getShape(resultObj $result)

If the resultObj passed has a valid resultindex, retrieve shapeObj from a layer's resultset. (You get it from the resultObj returned by getResult() for instance). Otherwise, it will do a single query on the layer to fetch the shapeindex .. code-block:: php $map = new mapObj("gmap75.map"); $l = $map->getLayerByName("popplace"); $l->queryByRect($map->extent); for ($i = 0; $i < $l->getNumResults(); $i++) { $s = $l->getShape($l->getResult($i)); echo $s->getValue($l,"Name"); echo "\n"; }

Parameters

resultObj $result

Return Value

shapeObj

final string getWMSFeatureInfoURL(int $clickX, int $clickY, int $featureCount, string $infoFormat)

Returns a WMS GetFeatureInfo URL (works only for WMS layers) clickX, clickY is the location of to query in pixel coordinates with (0,0) at the top left of the image.

featureCount is the number of results to return. infoFormat is the format the format in which the result should be requested. Depends on remote server's capabilities. MapServer WMS servers support only "MIME" (and should support "GML.1" soon). Returns "" and outputs a warning if layer is not a WMS layer or if it is not queriable.

Parameters

int $clickX
int $clickY
int $featureCount
string $infoFormat

Return Value

string

final bool isVisible()

Returns MS_TRUE/MS_FALSE depending on whether the layer is currently visible in the map (i.e. turned on, in scale, etc.).

Return Value

bool

final int moveclassdown(int $index)

The class specified by the class index will be moved down into the array of layers. Returns MS_SUCCESS or MS_FAILURE.

ex layer->moveclassdown(0) will have the effect of moving class 0 up to position 1, and the class at position 1 will be moved to position 0.

Parameters

int $index

Return Value

int

final int moveclassup(int $index)

The class specified by the class index will be moved up into the array of layers. Returns MS_SUCCESS or MS_FAILURE.

ex layer->moveclassup(1) will have the effect of moving class 1 up to position 0, and the class at position 0 will be moved to position 1.

Parameters

int $index

Return Value

int

final int open()

Open the layer for use with getShape().

Returns MS_SUCCESS/MS_FAILURE.

Return Value

int

final shapeObj nextShape()

Called after msWhichShapes has been called to actually retrieve shapes within a given area. Returns a shape object or NULL on error.

.. code-block:: php $map = ms_newmapobj("d:/msapps/gmap-ms40/htdocs/gmap75.map"); $layer = $map->getLayerByName('road'); $status = $layer->open(); $status = $layer->whichShapes($map->extent); while ($shape = $layer->nextShape()) { echo $shape->index ."
\n"; } $layer->close();

Return Value

shapeObj

final int queryByAttributes(string $qitem, string $qstring, int $mode)

Query layer for shapes that intersect current map extents. qitem is the item (attribute) on which the query is performed, and qstring is the expression to match. The query is performed on all the shapes that are part of a :ref:CLASS that contains a :ref:TEMPLATE <template> value or that match any class in a layer that contains a :ref:LAYER :ref:TEMPLATE <template> value. Note that the layer's FILTER/FILTERITEM are ignored by this function. Mode is MS_SINGLE or MS_MULTIPLE depending on number of results you want. Returns MS_SUCCESS if shapes were found or MS_FAILURE if nothing was found or if some other error happened (note that the error message in case nothing was found can be avoided in PHP using the '@' control operator).

Parameters

string $qitem
string $qstring
int $mode

Return Value

int

final int queryByFeatures(int $slayer)

Perform a query set based on a previous set of results from another layer. At present the results MUST be based on a polygon layer.

Returns MS_SUCCESS if shapes were found or MS_FAILURE if nothing was found or if some other error happened (note that the error message in case nothing was found can be avoided in PHP using the '@' control operator).

Parameters

int $slayer

Return Value

int

final int queryByPoint(pointObj $point, int $mode, float $buffer)

Query layer at point location specified in georeferenced map coordinates (i.e. not pixels).

The query is performed on all the shapes that are part of a CLASS that contains a TEMPLATE value or that match any class in a layer that contains a LAYER TEMPLATE value. Mode is MS_SINGLE or MS_MULTIPLE depending on number of results you want. Passing buffer -1 defaults to tolerances set in the map file (in pixels) but you can use a constant buffer (specified in ground units) instead. Returns MS_SUCCESS if shapes were found or MS_FAILURE if nothing was found or if some other error happened (note that the error message in case nothing was found can be avoided in PHP using the '@' control operator).

Parameters

pointObj $point
int $mode
float $buffer

Return Value

int

final int queryByRect(rectObj $rect)

Query layer using a rectangle specified in georeferenced map coordinates (i.e. not pixels).

The query is performed on all the shapes that are part of a CLASS that contains a TEMPLATE value or that match any class in a layer that contains a LAYER TEMPLATE value. Returns MS_SUCCESS if shapes were found or MS_FAILURE if nothing was found or if some other error happened (note that the error message in case nothing was found can be avoided in PHP using the '@' control operator).

Parameters

rectObj $rect

Return Value

int

final int queryByShape(shapeObj $shape)

Query layer based on a single shape, the shape has to be a polygon at this point.

Returns MS_SUCCESS if shapes were found or MS_FAILURE if nothing was found or if some other error happened (note that the error message in case nothing was found can be avoided in PHP using the '@' control operator).

Parameters

shapeObj $shape

Return Value

int

final classObj|null removeClass(int $index)

Removes the class indicated and returns a copy, or NULL in the case of a failure. Note that subsequent classes will be renumbered by this operation. The numclasses field contains the number of classes available.

Parameters

int $index

Return Value

classObj|null

final int removeMetaData(string $name)

Remove a metadata entry for the layer. Returns MS_SUCCESS/MS_FAILURE.

Parameters

string $name

Return Value

int

final int set(string $property_name, $new_value)

Set object property to a new value.

Parameters

string $property_name
$new_value

Return Value

int

final int setConnectionType(int $connectiontype, string $plugin_library)

Changes the connectiontype of the layer and recreates the vtable according to the new connection type. This method should be used instead of setting the connectiontype parameter directly.

In the case when the layer.connectiontype = MS_PLUGIN the plugin_library parameter should also be specified so as to select the library to load by MapServer. For the other connection types this parameter is not used.

Parameters

int $connectiontype
string $plugin_library

Return Value

int

final int setFilter(string $expression)

Set layer filter :ref:expression <expressions>.

Parameters

string $expression

Return Value

int

final int setMetaData(string $name, string $value)

Set a metadata entry for the layer. Returns MS_SUCCESS/MS_FAILURE.

int setProcessing(string) Add the string to the processing string list for the layer. The layer->num_processing is incremented by 1. Returns MS_SUCCESS or MS_FAILURE on error. .. code-block:: php $oLayer->setprocessing("SCALE_1=AUTO"); $oLayer->setprocessing("SCALE_2=AUTO");

Parameters

string $name
string $value

Return Value

int

final int setProjection(string $proj_params)

Set layer :ref:projection <projection> and coordinate system.

Parameters are given as a single string of comma-delimited PROJ.4 parameters. Returns MS_SUCCESS or MS_FAILURE on error.

Parameters

string $proj_params

Return Value

int

final int setWKTProjection(string $proj_params)

Same as setProjection(), but takes an OGC WKT projection definition string as input.

.. note:: setWKTProjection requires GDAL support

Parameters

string $proj_params

Return Value

int

final int updateFromString(string $snippet)

Update a layer from a string snippet. Returns MS_SUCCESS/MS_FAILURE.

.. code-block:: php modify the name $oLayer->updateFromString('LAYER NAME land_fn2 END'); add a new class $oLayer->updateFromString('LAYER CLASS STYLE COLOR 255 255 0 END END END'); int whichshapes(rectobj) Performs a spatial, and optionally an attribute based feature search. The function basically prepares things so that candidate features can be accessed by query or drawing functions (eg using nextshape function). Returns MS_SUCCESS, MS_FAILURE or MS_DONE. MS_DONE is returned if the layer extent does not overlap the rectObj.

Parameters

string $snippet

Return Value

int