Skip to content
This repository was archived by the owner on Nov 13, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
d6d8ff7
Update install.md
ktzouno Jun 23, 2016
191f8d3
Merge pull request #159 from ktzouno/patch-1
sadortun Jun 23, 2016
4032b87
Fix PostgreSql function class names
teohhanhui Jul 15, 2016
1824a6f
Merge pull request #162 from teohhanhui/patch-2
sadortun Jul 15, 2016
c24d779
Update configuration.md
tgabi333 Sep 2, 2016
5829a52
Merge pull request #165 from tgabi333/patch-1
sadortun Dec 3, 2016
8ae16cc
Added support for geometry function
dragosprotung Dec 15, 2016
caa84a2
Merge pull request #167 from dragosprotung/geometry
sadortun Dec 15, 2016
23e47b9
Added support for ST_Collect function
dragosprotung Dec 15, 2016
065686e
Merge pull request #168 from dragosprotung/stcollect
sadortun Dec 15, 2016
43f6826
Support PHP 7.1
dragosprotung Dec 15, 2016
a35f9c1
Added ST_SnapToGrid support
dragosprotung Dec 15, 2016
9ef9003
Improved getting the sql for functions
dragosprotung Dec 15, 2016
8b73c5d
Merge pull request #171 from dragosprotung/improvedgetsql
sadortun Dec 16, 2016
82649ac
Merge pull request #169 from dragosprotung/php71
sadortun Dec 16, 2016
dc28144
Merge pull request #170 from dragosprotung/stsnaptogrid
sadortun Dec 16, 2016
3e040af
Implemented ST_Overlaps
dragosprotung Jan 6, 2017
f354743
Merge pull request #172 from dragosprotung/stoverlaps
sadortun Jan 6, 2017
404aadf
Added test for polygon from array of points
dragosprotung Jan 10, 2017
7211e90
Merge pull request #173 from dragosprotung/testSolidPolygonFromArrayO…
sadortun Jan 10, 2017
1e22d0f
Fix indent.
masayuki14 Jul 13, 2017
f14e0d4
Merge pull request #179 from masayuki14/patch-2
sadortun Jul 13, 2017
58ea5fa
Update INSTALL.md
sadortun Jul 13, 2017
9ab5d68
Prefix AsBinary and GeomFromText with "ST_"
holtkamp Dec 15, 2018
6ba8120
Add support for ST_SRID to allow getting / setting the SRID of a geog…
holtkamp Jan 5, 2020
811fc84
Add support for Geographical MultiPolygon type
holtkamp Jan 20, 2020
73cddcc
Indicated preferred axis-order "longitude, latitude" for Geographic t…
holtkamp Jan 20, 2020
8f2a963
Detect proper types
holtkamp Jan 20, 2020
6a8d172
Invalid type detection used
holtkamp Jan 23, 2020
258b520
Allow to statically set the used SRID to allow persisting Geography t…
holtkamp Jan 23, 2020
034edaa
Add static property
holtkamp Jan 23, 2020
b5788d2
Merge remote-tracking branch 'holtkamp/mysql-80-support' into add-hol…
matason Sep 15, 2023
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
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ php:
- 5.5
- 5.6
- 7.0
- 7.1
- hhvm

env:
Expand Down
205 changes: 107 additions & 98 deletions INSTALL.md

Large diffs are not rendered by default.

15 changes: 7 additions & 8 deletions doc/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ Add the types and functions you need to your Symfony configuration file. The doc
orm:
dql:
numeric_functions:
numeric_functions:
st_contains: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\STContains
contains: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Contains
st_area: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Area
st_geomfromtext: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\GeomFromText
st_intersects: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\STIntersects
st_buffer: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\STBuffer
point: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Point
st_contains: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\STContains
contains: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Contains
st_area: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Area
st_geomfromtext: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\GeomFromText
st_intersects: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\STIntersects
st_buffer: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\STBuffer
point: CrEOF\Spatial\ORM\Query\AST\Functions\MySql\Point
2 changes: 1 addition & 1 deletion doc/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Use these instructions if you're using Doctrine with Symfony2 , otherwise the Or
Require the `CrEOF/spatial2-doctrine` package in your composer.json and update
your dependencies.

$ composer require CrEOF/spatial2-doctrine
$ composer require CrEOF/doctrine2-spatial

## composer.json

Expand Down
26 changes: 24 additions & 2 deletions lib/CrEOF/Spatial/DBAL/Platform/MySql.php
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
* @license http://dlambert.mit-license.org MIT
*/
class MultiPolygonType extends GeographyType
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,12 @@ public function getSql(SqlWalker $sqlWalker)
{
$this->validatePlatform($sqlWalker->getConnection()->getDatabasePlatform());

$result = sprintf('%s(', $this->functionName);

for ($i = 0, $size = count($this->geomExpr); $i < $size;) {
$result .= $this->geomExpr[$i]->dispatch($sqlWalker);

if (++$i < $size) {
$result .= ', ';
}
$arguments = array();
foreach ($this->geomExpr as $expression) {
$arguments[] = $expression->dispatch($sqlWalker);
}

$result .= ')';

return $result;
return sprintf('%s(%s)', $this->functionName, implode(', ', $arguments));
}

/**
Expand All @@ -118,8 +111,10 @@ protected function validatePlatform(AbstractPlatform $platform)
{
$platformName = $platform->getName();

if (isset($this->platforms) && ! in_array($platformName, $this->platforms)) {
throw new UnsupportedPlatformException(sprintf('DBAL platform "%s" is not currently supported.', $platformName));
if (isset($this->platforms) && !in_array($platformName, $this->platforms)) {
throw new UnsupportedPlatformException(
sprintf('DBAL platform "%s" is not currently supported.', $platformName)
);
}
}
}
42 changes: 42 additions & 0 deletions lib/CrEOF/Spatial/ORM/Query/AST/Functions/MySql/STSRID.php
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
* @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;

}
43 changes: 43 additions & 0 deletions lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/Geometry.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* Copyright (C) 2016 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\ORM\Query\AST\Functions\PostgreSql;

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

/**
* Geometry DQL function
*
* @author Derek J. Lambert <[email protected]>
* @license http://dlambert.mit-license.org MIT
*/
class Geometry extends AbstractSpatialDQLFunction
{
protected $platforms = array('postgresql');

protected $functionName = 'geometry';

protected $minGeomExpr = 1;

protected $maxGeomExpr = 1;
}
43 changes: 43 additions & 0 deletions lib/CrEOF/Spatial/ORM/Query/AST/Functions/PostgreSql/STCollect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* Copyright (C) 2016 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\ORM\Query\AST\Functions\PostgreSql;

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

/**
* ST_Collect DQL function
*
* @author Derek J. Lambert <[email protected]>
* @license http://dlambert.mit-license.org MIT
*/
class STCollect extends AbstractSpatialDQLFunction
{
protected $platforms = array('postgresql');

protected $functionName = 'ST_Collect';

protected $minGeomExpr = 1;

protected $maxGeomExpr = 2;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

/**
* Copyright (C) 2017 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\ORM\Query\AST\Functions\PostgreSql;

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

/**
* ST_Overlaps DQL function.
*
* @author Dragos Protung
* @license http://mit-license.org MIT
*/
class STOverlaps extends AbstractSpatialDQLFunction
{
protected $platforms = array('postgresql');

protected $functionName = 'ST_Overlaps';

protected $minGeomExpr = 2;

protected $maxGeomExpr = 2;
}
Loading