diff --git a/lib/CrEOF/Spatial/DBAL/Types/Geometry/MultiPolygonType.php b/lib/CrEOF/Spatial/DBAL/Types/Geometry/MultiPolygonType.php new file mode 100644 index 00000000..bfac7c14 --- /dev/null +++ b/lib/CrEOF/Spatial/DBAL/Types/Geometry/MultiPolygonType.php @@ -0,0 +1,44 @@ + + * @license http://dlambert.mit-license.org MIT + */ +class MultiPolygonType extends GeometryType +{ + /** + * {@inheritdoc} + */ + public function getSQLType() + { + return GeometryInterface::MULTIPOLYGON; + } +} diff --git a/lib/CrEOF/Spatial/PHP/Types/AbstractGeometry.php b/lib/CrEOF/Spatial/PHP/Types/AbstractGeometry.php index f35a16c1..20f0a1bc 100644 --- a/lib/CrEOF/Spatial/PHP/Types/AbstractGeometry.php +++ b/lib/CrEOF/Spatial/PHP/Types/AbstractGeometry.php @@ -92,6 +92,9 @@ protected function validatePointValue($point) case (is_array($point) && count($point) == 2 && is_numeric($point[0]) && is_numeric($point[1])): return array_values($point); break; + case (is_array($point) && count($point) > 2 && is_array($point[0])): + return array_values($point); + break; default: throw InvalidValueException::invalidType($this, GeometryInterface::POINT, $point); } diff --git a/lib/CrEOF/Spatial/PHP/Types/AbstractMultiPolygon.php b/lib/CrEOF/Spatial/PHP/Types/AbstractMultiPolygon.php new file mode 100644 index 00000000..8f364d77 --- /dev/null +++ b/lib/CrEOF/Spatial/PHP/Types/AbstractMultiPolygon.php @@ -0,0 +1,121 @@ + + * @license http://dlambert.mit-license.org MIT + */ +abstract class AbstractMultiPolygon extends AbstractGeometry +{ + /** + * @var array[] $rings + */ + protected $rings = array(); + + /** + * @param AbstractLineString[]|array[] $rings + * @param null|int $srid + */ + public function __construct(array $rings, $srid = null) + { + $this->setRings($rings) + ->setSrid($srid); + } + + /** + * @param AbstractLineString|array[] $ring + * + * @return self + */ + public function addRing($ring) + { + $this->rings[] = $this->validateRingValue($ring); + + return $this; + } + + /** + * @return AbstractLineString[] + */ + public function getRings() + { + $rings = array(); + + for ($i = 0; $i < count($this->rings); $i++) { + $rings[] = $this->getRing($i); + } + + return $rings; + } + + /** + * @param int $index + * + * @return AbstractLineString + */ + public function getRing($index) + { + if (-1 == $index) { + $index = count($this->rings) - 1; + } + + $lineStringClass = $this->getNamespace() . '\LineString'; + + return new $lineStringClass($this->rings[$index], $this->srid); + } + + /** + * @param AbstractLineString[] $rings + * + * @return self + */ + public function setRings(array $rings) + { + $this->rings = $this->validatePolygonValue($rings); + + return $this; + } + + /** + * @return string + */ + public function getType() + { + return self::POLYGON; + } + + /** + * @return array[] + */ + public function toArray() + { + return $this->rings; + } +} diff --git a/lib/CrEOF/Spatial/PHP/Types/Geometry/MultiPolygon.php b/lib/CrEOF/Spatial/PHP/Types/Geometry/MultiPolygon.php new file mode 100644 index 00000000..ff5ee3c3 --- /dev/null +++ b/lib/CrEOF/Spatial/PHP/Types/Geometry/MultiPolygon.php @@ -0,0 +1,37 @@ + + * @license http://dlambert.mit-license.org MIT + */ +class MultiPolygon extends AbstractMultiPolygon +{ + +}