Skip to content

Commit

Permalink
Changed namespace from Grimzy\LaravelSpatial to Grimzy\LaravelMysqlSp…
Browse files Browse the repository at this point in the history
…atial
  • Loading branch information
grimzy committed Jun 4, 2017
1 parent 422e3f3 commit b5a90c6
Show file tree
Hide file tree
Showing 40 changed files with 201 additions and 191 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
"autoload": {
"psr-4": {
"Grimzy\\LaravelSpatial\\": "src/"
"Grimzy\\LaravelMysqlSpatial\\": "src/"
}
},
"autoload-dev" : {
Expand Down
5 changes: 3 additions & 2 deletions src/Connectors/ConnectionFactory.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php
namespace Grimzy\LaravelSpatial\Connectors;

use Grimzy\LaravelSpatial\MysqlConnection;
namespace Grimzy\LaravelMysqlSpatial\Connectors;

use Grimzy\LaravelMysqlSpatial\MysqlConnection;
use PDO;

class ConnectionFactory extends \Illuminate\Database\Connectors\ConnectionFactory
Expand Down
7 changes: 4 additions & 3 deletions src/Eloquent/Builder.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php
namespace Grimzy\LaravelSpatial\Eloquent;

use Grimzy\LaravelSpatial\Types\GeometryInterface;
namespace Grimzy\LaravelMysqlSpatial\Eloquent;

use Grimzy\LaravelMysqlSpatial\Types\GeometryInterface;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;

class Builder extends EloquentBuilder
Expand All @@ -19,6 +20,6 @@ public function update(array $values)

protected function asWKT(GeometryInterface $geometry)
{
return $this->getQuery()->raw("GeomFromText('" . $geometry->toWKT() . "')");
return $this->getQuery()->raw("GeomFromText('".$geometry->toWKT()."')");
}
}
39 changes: 23 additions & 16 deletions src/Eloquent/SpatialTrait.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php
namespace Grimzy\LaravelSpatial\Eloquent;

use Grimzy\LaravelSpatial\Exceptions\SpatialFieldsNotDefinedException;
use Grimzy\LaravelSpatial\Types\Geometry;
use Grimzy\LaravelSpatial\Types\GeometryInterface;
use Grimzy\LaravelSpatial\Types\Point;
namespace Grimzy\LaravelMysqlSpatial\Eloquent;

use Grimzy\LaravelMysqlSpatial\Exceptions\SpatialFieldsNotDefinedException;
use Grimzy\LaravelMysqlSpatial\Types\Geometry;
use Grimzy\LaravelMysqlSpatial\Types\GeometryInterface;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;

trait SpatialTrait
Expand All @@ -25,7 +25,7 @@ trait SpatialTrait
*
* @param \Illuminate\Database\Query\Builder $query
*
* @return \Grimzy\LaravelSpatial\Eloquent\Builder
* @return \Grimzy\LaravelMysqlSpatial\Eloquent\Builder
*/
public function newEloquentBuilder($query)
{
Expand Down Expand Up @@ -68,47 +68,54 @@ public function getSpatialFields()
if (property_exists($this, 'spatialFields')) {
return $this->spatialFields;
} else {
throw new SpatialFieldsNotDefinedException(__CLASS__ . ' has to define $spatialFields');
throw new SpatialFieldsNotDefinedException(__CLASS__.' has to define $spatialFields');
}
}

public function scopeDistance($query, $distance, $geometry, $column_name, $exclude_self = false) {
public function scopeDistance($query, $distance, $geometry, $column_name, $exclude_self = false)
{
$query->whereRaw("st_distance(`{$column_name}`, GeomFromText('{$geometry->toWkt()}')) <= {$distance}");

if($exclude_self) {
if ($exclude_self) {
$query->whereRaw("st_distance(`{$column_name}`, GeomFromText('{$geometry->toWkt()}')) != 0");
}

return $query;
}

public function scopeDistanceSphere($query, $distance, $geometry, $column_name, $exclude_self = false) {
public function scopeDistanceSphere($query, $distance, $geometry, $column_name, $exclude_self = false)
{
$query->whereRaw("st_distance_sphere(`{$column_name}`, GeomFromText('{$geometry->toWkt()}')) <= {$distance}");

if($exclude_self) {
if ($exclude_self) {
$query->whereRaw("st_distance_sphere(`{$column_name}`, GeomFromText('{$geometry->toWkt()}')) != 0");
}

return $query;
}

public function scopeDistanceValue($query, $geometry, $column_name) {
public function scopeDistanceValue($query, $geometry, $column_name)
{
$columns = $query->getQuery()->columns;

if(!$columns) {
if (! $columns) {
$query->select('*');
}
$query->selectRaw("st_distance(`{$column_name}`, GeomFromText('{$geometry->toWkt()}')) as distance");
}

public function scopeDistanceSphereValue($query, $geometry, $column_name) {
public function scopeDistanceSphereValue($query, $geometry, $column_name)
{
$columns = $query->getQuery()->columns;

if(!$columns) {
if (! $columns) {
$query->select('*');
}
$query->selectRaw("st_distance_sphere(`{$column_name}`, GeomFromText('{$geometry->toWkt()}')) as distance");
}

public function scopeBounding($query, Geometry $bounds, $column_name) {
public function scopeBounding($query, Geometry $bounds, $column_name)
{
return $query->whereRaw("st_intersects(GeomFromText('{$bounds->toWkt()}'), `{$column_name}`)");
}
}
3 changes: 2 additions & 1 deletion src/Exceptions/SpatialFieldsNotDefinedException.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
namespace Grimzy\LaravelSpatial\Exceptions;

namespace Grimzy\LaravelMysqlSpatial\Exceptions;

class SpatialFieldsNotDefinedException extends \RuntimeException
{
Expand Down
3 changes: 2 additions & 1 deletion src/Exceptions/UnknownWKTTypeException.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
namespace Grimzy\LaravelSpatial\Exceptions;

namespace Grimzy\LaravelMysqlSpatial\Exceptions;

class UnknownWKTTypeException extends \RuntimeException
{
Expand Down
4 changes: 2 additions & 2 deletions src/MysqlConnection.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
namespace Grimzy\LaravelSpatial;

namespace Grimzy\LaravelMysqlSpatial;

class MysqlConnection extends \Illuminate\Database\MySqlConnection
{
Expand All @@ -21,7 +22,6 @@ protected function getDefaultSchemaGrammar()
return $this->withTablePrefix(new Schema\Grammars\MySqlGrammar());
}


public function getSchemaBuilder()
{
if (is_null($this->schemaGrammar)) {
Expand Down
12 changes: 7 additions & 5 deletions src/Schema/Blueprint.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
namespace Grimzy\LaravelSpatial\Schema;

namespace Grimzy\LaravelMysqlSpatial\Schema;

class Blueprint extends \Illuminate\Database\Schema\Blueprint
{
Expand Down Expand Up @@ -94,18 +95,19 @@ public function geometryCollection($column)
/**
* Specify a spatial index for the table
*
* @param string|array $columns
* @param string $name
* @param string|array $columns
* @param string $name
* @return \Illuminate\Support\Fluent
*/
public function spatialIndex($columns, $name = null) {
public function spatialIndex($columns, $name = null)
{
return $this->indexCommand('spatial', $columns, $name);
}

/**
* Indicate that the given index should be dropped.
*
* @param string|array $index
* @param string|array $index
* @return \Illuminate\Support\Fluent
*/
public function dropSpatialIndex($index)
Expand Down
3 changes: 2 additions & 1 deletion src/Schema/Builder.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
namespace Grimzy\LaravelSpatial\Schema;

namespace Grimzy\LaravelMysqlSpatial\Schema;

use Closure;
use Illuminate\Database\Schema\MySqlBuilder;
Expand Down
9 changes: 5 additions & 4 deletions src/Schema/Grammars/MySqlGrammar.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php
namespace Grimzy\LaravelSpatial\Schema\Grammars;

use Grimzy\LaravelSpatial\Schema\Blueprint;
namespace Grimzy\LaravelMysqlSpatial\Schema\Grammars;

use Grimzy\LaravelMysqlSpatial\Schema\Blueprint;
use Illuminate\Support\Fluent;

class MySqlGrammar extends \Illuminate\Database\Schema\Grammars\MySqlGrammar
Expand Down Expand Up @@ -97,8 +98,8 @@ public function typeGeometrycollection(Fluent $column)
/**
* Compile a spatial index key command.
*
* @param \Grimzy\LaravelSpatial\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @param \Grimzy\LaravelMysqlSpatial\Schema\Blueprint $blueprint
* @param \Illuminate\Support\Fluent $command
* @return string
*/
public function compileSpatial(Blueprint $blueprint, Fluent $command)
Expand Down
9 changes: 5 additions & 4 deletions src/SpatialServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
<?php
namespace Grimzy\LaravelSpatial;

use Grimzy\LaravelSpatial\Connectors\ConnectionFactory;
namespace Grimzy\LaravelMysqlSpatial;

use Grimzy\LaravelMysqlSpatial\Connectors\ConnectionFactory;
use Illuminate\Database\DatabaseManager;
use Illuminate\Database\DatabaseServiceProvider;

/**
* Class DatabaseServiceProvider
* @package Grimzy\LaravelSpatial
*
* @package Grimzy\LaravelMysqlSpatial
*/
class SpatialServiceProvider extends DatabaseServiceProvider
{

/**
* Register the service provider.
*
Expand Down
4 changes: 2 additions & 2 deletions src/Types/Factory.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
namespace Grimzy\LaravelSpatial\Types;

namespace Grimzy\LaravelMysqlSpatial\Types;

class Factory implements \GeoIO\Factory
{
Expand Down Expand Up @@ -42,5 +43,4 @@ public function createGeometryCollection($dimension, array $geometries, $srid =
{
return new GeometryCollection($geometries);
}

}
10 changes: 6 additions & 4 deletions src/Types/Geometry.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?php
namespace Grimzy\LaravelSpatial\Types;

namespace Grimzy\LaravelMysqlSpatial\Types;

use GeoIO\WKB\Parser\Parser;
use Grimzy\LaravelSpatial\Exceptions\UnknownWKTTypeException;
use Grimzy\LaravelMysqlSpatial\Exceptions\UnknownWKTTypeException;

abstract class Geometry implements GeometryInterface, \JsonSerializable
{
Expand All @@ -13,7 +14,7 @@ abstract class Geometry implements GeometryInterface, \JsonSerializable
4 => MultiPoint::class,
5 => MultiLineString::class,
6 => MultiPolygon::class,
7 => GeometryCollection::class
7 => GeometryCollection::class,
];

public static function getWKTArgument($value)
Expand Down Expand Up @@ -45,7 +46,7 @@ public static function getWKTClass($value)
case 'GEOMETRYCOLLECTION':
return GeometryCollection::class;
default:
throw new UnknownWKTTypeException('Type was ' . $type);
throw new UnknownWKTTypeException('Type was '.$type);
}
}

Expand All @@ -58,6 +59,7 @@ public static function fromWKB($wkb)
}

$parser = new Parser(new Factory());

return $parser->parse($wkb);
}

Expand Down
32 changes: 10 additions & 22 deletions src/Types/GeometryCollection.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
namespace Grimzy\LaravelSpatial\Types;

namespace Grimzy\LaravelMysqlSpatial\Types;

use Countable;
use GeoJson\GeoJson;
use InvalidArgumentException;

class GeometryCollection extends Geometry implements Countable
Expand Down Expand Up @@ -36,37 +36,25 @@ public function getGeometries()

public function toWKT()
{
return sprintf('GEOMETRYCOLLECTION(%s)', (string)$this);
return sprintf('GEOMETRYCOLLECTION(%s)', (string) $this);
}

public function __toString()
{
return implode(
',',
array_map(
function (GeometryInterface $geometry) {
return $geometry->toWKT();
},
$this->geometries
)
);
return implode(',', array_map(function (GeometryInterface $geometry) {
return $geometry->toWKT();
}, $this->geometries));
}

public static function fromString($wktArgument)
{
$geometry_strings = preg_split('/,\s*(?=[A-Za-z])/', $wktArgument);

return new static(
array_map(
function ($geometry_string) {
$klass = Geometry::getWKTClass($geometry_string);

return call_user_func($klass . '::fromWKT', $geometry_string);
return new static(array_map(function ($geometry_string) {
$klass = Geometry::getWKTClass($geometry_string);

},
$geometry_strings
)
);
return call_user_func($klass.'::fromWKT', $geometry_string);
}, $geometry_strings));
}

public function count()
Expand Down
4 changes: 2 additions & 2 deletions src/Types/GeometryInterface.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
namespace Grimzy\LaravelSpatial\Types;

namespace Grimzy\LaravelMysqlSpatial\Types;

interface GeometryInterface
{
Expand All @@ -10,5 +11,4 @@ public static function fromWKT($wkt);
public function __toString();

public static function fromString($wktArgument);

}
3 changes: 2 additions & 1 deletion src/Types/LineString.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
namespace Grimzy\LaravelSpatial\Types;

namespace Grimzy\LaravelMysqlSpatial\Types;

class LineString extends PointCollection implements GeometryInterface
{
Expand Down
Loading

0 comments on commit b5a90c6

Please sign in to comment.