Skip to content

Commit

Permalink
Add Geometry::withSRID()
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMorel committed Mar 30, 2019
1 parent 3f2bdde commit e778dc0
Show file tree
Hide file tree
Showing 20 changed files with 256 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/CoordinateSystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

/**
* Represents the dimensionality and spatial reference system of a geometry.
*
* This class is immutable.
*/
class CoordinateSystem
{
Expand Down Expand Up @@ -82,7 +84,6 @@ public static function xym(int $srid = 0) : CoordinateSystem
return new self(false, true, $srid);
}


/**
* Returns a CoordinateSystem with X, Y, Z and M coordinates, and an optional SRID.
*
Expand Down Expand Up @@ -179,6 +180,25 @@ public function spatialDimension() : int
return $this->hasZ ? 3 : 2;
}

/**
* Returns a copy of this CoordinateSystem with the SRID altered.
*
* @param int $srid
*
* @return CoordinateSystem
*/
public function withSRID(int $srid) : CoordinateSystem
{
if ($srid === $this->srid) {
return $this;
}

$that = clone $this;
$that->srid = $srid;

return $that;
}

/**
* @param Geometry $reference The geometry holding the reference coordinate system.
* @param Geometry ...$geometries The geometries to check against this coordinate system.
Expand Down
19 changes: 19 additions & 0 deletions src/Geometry.php
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,25 @@ public function coordinateSystem() : CoordinateSystem
return $this->coordinateSystem;
}

/**
* Returns a copy of this Geometry, with the SRID altered.
*
* @param int $srid
*
* @return static
*/
public function withSRID(int $srid) : Geometry
{
if ($srid === $this->SRID()) {
return $this;
}

$that = clone $this;
$that->coordinateSystem = $that->coordinateSystem->withSRID($srid);

return $that;
}

/**
* Returns the raw coordinates of this geometry as an array.
*
Expand Down
12 changes: 12 additions & 0 deletions src/Proxy/CircularStringProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,4 +331,16 @@ public function coordinateSystem() : \Brick\Geo\CoordinateSystem
return $this->proxyGeometry->coordinateSystem();
}

/**
* {@inheritdoc}
*/
public function withSRID(int $srid) : \Brick\Geo\Geometry
{
if ($this->proxyGeometry === null) {
$this->load();
}

return $this->proxyGeometry->withSRID($srid);
}

}
12 changes: 12 additions & 0 deletions src/Proxy/CompoundCurveProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,4 +331,16 @@ public function coordinateSystem() : \Brick\Geo\CoordinateSystem
return $this->proxyGeometry->coordinateSystem();
}

/**
* {@inheritdoc}
*/
public function withSRID(int $srid) : \Brick\Geo\Geometry
{
if ($this->proxyGeometry === null) {
$this->load();
}

return $this->proxyGeometry->withSRID($srid);
}

}
12 changes: 12 additions & 0 deletions src/Proxy/CurvePolygonProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,4 +319,16 @@ public function coordinateSystem() : \Brick\Geo\CoordinateSystem
return $this->proxyGeometry->coordinateSystem();
}

/**
* {@inheritdoc}
*/
public function withSRID(int $srid) : \Brick\Geo\Geometry
{
if ($this->proxyGeometry === null) {
$this->load();
}

return $this->proxyGeometry->withSRID($srid);
}

}
12 changes: 12 additions & 0 deletions src/Proxy/CurveProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,18 @@ public function coordinateSystem() : \Brick\Geo\CoordinateSystem
return $this->proxyGeometry->coordinateSystem();
}

/**
* {@inheritdoc}
*/
public function withSRID(int $srid) : \Brick\Geo\Geometry
{
if ($this->proxyGeometry === null) {
$this->load();
}

return $this->proxyGeometry->withSRID($srid);
}

/**
* {@inheritdoc}
*/
Expand Down
12 changes: 12 additions & 0 deletions src/Proxy/GeometryCollectionProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,4 +319,16 @@ public function coordinateSystem() : \Brick\Geo\CoordinateSystem
return $this->proxyGeometry->coordinateSystem();
}

/**
* {@inheritdoc}
*/
public function withSRID(int $srid) : \Brick\Geo\Geometry
{
if ($this->proxyGeometry === null) {
$this->load();
}

return $this->proxyGeometry->withSRID($srid);
}

}
12 changes: 12 additions & 0 deletions src/Proxy/GeometryProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,18 @@ public function coordinateSystem() : \Brick\Geo\CoordinateSystem
return $this->proxyGeometry->coordinateSystem();
}

/**
* {@inheritdoc}
*/
public function withSRID(int $srid) : \Brick\Geo\Geometry
{
if ($this->proxyGeometry === null) {
$this->load();
}

return $this->proxyGeometry->withSRID($srid);
}

/**
* {@inheritdoc}
*/
Expand Down
12 changes: 12 additions & 0 deletions src/Proxy/LineStringProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,4 +331,16 @@ public function coordinateSystem() : \Brick\Geo\CoordinateSystem
return $this->proxyGeometry->coordinateSystem();
}

/**
* {@inheritdoc}
*/
public function withSRID(int $srid) : \Brick\Geo\Geometry
{
if ($this->proxyGeometry === null) {
$this->load();
}

return $this->proxyGeometry->withSRID($srid);
}

}
12 changes: 12 additions & 0 deletions src/Proxy/MultiCurveProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,4 +319,16 @@ public function coordinateSystem() : \Brick\Geo\CoordinateSystem
return $this->proxyGeometry->coordinateSystem();
}

/**
* {@inheritdoc}
*/
public function withSRID(int $srid) : \Brick\Geo\Geometry
{
if ($this->proxyGeometry === null) {
$this->load();
}

return $this->proxyGeometry->withSRID($srid);
}

}
12 changes: 12 additions & 0 deletions src/Proxy/MultiLineStringProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,4 +319,16 @@ public function coordinateSystem() : \Brick\Geo\CoordinateSystem
return $this->proxyGeometry->coordinateSystem();
}

/**
* {@inheritdoc}
*/
public function withSRID(int $srid) : \Brick\Geo\Geometry
{
if ($this->proxyGeometry === null) {
$this->load();
}

return $this->proxyGeometry->withSRID($srid);
}

}
12 changes: 12 additions & 0 deletions src/Proxy/MultiPointProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,4 +319,16 @@ public function coordinateSystem() : \Brick\Geo\CoordinateSystem
return $this->proxyGeometry->coordinateSystem();
}

/**
* {@inheritdoc}
*/
public function withSRID(int $srid) : \Brick\Geo\Geometry
{
if ($this->proxyGeometry === null) {
$this->load();
}

return $this->proxyGeometry->withSRID($srid);
}

}
12 changes: 12 additions & 0 deletions src/Proxy/MultiPolygonProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,4 +319,16 @@ public function coordinateSystem() : \Brick\Geo\CoordinateSystem
return $this->proxyGeometry->coordinateSystem();
}

/**
* {@inheritdoc}
*/
public function withSRID(int $srid) : \Brick\Geo\Geometry
{
if ($this->proxyGeometry === null) {
$this->load();
}

return $this->proxyGeometry->withSRID($srid);
}

}
12 changes: 12 additions & 0 deletions src/Proxy/MultiSurfaceProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,4 +319,16 @@ public function coordinateSystem() : \Brick\Geo\CoordinateSystem
return $this->proxyGeometry->coordinateSystem();
}

/**
* {@inheritdoc}
*/
public function withSRID(int $srid) : \Brick\Geo\Geometry
{
if ($this->proxyGeometry === null) {
$this->load();
}

return $this->proxyGeometry->withSRID($srid);
}

}
12 changes: 12 additions & 0 deletions src/Proxy/PointProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,4 +319,16 @@ public function coordinateSystem() : \Brick\Geo\CoordinateSystem
return $this->proxyGeometry->coordinateSystem();
}

/**
* {@inheritdoc}
*/
public function withSRID(int $srid) : \Brick\Geo\Geometry
{
if ($this->proxyGeometry === null) {
$this->load();
}

return $this->proxyGeometry->withSRID($srid);
}

}
12 changes: 12 additions & 0 deletions src/Proxy/PolygonProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,4 +319,16 @@ public function coordinateSystem() : \Brick\Geo\CoordinateSystem
return $this->proxyGeometry->coordinateSystem();
}

/**
* {@inheritdoc}
*/
public function withSRID(int $srid) : \Brick\Geo\Geometry
{
if ($this->proxyGeometry === null) {
$this->load();
}

return $this->proxyGeometry->withSRID($srid);
}

}
12 changes: 12 additions & 0 deletions src/Proxy/PolyhedralSurfaceProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,4 +307,16 @@ public function coordinateSystem() : \Brick\Geo\CoordinateSystem
return $this->proxyGeometry->coordinateSystem();
}

/**
* {@inheritdoc}
*/
public function withSRID(int $srid) : \Brick\Geo\Geometry
{
if ($this->proxyGeometry === null) {
$this->load();
}

return $this->proxyGeometry->withSRID($srid);
}

}
12 changes: 12 additions & 0 deletions src/Proxy/SurfaceProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,18 @@ public function coordinateSystem() : \Brick\Geo\CoordinateSystem
return $this->proxyGeometry->coordinateSystem();
}

/**
* {@inheritdoc}
*/
public function withSRID(int $srid) : \Brick\Geo\Geometry
{
if ($this->proxyGeometry === null) {
$this->load();
}

return $this->proxyGeometry->withSRID($srid);
}

/**
* {@inheritdoc}
*/
Expand Down
12 changes: 12 additions & 0 deletions src/Proxy/TINProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,4 +307,16 @@ public function coordinateSystem() : \Brick\Geo\CoordinateSystem
return $this->proxyGeometry->coordinateSystem();
}

/**
* {@inheritdoc}
*/
public function withSRID(int $srid) : \Brick\Geo\Geometry
{
if ($this->proxyGeometry === null) {
$this->load();
}

return $this->proxyGeometry->withSRID($srid);
}

}
12 changes: 12 additions & 0 deletions src/Proxy/TriangleProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,4 +319,16 @@ public function coordinateSystem() : \Brick\Geo\CoordinateSystem
return $this->proxyGeometry->coordinateSystem();
}

/**
* {@inheritdoc}
*/
public function withSRID(int $srid) : \Brick\Geo\Geometry
{
if ($this->proxyGeometry === null) {
$this->load();
}

return $this->proxyGeometry->withSRID($srid);
}

}

0 comments on commit e778dc0

Please sign in to comment.