Skip to content

Commit

Permalink
Merge 034edaa into 58ea5fa
Browse files Browse the repository at this point in the history
  • Loading branch information
holtkamp committed Jan 23, 2020
2 parents 58ea5fa + 034edaa commit ba61c32
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 2 deletions.
26 changes: 24 additions & 2 deletions lib/CrEOF/Spatial/DBAL/Platform/MySql.php
Expand Up @@ -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
Expand All @@ -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.
*
Expand All @@ -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);
}

/**
Expand All @@ -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);
}

}
37 changes: 37 additions & 0 deletions lib/CrEOF/Spatial/DBAL/Types/Geography/MultiPolygonType.php
@@ -0,0 +1,37 @@
<?php
/**
* Copyright (C) 2015 Derek J. Lambert
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

namespace CrEOF\Spatial\DBAL\Types\Geography;

use CrEOF\Spatial\DBAL\Types\GeographyType;

/**
* Doctrine MULTIPOLYGON type
*
* @author Derek J. Lambert <dlambert@dereklambert.com>
* @license http://dlambert.mit-license.org MIT
*/
class MultiPolygonType extends GeographyType
{

}
42 changes: 42 additions & 0 deletions lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STSRID.php
@@ -0,0 +1,42 @@
<?php

/**
* Copyright (C) 2013 luca capra
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

namespace CrEOF\Spatial\ORM\Query\AST\Functions\MySql;

use CrEOF\Spatial\ORM\Query\AST\Functions\AbstractSpatialDQLFunction;

/**
* ST_SRID DQL function
*
* @author luca capra <luca.capra@create-net.org>
* @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;

}
37 changes: 37 additions & 0 deletions lib/CrEOF/Spatial/PHP/Types/Geography/MultiPolygon.php
@@ -0,0 +1,37 @@
<?php
/**
* Copyright (C) 2012 Derek J. Lambert
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

namespace CrEOF\Spatial\PHP\Types\Geography;

use CrEOF\Spatial\PHP\Types\AbstractMultiPolygon;

/**
* MultiPolygon object for MULTIPOLYGON geography type
*
* @author Derek J. Lambert <dlambert@dereklambert.com>
* @license http://dlambert.mit-license.org MIT
*/
class MultiPolygon extends AbstractMultiPolygon implements GeographyInterface
{

}

0 comments on commit ba61c32

Please sign in to comment.