Allows to interact with spatial-fields of AR-model like regular arrays


SpatialDataBehavior allows to interact with spatial-fields of AR-model like regular arrays

If your MySql database contains Spatial-fields (eg POINT or LINESTRING), this behavior allows to operate with these fields in models as normal arrays:

$spatial=new SpatialTableModel;
$spatial->pointField = array(86.18, 55.31);
$spatial->linestringField = [[86.18, 55.31], [86.19, 55.32]];
$spatial->multiLineStringField = [[[86.18, 55.31], [86.19, 55.32]], [[85.18, 56.31], [87.19, 54.32]]];

All "instantiable" class are supported except GeometryCollection (see MySql's Spatial Extention docs).

Behaviour also converts the data into an array when received from the base:



Developed with Yii 1.1.13. Should work with any 1.1 Version of Yii.


  1. Place SpatialDataBehavior.php into your project, for example to the folder components/behaviors
  2. Register the behavior on the model with spatial fields
  3. Specify a list of your spatial fields:
public function behaviors() {
    return array(

Use behavior as described above.

You can also use the method arrayToGeom to convert an array to OpenGIS's WKT format which used by MySql:



Be the first person to leave a comment

Please to leave your comment.

Create extension