Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/CrEOF/Spatial/DBAL/Platform/MySql.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
namespace CrEOF\Spatial\DBAL\Platform;

use CrEOF\Spatial\DBAL\Types\AbstractSpatialType;
use CrEOF\Spatial\DBAL\Types\GeographyType;
use CrEOF\Spatial\PHP\Types\Geography\GeographyInterface;

/**
Expand All @@ -34,6 +35,8 @@
*/
class MySql extends AbstractPlatform
{
const DEFAULT_SRID = 4326;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4326 magic number : spherical Mercator

http://spatialreference.org/ref/epsg/4326/


/**
* Gets the SQL declaration snippet for a field of this type.
*
Expand Down Expand Up @@ -69,6 +72,10 @@ public function convertToPHPValueSQL(AbstractSpatialType $type, $sqlExpr)
*/
public function convertToDatabaseValueSQL(AbstractSpatialType $type, $sqlExpr)
{
if ($type instanceof GeographyType) {
return sprintf('GeomFromText(%s, %u)', $sqlExpr, self::DEFAULT_SRID);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This always uses the constant though.

}

return sprintf('GeomFromText(%s)', $sqlExpr);
}
}