[SOLVED]How does Yii framework deal with spatial data on MySQL or PostgreSQL?

Hi, I am a newbie to Yii. I have spatial data (of Geometry type) in the database where the data is stored in binary form. The model generated from Yii (using crud command) couldn’t display the binary data. So my questions is:

How to deal with spatial data with Yii?

For example:

  1. The sql to read a spatial data: SELECT AsText(shape) as shape_string FROM my_shape_table;

  2. To insert a new spatial entry:

INSERT INTO my_shape_table(id, shape) VALUES($id, geomFromText(‘Polygon((34.13 -118.66 , 34.23 -118.66, 34.23 -118.56, 34.13 -118.56, 34.13 -118.66))’));



I solved it with custom query.

$sql = "SELECT astext(shape) FROM myshapetable;";

$command = $this->connection->createCommand($sql);

$result = $command->queryAll();

Hope that helps!

same question here!!!

EDIT: hmmm…maybe you could create a method in the model that takes the geometry field returned and convert it back to text! :mellow:


using the example downthere

// an SQL with two placeholders ":username" and ":email"

$sql="INSERT INTO tbl_user (username, email) VALUES(:username,:email)";


// replace the placeholder ":username" with the actual username value


// replace the placeholder ":email" with the actual email value



// insert another row with a new set of parameters