How can I extend Doctrine 2 to handle the spatial ("point" type) of MySQL in CodeIgniter 2?

I am coding a website using CodeIgniter 2 as my framework, and recently I started using Doctrine 2 for ORM.

My database needs to store spatial data (such as a dot column), and apparently Doctrine cannot handle this out of the box.

I searched all over the internet and found only these tips: http://codeutopia.net/blog/2011/02/19/using-spatial-data-in-doctrine-2/

But this article is unclear where to save these files and what else needs to be configured. I tried to contact the author and never heard.

Can anyone help?

Thank! Ryan

+3
source share
2

, , 4 CodeIgniter/application/libraries/Doctrine/CustomAddon:

  • Distance.php
  • Point.php
  • PointStr.php
  • PointType.php

"CustomAddon".

CodeIgniter/application/libraries/Doctrine.php :

require_once APPPATH . 'libraries/Doctrine/CustomAddon/Distance.php';
require_once APPPATH . 'libraries/Doctrine/CustomAddon/Point.php';
require_once APPPATH . 'libraries/Doctrine/CustomAddon/PointStr.php';
require_once APPPATH . 'libraries/Doctrine/CustomAddon/PointType.php';
Doctrine\DBAL\Types\Type::addType('point', 'CustomAddon\PointType');
//Assuming $config is a Doctrine\ORM\Configuration object used to configure the EM
$config->addCustomNumericFunction('DISTANCE', 'CustomAddon\Distance');
$config->addCustomNumericFunction('POINT_STR', 'CustomAddon\PointStr');

// Create EntityManager
$this->em = EntityManager::create($connectionOptions, $config);

:

$point = new \CustomAddon\Point($geo['lat'], $geo['lon']);
+1

1.2, , . 1.2.4 yaml , . , , :

$phone->point = new Doctrine_Expression("GEOMFROMTEXT('POINT(25 10)')");

, 25 10, . 1.2.4 . , select:

$query = Doctrine_Query::create()
         ->select ('X(p.point), Y(p.point)')
         ->from('Points p');

, (x y) . , 1.2.4, , - 2. !

0

All Articles