layerObj
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 | ||
string | $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
Add a new feature in a layer. Returns MS_SUCCESS or MS_FAILURE on error.
Apply the :ref:SLD <sld>
document to the layer object.
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.
Clears all the processing strings.
Close layer previously opened with open().
Saves the object to a string. Provides the inverse option for updateFromString.
Free the object properties and break the internal references.
Returns an SLD XML string based on all the classes found in the
layer (the layer must have STATUS
on
).
Returns a classObj from the layer given an index value (0=first class)
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.
Returns the :ref:expression <expressions>
for this layer or NULL
on error.
Returns an array containing the grid intersection coordinates. If there are no coordinates, it returns an empty array.
Returns an array containing the items. Must call open function first.
Fetch layer metadata entry by name. Returns "" if no entry matches the name. Note that the search is case sensitive.
Returns the number of results in the last query.
Returns an array containing the processing strings.
Returns a string representation of the :ref:projection <projection>
.
Returns a resultObj by index from a layer object with index in the range 0 to numresults-1.
Returns the bounding box of the latest 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"; }
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.
Returns MS_TRUE/MS_FALSE depending on whether the layer is currently visible in the map (i.e. turned on, in scale, etc.).
The class specified by the class index will be moved down into the array of layers. Returns MS_SUCCESS or MS_FAILURE.
The class specified by the class index will be moved up into the array of layers. Returns MS_SUCCESS or MS_FAILURE.
Open the layer for use with getShape().
Called after msWhichShapes has been called to actually retrieve shapes within a given area. Returns a shape object or NULL on error.
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).
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.
Query layer at point location specified in georeferenced map coordinates (i.e. not pixels).
Query layer using a rectangle specified in georeferenced map coordinates (i.e. not pixels).
Query layer based on a single shape, the shape has to be a polygon at this point.
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.
Remove a metadata entry for the layer. Returns MS_SUCCESS/MS_FAILURE.
Set object property to a new value.
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.
Set layer filter :ref:expression <expressions>
.
Set a metadata entry for the layer. Returns MS_SUCCESS/MS_FAILURE.
Set layer :ref:projection <projection>
and coordinate system.
Same as setProjection(), but takes an OGC WKT projection definition string as input.
Update a layer from a string snippet. Returns MS_SUCCESS/MS_FAILURE.
Details
final int
addFeature(shapeObj $shape)
Add a new feature in a layer. Returns MS_SUCCESS or MS_FAILURE on error.
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.
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.
final void
clearProcessing()
Clears all the processing strings.
final void
close()
Close layer previously opened with open().
final string
convertToString()
Saves the object to a string. Provides the inverse option for updateFromString.
final int
draw(imageObj $image)
Draw a single layer, add labels to cache if required.
Returns MS_SUCCESS or MS_FAILURE on error.
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.
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.
final string
generateSLD()
Returns an SLD XML string based on all the classes found in the
layer (the layer must have STATUS
on
).
final classObj
getClass(int $classIndex)
Returns a classObj from the layer given an index value (0=first class)
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.
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.
final string|null
getFilterString()
Returns the :ref:expression <expressions>
for this layer or NULL
on error.
final array
getGridIntersectionCoordinates()
Returns an array containing the grid intersection coordinates. If there are no coordinates, it returns an empty 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.
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.
final int
getNumResults()
Returns the number of results in the last query.
final array
getProcessing()
Returns an array containing the processing strings.
If there are no processing strings, it returns an empty array.
final string
getProjection()
Returns a string representation of the :ref:projection <projection>
.
Returns NULL on error or if no projection is set.
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.
final rectObj
getResultsBounds()
Returns the bounding box of the latest result.
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"; }
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.
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.).
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.
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.
final int
open()
Open the layer for use with getShape().
Returns MS_SUCCESS/MS_FAILURE.
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();
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).
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).
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).
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).
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).
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.
final int
removeMetaData(string $name)
Remove a metadata entry for the layer. Returns MS_SUCCESS/MS_FAILURE.
final int
set(string $property_name, $new_value)
Set object property to a new value.
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.
final int
setFilter(string $expression)
Set layer filter :ref:expression <expressions>
.
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");
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.
final int
setWKTProjection(string $proj_params)
Same as setProjection(), but takes an OGC WKT projection definition string as input.
.. note:: setWKTProjection requires GDAL support
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.