Home | Docs | Issue Tracker | FAQ | Download | |
Author: | Daniel Morissette |
---|---|
Contact: | dmorissette at mapgears.com |
Author: | Yewondwossen Assefa |
Contact: | yassefa at dmsolutions.ca |
Revision: | $Revision$ |
Date: | $Date$ |
Warning
This is the old PHP MapScript documentation. It only applies to MapServer 5.6 and older.
Contents
This is a PHP module to make MapServer’s MapScript functionalities available in a PHP Dynamically Loadable Library.
PHP MapScript was originally developed for PHP-3.0.14 but after MapServer 3.5 support for PHP3 has been dropped and as of the last update of this document, PHP 4.1.2 or more recent was required.
The module has been tested and used on Linux, Solaris, *BSD, and WinNT.
The following MapServer constants are available:
The following class objects are available through PHP MapScript.
Class Objects can be returned by the layerObj class, or can be created using:
classObj ms_newClassObj(layerObj layer [, classObj class])
The second argument class is optional. If given, the new class created will be a copy of this class.
Type | Name |
---|---|
string | name |
string | title |
int | type |
int | status (MS_ON, MS_OFF or MS_DELETE) |
double | minscaledenom |
double | maxscaledenom |
double | minscale (Deprecated in v5.0, use minscaledenom instead) |
double | maxscale (Deprecated in v5.0, use maxscaledenom instead) |
string | template |
labelObj | label |
int | numstyles |
string | keyimage |
string | group |
hashTableObj | metadata |
$oClass->updateFromString('CLASS STYLE COLOR 255 0 255 END END'); /*set the color */
Note
if you are using the numstyles parameter while using the deletestyle function on the class object you need to refetch a new class object.
Example :
//class has 2 styles
$class = $oLayer->getclass(0);
$class->deletestyle(1);
echo $class->numstyles; : will echo 2
$class = $oLayer->getclass(0);
echo $class->numstyles; : will echo 1
Note
getMetaData’s query is case sensitive.
Instances of colorObj are always embedded inside other classes.
Type | Name |
---|---|
int | red |
int | green |
int | blue |
Instances of errorObj are created internally by MapServer as errors happen. Errors are managed as a chained list with the first item being the most recent error. The head of the list can be fetched using ms_GetErrorObj(), and the list can be cleared using ms_ResetErrorList()
Type | Name |
---|---|
int | code //See error code constants above |
string | routine |
string | message |
Example: This example draws a map and reports all errors generated during the draw() call, errors can potentially come from multiple layers.
ms_ResetErrorList();
$img = $map->draw();
$error = ms_GetErrorObj();
while($error && $error->code != MS_NOERR)
{
printf("Error in %s: %s<br>\n", $error->routine, $error->message);
$error = $error->next();
}
The grid is always embedded inside a layer object defined as a grid (layer->connectiontype = MS_GRATICULE) (for more docs : https://github.com/mapserver/mapserver/wiki/MapServerGrid)
A layer can become a grid layer by adding a grid object to it using : ms_newGridObj(layerObj layer)
$oLayer = ms_newlayerobj($oMap);
$oLayer->set("name", "GRID");
ms_newgridobj($oLayer);
$oLayer->grid->set("labelformat", "DDMMSS");
Type | Name |
---|---|
double | minsubdivide |
double | maxsubdivide |
double | minarcs |
double | maxacrs |
double | mininterval |
double | maxinterval |
string | labelformat |
Instance of hashTableObj is always embedded inside the classObj, layerObj, and webObj. It is uses a read only.
$hashTable = $oLayer->metadata;
$key = null;
while ($key = $hashTable->nextkey($key))
echo "Key: ".$key." value: ".$hashTable->get($key)."<br/>";
Type | Name |
---|---|
int | width (read-only) |
int | height (read-only) |
string | imagepath |
string | imageurl |
Accessible only through the mapObj (map->getLabel()).
Type | Name |
---|---|
int | classindex (Read-Only) |
int | featuresize (Read-Only) |
int | layerindex (Read-Only) |
int | numstyles (Read-Only) |
int | shapeindex (Read-Only) |
int | status (Read-Only) |
string | text (Read-Only) |
int | tileindex (Read-Only) |
None
Accessible only through the mapObj (map->labelcache). This object is only used to give the possiblity to free the label cache (map->labelcache->free())
labelObj are always embedded inside other classes.
Type | Name |
---|---|
string | font |
int | type |
colorObj | color |
colorObj | outlinecolor |
int | outlinewidth |
colorObj | shadowcolor |
int | shadowsizex |
int | shadowsizey |
colorObj | backgroundcolor |
colorObj | backgroundshadowcolor |
int | backgroundshadowsizex |
int | backgroundshadowsizey |
int | size |
int | minsize |
int | maxsize |
int | position |
int | offsetx |
int | offsety |
double | angle |
int | autoangle |
int | autofollow |
int | buffer |
int | antialias |
int | wrap |
int | minfeaturesize |
int | autominfeaturesize |
int | mindistance |
int | repeatdistance |
int | partials |
int | force |
string | encoding |
int | align |
int | maxlength |
int | minlength |
int | priority |
Set the attribute binding for a specified label property. Returns true on success.
Example:
$oLabel->setbinding(MS_LABEL_BINDING_COLOR, "FIELD_NAME_COLOR");
This would bind the color parameter with the data (ie will extract the value of the color from the field called “FIELD_NAME_COLOR”
Get the attribute binding for a specified label property. Returns null if there is no binding for this property.
Example:
$oLabel->setbinding(MS_LABEL_BINDING_COLOR, "FIELD_NAME_COLOR");
echo $oLabel->getbinding(MS_LABEL_BINDING_COLOR); // FIELD_NAME_COLOR
Remove the attribute binding for a specfiled style property. Returns true on success.
Example:
$oStyle->removebinding(MS_LABEL_BINDING_COLOR);
Layer Objects can be returned by the mapObj class, or can be created using:
layerObj ms_newLayerObj(MapObj map [, layerObj layer])
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.
Type | Name |
---|---|
int | numclasses (read-only) |
int | index (read-only) |
int | status (MS_ON, MS_OFF, MS_DEFAULT or MS_DELETE) |
int | debug |
string | classitem |
string | classgroup |
string | name |
string | group |
string | data |
int | type |
int | dump |
double | tolerance |
int | toleranceunits |
int | sizeunits |
double | symbolscaledenom |
double | minscaledenom |
double | maxscaledenom |
double | labelminscaledenom |
double | labelmaxscaledenom |
double | symbolscale (Deprecated in v5.0, use symbolscaledenom instead) |
double | minscale (Deprecated in v5.0, use minscaledenom instead) |
double | maxscale (Deprecated in v5.0, use maxscaledenom instead) |
double | labelminscale (Deprecated in v5.0, use labelminscaledenom instead) |
double | labelmaxscale (Deprecated in v5.0, use labelmaxscaledenom instead) |
int | maxfeatures |
colorObj | offsite |
int | annotate |
int | transform |
int | labelcache |
int | postlabelcache |
string | labelitem |
string | labelsizeitem |
string | labelangleitem |
string | tileitem |
string | tileindex |
string | header |
string | footer |
string | connection |
int | connectiontype (read-only, use setConnectionType() to set it) |
string | filteritem |
string | template |
int | opacity |
int | transparency (Deprecated in v5.0. Use opacity instead.) |
string | styleitem |
gridObj | grid //only available on a layer defined as grid (MS_GRATICULE) |
int | num_processing |
string | requires |
string | labelrequires |
hashTableObj | metadata |
projectionObj | projection |
$oLayer->updateFromString('LAYER NAME land_fn2 END'); /*modify the name */
$oLayer->updateFromString('LAYER CLASS STYLE COLOR 255 255 0 END END END'); /*add a new class*/
Note
setWKTProjection requires GDAL support
$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 ."<br>\n";
}
$layer->close();
Note
getMetaData’s query is case sensitive.
$oLayer->setprocessing("SCALE_1=AUTO");
$oLayer->setprocessing("SCALE_2=AUTO");
Type | Name |
---|---|
int | height |
int | width |
int | keysizex |
int | keysizey |
int | keyspacingx |
int | keyspacingy |
colorObj | outlinecolor //Color of outline of box, -1 for no outline |
int | status //MS_ON, MS_OFF, MS_EMBED |
int | position //for embeded legends, MS_UL, MS_UC, ... |
int | transparent (Deprecated in v4.6) |
int | interlace (Deprecated in v4.6) |
int | postlabelcache //MS_TRUE, MS_FALSE |
labelObj | label |
colorObj | imagecolor |
string | template |
LineObj ms_newLineObj()
Type | Name |
---|---|
int | numpoints (read-only) |
Note
the 3rd parameter m is used for measured shape files only. It is not mandatory.
Note
the 4th parameter m is used for measured shape files only. It is not mandatory.
Note
By default, the SYMBOLSET, FONTSET, and other paths in the mapfile are relative to the mapfile location. If new_map_path is provided then this directory will be used as the base path for all the relative paths inside the mapfile.
Type | Name |
---|---|
int | numlayers (read-only) |
string | name |
int | status |
int | debug |
int | width (see setSize()) |
int | height (see setSize()) |
int | maxsize |
outputformatObj | outputformat |
double | resolution (pixels per inch, defaults to 72) |
rectObj | extent; |
double | cellsize |
int | units (map units type) |
double | scaledenom (read-only, set by drawMap()) |
double | scale (Deprecated in v5.0. Use scaledenom instead) |
string | shapepath |
int | keysizex |
int | keysizey |
int | keyspacingx |
int | keyspacingy |
webObj | web |
referenceMapObj | reference |
colorObj | imagecolor |
scalebarObj | scalebar |
legendObj | legend |
querymapObj | querymap |
string | symbolsetfilename (read-only, set by setSymbolSet()) |
string | fontsetfilename (read-only, set by setFontSet()) |
labelcacheObj | labelcache (no members. Used only to be able to free the the label cache (ex : map->labelcache->free()) |
projectionObj | projection |
int | transparent (Deprecated, use outputFormatObj) |
int | interlace (Deprecated, use outputFormatObj) |
int | imagetype (Deprecated, use outputFormatObj) |
int | imagequality (Deprecated, use outputFormatObj) |
while ($oLabelCacheMember = $oMap->getLabel($i)) {
/* do something with the labelcachemember */
++$i;
}
colorObj getcolorbyindex(int iCloIndex) Returns a colorObj corresponding to the color index in the palette
Zoom to a given XY postion.
Set the map extents to a given extents.
oPixelExt (rect object) : Pixel Extents, with (0,0) at the top-left The rectangle contains the coordinates of the LL and UR coordinates in pixel. (the maxy in the rect object should be < miny value)
------- UR (values in the rect object : maxx, maxy)
| |
| |
| |
------
LL (values in the rectobject minx, miny)
Width : width in pixel of the current image.
Height : Height in pixel of the current image.
Georef extent (rectObj) : current georef extents.
Zoom in or out to a given XY position so that the map is displayed at specified scale.
Note
setWKTProjection requires GDAL support
Note
getMetaData’s query is case sensitive.
Process the template file specified in the web object and return the result in a buffer. The processing consists of opening the template file and replace all the tags found in it. Only tags that have an equivalent element in the map object are replaced (ex [scaledenom]). The are two exceptions to the previous statement :
$tmparray["my_tag"] = "value_of_my_tag";
$map->processtemplate($tmparray, MS_FALSE);
See also
See also
Note
the type used should correspond to one of the output formats declared in the map file. The type argument passed is compared with the mimetype parameter in the output format structure and then to the name parameter in the structure.
Instance of outputformatObj is always embedded inside the mapObj. It is uses a read only.
No constructor available (coming soon, see ticket 979)
Type | Name |
---|---|
string | name |
string | mimetype |
string | driver |
string | extension |
int | renderer |
int | imagemode // MS_IMAGEMODE_* value. |
int | transparent |
Add or Modify the format option list. return true on success.
$oMap->outputformat->setOption("OUTPUT_TYPE", "RASTER");
Type | Name |
---|---|
int | numparams (read-only) |
int | type (read-only): MS_GET_REQUEST or MS_POST_REQUEST |
Set a request parameter. For example :
$request->setparameter('REQUEST', 'GetMap');
PointObj ms_newPointObj()
Type | Name |
---|---|
double | x |
double | y |
double | z (used for 3d shape files. set to 0 for other types) |
double | m (used only for measured shape files. set to 0 for other types.) |
Note
the 3rd parameter m is used for measured shape files only. It is not mandatory.
Note
the 4th parameter m is used for measured shape files only. It is not mandatory.
ProjectionObj ms_newProjectionObj(string projectionstring)
Creates a projection object based on the projection string passed as argument.
$projInObj = ms_newprojectionobj("proj=latlong")
will create a geographic projection class.
The following example will convert a lat/long point to an LCC projection:
$projInObj = ms_newprojectionobj("proj=latlong");
$projOutObj = ms_newprojectionobj("proj=lcc,ellps=GRS80,lat_0=49,".
"lon_0=-95,lat_1=49,lat_2=77");
$poPoint = ms_newpointobj();
$poPoint->setXY(-92.0, 62.0);
$poPoint->project($projInObj, $projOutObj);
Type | Name |
---|---|
int | width |
int | height |
int | style (MS_NORMAL, MS_HILITE, MS_SELECTED) |
colorObj | color |
rectObj are sometimes embedded inside other objects. New ones can also be created with:
RectObj ms_newRectObj()
Note
the members (minx, miny,maxx,maxy) are initialized to -1;
Type | Name |
---|---|
double | minx |
double | miny |
double | maxx |
double | maxy |
Type | Name |
---|---|
string | image |
int | width |
int | height |
int | status |
rectObj | extent |
ColorObj | color |
ColorObj | outlinecolor |
Instances of resultCacheMemberObj are always obtained through layerObj‘s getResult() method.
Type | Name |
---|---|
int | shapeindex (read-only) |
int | tileindex (read-only) |
int | classindex (read-only) |
None
Type | Name |
---|---|
int | height |
int | width |
int | style |
int | intervals |
colorObj | color |
colorObj | backgroundcolor |
colorObj | outlinecolor |
int | units |
int | status //MS_ON, MS_OFF, MS_EMBED |
int | position //for embeded scalebars, MS_UL, MS_UC, ... |
int | transparent (Deprecated in v4.6) |
int | interlace (Deprecated in v4.6) |
int | postlabelcache |
labelObj | label |
colorObj | imagecolor |
int | align |
shapefileObj ms_newShapefileObj(string filename, int type)
Opens a shapefile and returns a new object to deal with it. Filename should be passed with no extension. To create a new file (or overwrite an existing one), type should be one of MS_SHP_POINT, MS_SHP_ARC, MS_SHP_POLYGON or MS_SHP_MULTIPOINT. Pass type as -1 to open an existing file for read-only access, and type=-2 to open an existing file for update (append).
Type | Name |
---|---|
int | numshapes (read-only) |
int | type (read-only) |
string | source (read-only) |
rectObj | bounds (read-only) |
ShapeObj ms_newShapeObj(int type)
‘type’ is one of MS_SHAPE_POINT, MS_SHAPE_LINE, MS_SHAPE_POLYGON or MS_SHAPE_NULL
ShapeObj ms_shapeObjFromWkt(string wkt)
Creates new shape object from WKT string.
Type | Name |
---|---|
string | text |
int | classindex |
int | type (read-only) |
int | numlines (read-only) |
int | index |
int | tileindex (read-only) |
rectObj | bounds (read-only) |
int | numvalues (read-only) |
array | values (read-only) |
The values array is an associative array with the attribute values for this shape. It is set only on shapes obtained from layer->getShape(). The key to the values in the array is the attribute name, e.g.
$population = $shape->values["Population"];
Instances of styleObj are always embedded inside the classObj.
styleObj ms_newStyleObj(classObj class [, styleObj style])
The second argument ‘style’ is optional. If given, the new style created will be a copy of the style passed as argument.
Type | Name |
---|---|
int | symbol |
string | symbolname |
double | size |
double | minsize |
double | maxsize |
int | offsetx |
int | offsety |
int | antialias |
colorObj | color |
colorObj | backgroundcolor |
colorObj | outlinecolor |
double | width |
double | minwidth |
double | maxwidth |
double | angle |
string | angleitem |
string | sizeitem |
double | minvalue |
double | maxvalue |
string | rangeitem |
int | opacity (this parameter is only supported for the AGG driver) |
Set the attribute binding for a specfiled style property. Returns true on success. Added in MapServer 5.0.
$oStyle->setbinding(MS_STYLE_BINDING_COLOR, "FIELD_NAME_COLOR");
This would bind the color parameter with the data (ie will extract the value of the color from the field called “FIELD_NAME_COLOR”
Get the attribute binding for a specfiled style property. Returns null if there is no binding for this property.
$oStyle->setbinding(MS_STYLE_BINDING_COLOR, "FIELD_NAME_COLOR");
echo $oStyle->getbinding(MS_STYLE_BINDING_COLOR); // FIELD_NAME_COLOR
Remove the attribute binding for a specfiled style property. Returns true on success. Added in MapServer 5.0.
$oStyle->removebinding(MS_STYLE_BINDING_COLOR);
int ms_newSymbolObj(mapObj map, string symbolname)
Creates a new symbol with default values in the symbolist. Returns the Id of the new symbol. If a symbol with the same name exists, its id will be returned.
To get a symbol object, you need to use a method on the map object:
$oSymbol = $map->getSymbolObjectById($nId);
Type | Name |
---|---|
string | name |
type | name //Please refer to symbol type constants |
int | inmapfile If set to TRUE, the symbol will be saved inside the mapfile. |
double | sizex |
double | sizey |
int | numpoints (Read-Only) |
int | filled |
int | patternlength (Read-Only) |
int | stylelength (Deprecated in v5.0, use patternlength instead.) (Read-Only) |
string | imagepath (Read-Only)) |
int | transparent |
int | transparentcolor |
string | character |
int | antialias |
string | font |
int | gap (Deprecated in v6.0) |
int | position |
Example of usage:
$nId = ms_newsymbolobj($gpoMap, "mydash");
$oSymbol = $gpoMap->getsymbolobjectbyid($nId);
$oSymbol->set("filled", MS_TRUE);
$oSymbol->set("sizex", 1);
$oSymbol->set("sizey", 1);
$oSymbol->set("inmapfile", MS_TRUE);
$aPoints[0] = 1;
$aPoints[1] = 1;
$oSymbol->setpoints($aPoints);
$aPattern[0] = 10;
$aPattern[1] = 5;
$aPattern[2] = 5;
$aPattern[3] = 10;
$oSymbol->setpattern($aPattern);
$style->set("symbolname", "mydash");
$nId = ms_newSymbolObj($gpoMap, "ttfSymbol");
$oSymbol = $gpoMap->getSymbolObjectById($nId);
$oSymbol->set("type", MS_SYMBOL_TRUETYPE);
$oSymbol->set("filled", true);
$oSymbol->set("character", "D");
$oSymbol->set("font", "ttfFontName");
Type | Name |
---|---|
string | log |
string | imagepath |
string | template |
string | imageurl |
string | header |
string | footer |
string | empty (read-only) |
string | error (read-only) |
string | mintemplate |
string | maxtemplate |
double | minscaledenom |
double | maxscaledenom |
double | minscale (Deprecated in v5.0, use minscaledenom instead) |
double | maxscale (Deprecated in v5.0, use maxscaledenom instead) |
rectObj | extent (read-only) |
string | queryformat |
string | legendformat |
string | browseformat |
hashTableObj | metadata |