[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))’));

Thanks!

SOLUTION:

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:

http://www.yiiframework.com/doc/guide/database.dao

using the example downthere

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

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

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

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

$command->bindParam(":username",$username,PDO::PARAM_STR);

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

$command->bindParam(":email",$email,PDO::PARAM_STR);

$command->execute();

// insert another row with a new set of parameters

$command->bindParam(":username",$username2,PDO::PARAM_STR);

$command->bindParam(":email",$email2,PDO::PARAM_STR);

$command->execute();