Skip to content

Commit 8f92b9f

Browse files
committed
Add geo spatial blueprint methods
1 parent c276af8 commit 8f92b9f

7 files changed

+600
-0
lines changed

src/Illuminate/Database/Schema/Blueprint.php

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -924,6 +924,94 @@ public function macAddress($column)
924924
return $this->addColumn('macAddress', $column);
925925
}
926926

927+
/**
928+
* Create a new geometry column on the table.
929+
*
930+
* @param string $column
931+
* @return \Illuminate\Support\Fluent
932+
*/
933+
public function geometry($column)
934+
{
935+
return $this->addColumn('geometry', $column);
936+
}
937+
938+
/**
939+
* Create a new point column on the table.
940+
*
941+
* @param string $column
942+
* @return \Illuminate\Support\Fluent
943+
*/
944+
public function point($column)
945+
{
946+
return $this->addColumn('point', $column);
947+
}
948+
949+
/**
950+
* Create a new linestring column on the table.
951+
*
952+
* @param string $column
953+
* @return \Illuminate\Support\Fluent
954+
*/
955+
public function lineString($column)
956+
{
957+
return $this->addColumn('linestring', $column);
958+
}
959+
960+
/**
961+
* Create a new polygon column on the table.
962+
*
963+
* @param string $column
964+
* @return \Illuminate\Support\Fluent
965+
*/
966+
public function polygon($column)
967+
{
968+
return $this->addColumn('polygon', $column);
969+
}
970+
971+
/**
972+
* Create a new geometrycollection column on the table.
973+
*
974+
* @param string $column
975+
* @return \Illuminate\Support\Fluent
976+
*/
977+
public function geometryCollection($column)
978+
{
979+
return $this->addColumn('geometrycollection', $column);
980+
}
981+
982+
/**
983+
* Create a new multipoint column on the table.
984+
*
985+
* @param string $column
986+
* @return \Illuminate\Support\Fluent
987+
*/
988+
public function multiPoint($column)
989+
{
990+
return $this->addColumn('multipoint', $column);
991+
}
992+
993+
/**
994+
* Create a new multilinestring column on the table.
995+
*
996+
* @param string $column
997+
* @return \Illuminate\Support\Fluent
998+
*/
999+
public function multiLineString($column)
1000+
{
1001+
return $this->addColumn('multilinestring', $column);
1002+
}
1003+
1004+
/**
1005+
* Create a new multipolygon column on the table.
1006+
*
1007+
* @param string $column
1008+
* @return \Illuminate\Support\Fluent
1009+
*/
1010+
public function multiPolygon($column)
1011+
{
1012+
return $this->addColumn('multipolygon', $column);
1013+
}
1014+
9271015
/**
9281016
* Add the proper columns for a polymorphic table.
9291017
*

src/Illuminate/Database/Schema/Grammars/MySqlGrammar.php

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,94 @@ protected function typeMacAddress(Fluent $column)
677677
return 'varchar(17)';
678678
}
679679

680+
/**
681+
* Create the column definition for a geometry type.
682+
*
683+
* @param \Illuminate\Support\Fluent $column
684+
* @return string
685+
*/
686+
public function typeGeometry(Fluent $column)
687+
{
688+
return 'geometry';
689+
}
690+
691+
/**
692+
* Create the column definition for a point type.
693+
*
694+
* @param \Illuminate\Support\Fluent $column
695+
* @return string
696+
*/
697+
public function typePoint(Fluent $column)
698+
{
699+
return 'point';
700+
}
701+
702+
/**
703+
* Create the column definition for a linestring type.
704+
*
705+
* @param \Illuminate\Support\Fluent $column
706+
* @return string
707+
*/
708+
public function typeLinestring(Fluent $column)
709+
{
710+
return 'linestring';
711+
}
712+
713+
/**
714+
* Create the column definition for a polygon type.
715+
*
716+
* @param \Illuminate\Support\Fluent $column
717+
* @return string
718+
*/
719+
public function typePolygon(Fluent $column)
720+
{
721+
return 'polygon';
722+
}
723+
724+
/**
725+
* Create the column definition for a geometrycollection type.
726+
*
727+
* @param \Illuminate\Support\Fluent $column
728+
* @return string
729+
*/
730+
public function typeGeometrycollection(Fluent $column)
731+
{
732+
return 'geometrycollection';
733+
}
734+
735+
/**
736+
* Create the column definition for a multipoint type.
737+
*
738+
* @param \Illuminate\Support\Fluent $column
739+
* @return string
740+
*/
741+
public function typeMultipoint(Fluent $column)
742+
{
743+
return 'multipoint';
744+
}
745+
746+
/**
747+
* Create the column definition for a multilinestring type.
748+
*
749+
* @param \Illuminate\Support\Fluent $column
750+
* @return string
751+
*/
752+
public function typeMultilinestring(Fluent $column)
753+
{
754+
return 'multilinestring';
755+
}
756+
757+
/**
758+
* Create the column definition for a multipolygon type.
759+
*
760+
* @param \Illuminate\Support\Fluent $column
761+
* @return string
762+
*/
763+
public function typeMultipolygon(Fluent $column)
764+
{
765+
return 'multipolygon';
766+
}
767+
680768
/**
681769
* Get the SQL for a generated virtual column modifier.
682770
*

src/Illuminate/Database/Schema/Grammars/PostgresGrammar.php

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,103 @@ protected function typeMacAddress(Fluent $column)
605605
return 'macaddr';
606606
}
607607

608+
/**
609+
* Create the column definition for a geometry type.
610+
*
611+
* @param \Illuminate\Support\Fluent $column
612+
* @throws \Exception
613+
*/
614+
protected function typeGeometry(Fluent $column)
615+
{
616+
throw new \Exception('Geometry data type not supported for current database engine.');
617+
}
618+
619+
/**
620+
* Create the column definition for a point type.
621+
*
622+
* @param \Illuminate\Support\Fluent $column
623+
* @return string
624+
*/
625+
protected function typePoint(Fluent $column)
626+
{
627+
return $this->formatPostGisType('point');
628+
}
629+
630+
/**
631+
* Create the column definition for a linestring type.
632+
*
633+
* @param \Illuminate\Support\Fluent $column
634+
* @return string
635+
*/
636+
protected function typeLinestring(Fluent $column)
637+
{
638+
return $this->formatPostGisType('linestring');
639+
}
640+
641+
/**
642+
* Create the column definition for a polygon type.
643+
*
644+
* @param \Illuminate\Support\Fluent $column
645+
* @return string
646+
*/
647+
protected function typePolygon(Fluent $column)
648+
{
649+
return $this->formatPostGisType('polygon');
650+
}
651+
652+
/**
653+
* Create the column definition for a geometrycollection type.
654+
*
655+
* @param \Illuminate\Support\Fluent $column
656+
* @return string
657+
*/
658+
protected function typeGeometrycollection(Fluent $column)
659+
{
660+
return $this->formatPostGisType('geometrycollection');
661+
}
662+
663+
/**
664+
* Create the column definition for a multipoint type.
665+
*
666+
* @param \Illuminate\Support\Fluent $column
667+
* @return string
668+
*/
669+
protected function typeMultipoint(Fluent $column)
670+
{
671+
return $this->formatPostGisType('multipoint');
672+
}
673+
674+
/**
675+
* Create the column definition for a multilinestring type.
676+
*
677+
* @param \Illuminate\Support\Fluent $column
678+
* @return string
679+
*/
680+
public function typeMultilinestring(Fluent $column)
681+
{
682+
return $this->formatPostGisType('multilinestring');
683+
}
684+
685+
/**
686+
* Create the column definition for a multipolygon type.
687+
*
688+
* @param \Illuminate\Support\Fluent $column
689+
* @return string
690+
*/
691+
protected function typeMultipolygon(Fluent $column)
692+
{
693+
return $this->formatPostGisType('multipolygon');
694+
}
695+
696+
/**
697+
* @param string $type
698+
* @return string
699+
*/
700+
private function formatPostGisType(string $type)
701+
{
702+
return "geography({$type}, 4326)";
703+
}
704+
608705
/**
609706
* Get the SQL for a nullable column modifier.
610707
*

src/Illuminate/Database/Schema/Grammars/SQLiteGrammar.php

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,94 @@ protected function typeMacAddress(Fluent $column)
641641
return 'varchar';
642642
}
643643

644+
/**
645+
* Create the column definition for a geometry type.
646+
*
647+
* @param \Illuminate\Support\Fluent $column
648+
* @return string
649+
*/
650+
public function typeGeometry(Fluent $column)
651+
{
652+
return 'geometry';
653+
}
654+
655+
/**
656+
* Create the column definition for a point type.
657+
*
658+
* @param \Illuminate\Support\Fluent $column
659+
* @return string
660+
*/
661+
public function typePoint(Fluent $column)
662+
{
663+
return 'point';
664+
}
665+
666+
/**
667+
* Create the column definition for a linestring type.
668+
*
669+
* @param \Illuminate\Support\Fluent $column
670+
* @return string
671+
*/
672+
public function typeLinestring(Fluent $column)
673+
{
674+
return 'linestring';
675+
}
676+
677+
/**
678+
* Create the column definition for a polygon type.
679+
*
680+
* @param \Illuminate\Support\Fluent $column
681+
* @return string
682+
*/
683+
public function typePolygon(Fluent $column)
684+
{
685+
return 'polygon';
686+
}
687+
688+
/**
689+
* Create the column definition for a geometrycollection type.
690+
*
691+
* @param \Illuminate\Support\Fluent $column
692+
* @return string
693+
*/
694+
public function typeGeometrycollection(Fluent $column)
695+
{
696+
return 'geometrycollection';
697+
}
698+
699+
/**
700+
* Create the column definition for a multipoint type.
701+
*
702+
* @param \Illuminate\Support\Fluent $column
703+
* @return string
704+
*/
705+
public function typeMultipoint(Fluent $column)
706+
{
707+
return 'multipoint';
708+
}
709+
710+
/**
711+
* Create the column definition for a multilinestring type.
712+
*
713+
* @param \Illuminate\Support\Fluent $column
714+
* @return string
715+
*/
716+
public function typeMultilinestring(Fluent $column)
717+
{
718+
return 'multilinestring';
719+
}
720+
721+
/**
722+
* Create the column definition for a multipolygon type.
723+
*
724+
* @param \Illuminate\Support\Fluent $column
725+
* @return string
726+
*/
727+
public function typeMultipolygon(Fluent $column)
728+
{
729+
return 'multipolygon';
730+
}
731+
644732
/**
645733
* Get the SQL for a nullable column modifier.
646734
*

0 commit comments

Comments
 (0)