Skip to content

Commit

Permalink
Add geo spatial blueprint methods
Browse files Browse the repository at this point in the history
  • Loading branch information
antonkomarev committed Sep 7, 2017
1 parent c276af8 commit 8f92b9f
Show file tree
Hide file tree
Showing 7 changed files with 600 additions and 0 deletions.
88 changes: 88 additions & 0 deletions src/Illuminate/Database/Schema/Blueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -924,6 +924,94 @@ public function macAddress($column)
return $this->addColumn('macAddress', $column);
}

/**
* Create a new geometry column on the table.
*
* @param string $column
* @return \Illuminate\Support\Fluent
*/
public function geometry($column)
{
return $this->addColumn('geometry', $column);
}

/**
* Create a new point column on the table.
*
* @param string $column
* @return \Illuminate\Support\Fluent
*/
public function point($column)
{
return $this->addColumn('point', $column);
}

/**
* Create a new linestring column on the table.
*
* @param string $column
* @return \Illuminate\Support\Fluent
*/
public function lineString($column)
{
return $this->addColumn('linestring', $column);
}

/**
* Create a new polygon column on the table.
*
* @param string $column
* @return \Illuminate\Support\Fluent
*/
public function polygon($column)
{
return $this->addColumn('polygon', $column);
}

/**
* Create a new geometrycollection column on the table.
*
* @param string $column
* @return \Illuminate\Support\Fluent
*/
public function geometryCollection($column)
{
return $this->addColumn('geometrycollection', $column);
}

/**
* Create a new multipoint column on the table.
*
* @param string $column
* @return \Illuminate\Support\Fluent
*/
public function multiPoint($column)
{
return $this->addColumn('multipoint', $column);
}

/**
* Create a new multilinestring column on the table.
*
* @param string $column
* @return \Illuminate\Support\Fluent
*/
public function multiLineString($column)
{
return $this->addColumn('multilinestring', $column);
}

/**
* Create a new multipolygon column on the table.
*
* @param string $column
* @return \Illuminate\Support\Fluent
*/
public function multiPolygon($column)
{
return $this->addColumn('multipolygon', $column);
}

/**
* Add the proper columns for a polymorphic table.
*
Expand Down
88 changes: 88 additions & 0 deletions src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,94 @@ protected function typeMacAddress(Fluent $column)
return 'varchar(17)';
}

/**
* Create the column definition for a geometry type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
public function typeGeometry(Fluent $column)
{
return 'geometry';
}

/**
* Create the column definition for a point type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
public function typePoint(Fluent $column)
{
return 'point';
}

/**
* Create the column definition for a linestring type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
public function typeLinestring(Fluent $column)
{
return 'linestring';
}

/**
* Create the column definition for a polygon type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
public function typePolygon(Fluent $column)
{
return 'polygon';
}

/**
* Create the column definition for a geometrycollection type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
public function typeGeometrycollection(Fluent $column)
{
return 'geometrycollection';
}

/**
* Create the column definition for a multipoint type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
public function typeMultipoint(Fluent $column)
{
return 'multipoint';
}

/**
* Create the column definition for a multilinestring type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
public function typeMultilinestring(Fluent $column)
{
return 'multilinestring';
}

/**
* Create the column definition for a multipolygon type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
public function typeMultipolygon(Fluent $column)
{
return 'multipolygon';
}

/**
* Get the SQL for a generated virtual column modifier.
*
Expand Down
97 changes: 97 additions & 0 deletions src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,103 @@ protected function typeMacAddress(Fluent $column)
return 'macaddr';
}

/**
* Create the column definition for a geometry type.
*
* @param \Illuminate\Support\Fluent $column
* @throws \Exception
*/
protected function typeGeometry(Fluent $column)
{
throw new \Exception('Geometry data type not supported for current database engine.');
}

/**
* Create the column definition for a point type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typePoint(Fluent $column)
{
return $this->formatPostGisType('point');
}

/**
* Create the column definition for a linestring type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeLinestring(Fluent $column)
{
return $this->formatPostGisType('linestring');
}

/**
* Create the column definition for a polygon type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typePolygon(Fluent $column)
{
return $this->formatPostGisType('polygon');
}

/**
* Create the column definition for a geometrycollection type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeGeometrycollection(Fluent $column)
{
return $this->formatPostGisType('geometrycollection');
}

/**
* Create the column definition for a multipoint type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeMultipoint(Fluent $column)
{
return $this->formatPostGisType('multipoint');
}

/**
* Create the column definition for a multilinestring type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
public function typeMultilinestring(Fluent $column)
{
return $this->formatPostGisType('multilinestring');
}

/**
* Create the column definition for a multipolygon type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
protected function typeMultipolygon(Fluent $column)
{
return $this->formatPostGisType('multipolygon');
}

/**
* @param string $type
* @return string
*/
private function formatPostGisType(string $type)
{
return "geography({$type}, 4326)";
}

/**
* Get the SQL for a nullable column modifier.
*
Expand Down
88 changes: 88 additions & 0 deletions src/Illuminate/Database/Schema/Grammars/SQLiteGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,94 @@ protected function typeMacAddress(Fluent $column)
return 'varchar';
}

/**
* Create the column definition for a geometry type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
public function typeGeometry(Fluent $column)
{
return 'geometry';
}

/**
* Create the column definition for a point type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
public function typePoint(Fluent $column)
{
return 'point';
}

/**
* Create the column definition for a linestring type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
public function typeLinestring(Fluent $column)
{
return 'linestring';
}

/**
* Create the column definition for a polygon type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
public function typePolygon(Fluent $column)
{
return 'polygon';
}

/**
* Create the column definition for a geometrycollection type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
public function typeGeometrycollection(Fluent $column)
{
return 'geometrycollection';
}

/**
* Create the column definition for a multipoint type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
public function typeMultipoint(Fluent $column)
{
return 'multipoint';
}

/**
* Create the column definition for a multilinestring type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
public function typeMultilinestring(Fluent $column)
{
return 'multilinestring';
}

/**
* Create the column definition for a multipolygon type.
*
* @param \Illuminate\Support\Fluent $column
* @return string
*/
public function typeMultipolygon(Fluent $column)
{
return 'multipolygon';
}

/**
* Get the SQL for a nullable column modifier.
*
Expand Down
Loading

0 comments on commit 8f92b9f

Please sign in to comment.