diff --git a/lib/CrEOF/Spatial/DBAL/Platform/MySql.php b/lib/CrEOF/Spatial/DBAL/Platform/MySql.php index 4444fca4..36379fdb 100644 --- a/lib/CrEOF/Spatial/DBAL/Platform/MySql.php +++ b/lib/CrEOF/Spatial/DBAL/Platform/MySql.php @@ -25,6 +25,7 @@ use CrEOF\Spatial\DBAL\Types\AbstractSpatialType; use CrEOF\Spatial\PHP\Types\Geography\GeographyInterface; +use CrEOF\Spatial\DBAL\Types\GeographyType; /** * MySql spatial platform @@ -34,6 +35,22 @@ */ class MySql extends AbstractPlatform { + /** + * For Geographic types MySQL follows the WKT specifications and returns (latitude,longitude) while (x,y) / (longitude,latitude) is expected. + * + * Using the following option the preferred axis-order can be indicated. + * + * @var string + */ + const AXIS_ORDER_OPTION = 'axis-order=long-lat'; + + /** + * Optionally a SRID can be set to be used for Geographic types. + * + * @var int|null + */ + public static $srid; + /** * Gets the SQL declaration snippet for a field of this type. * @@ -58,7 +75,9 @@ public function getSQLDeclaration(array $fieldDeclaration) */ public function convertToPHPValueSQL(AbstractSpatialType $type, $sqlExpr) { - return sprintf('AsBinary(%s)', $sqlExpr); + return $type instanceof GeographyType + ? sprintf('ST_AsBinary(%s, "%s")', $sqlExpr, self::AXIS_ORDER_OPTION) + : sprintf('ST_AsBinary(%s)', $sqlExpr); } /** @@ -69,6 +88,9 @@ public function convertToPHPValueSQL(AbstractSpatialType $type, $sqlExpr) */ public function convertToDatabaseValueSQL(AbstractSpatialType $type, $sqlExpr) { - return sprintf('GeomFromText(%s)', $sqlExpr); + return $type instanceof GeographyType && is_int(self::$srid) + ? sprintf('ST_GeomFromText(%s, %d)', $sqlExpr, self::$srid) + : sprintf('ST_GeomFromText(%s)', $sqlExpr); } + } diff --git a/lib/CrEOF/Spatial/DBAL/Types/Geography/MultiPolygonType.php b/lib/CrEOF/Spatial/DBAL/Types/Geography/MultiPolygonType.php new file mode 100644 index 00000000..52420293 --- /dev/null +++ b/lib/CrEOF/Spatial/DBAL/Types/Geography/MultiPolygonType.php @@ -0,0 +1,37 @@ + + * @license http://dlambert.mit-license.org MIT + */ +class MultiPolygonType extends GeographyType +{ + +} diff --git a/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STSRID.php b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STSRID.php new file mode 100644 index 00000000..b48b3e58 --- /dev/null +++ b/lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STSRID.php @@ -0,0 +1,42 @@ + + * @license http://dlambert.mit-license.org MIT + */ +class STSRID extends AbstractSpatialDQLFunction { + + protected $platforms = array('mysql'); + protected $functionName = 'ST_SRID'; + protected $minGeomExpr = 1; + protected $maxGeomExpr = 2; + +} diff --git a/lib/CrEOF/Spatial/PHP/Types/Geography/MultiPolygon.php b/lib/CrEOF/Spatial/PHP/Types/Geography/MultiPolygon.php new file mode 100644 index 00000000..417287f1 --- /dev/null +++ b/lib/CrEOF/Spatial/PHP/Types/Geography/MultiPolygon.php @@ -0,0 +1,37 @@ + + * @license http://dlambert.mit-license.org MIT + */ +class MultiPolygon extends AbstractMultiPolygon implements GeographyInterface +{ + +}