GIS extension for Doctrine 2

2019-06-20 09:48发布

I want to write a GIS (geospatial data) extension for my Doctrine 2 project.

I know how to write simple custom functions and types. In order to accommodate the MySQL special storage format, I need to use some SQL function (GeomFromWKB() and AsBinary()) when retrieving/storing data.

I can't find a place where I tell Doctrine 2 this. As I see it, the convertToPHPValue() and convertToDatabaseValue() methods are not the right place.

3条回答
贪生不怕死
2楼-- · 2019-06-20 10:22

Update/Alternative:

I've found a symfony2 extension that serves most of my needs. I've forked it and added what I need here:

https://github.com/tvogt/doctrine2-spatial/

查看更多
Melony?
3楼-- · 2019-06-20 10:34

If you want to call SQL function in doctrine2 you can do it be Expression Func but this will works only with DQL.

Here you have example that will tell you how to use DATE_DIFF function that is not included in doctrine.

$qb = $repository->createQueryBuilder('l');
$qb->expr()->lte(new Doctrine\ORM\Query\Expr\Func('DATE_DIFF',array('lo.start_date', 'CURRENT_DATE()')),'0');
查看更多
放荡不羁爱自由
4楼-- · 2019-06-20 10:37

What I found out so far: According to the IRC channel, convertToPHPValueSQL() and convertToDatabaseValueSQL() will be part of the next release, and will offer the functionality required. Once that is available, defining a CustomType is fairly straightforward.

查看更多
登录 后发表回答