Skip to content

Spatial fields not getting validated #105

Closed
@khooz

Description

@khooz

Since this package ignores SRID, it cannot explicitly validate input data, but, it is useful to include some level of data validation/transformation. for instance. a Long > 180 being reduced by 360 or Long < -180 being increased by 360 until it falls within range if a Lat/Long validation is used.

However, I am trying to add some SRID awareness to the package and soon will provide a PR for SRID. the main catch there was the parser used PostGIS EWKB formatting. I just transformed the $wkb to match that formatting. here's the code for that

In src/Types/Geometry.php:

// in Geometry class
protected $srid = 0;

public function getSRID()
{
	return $this->srid;
}

// in fromWKB
$bom		= unpack('C', substr($wkb, 4, 5));
$formatter	= $bom ? 'V' : 'N';
$srid		= unpack($formatter, substr($wkb, 0, 4))[1];
$type		= unpack($formatter, substr($wkb, 5, 9))[1];
$wkb		= substr($wkb, 9);
if ($srid)
{
	$type	|= GeoIO\WKB\Parser\Parser::MASK_SRID;
	$wkb	= pack('C', $bom) . pack($formatter, $type) . pack($formatter, $srid) . $wkb;
}
else
{
	$wkb	= pack('C', $bom) . pack($formatter, $type) . $wkb;
}

I also added $srid = null as the last parameter (as stated in Factory) of every type constructor available. This will provide $srid access for geometries. It is more complicated for public function setSRID(int $srid) since transformation between different (at least major) projections should be implemented.

The SRID is important because a point is not always a Lat/Long pair. It is an (X, Y, Z, M) vector in the specification, and some SRIDs treat (X, Y) as (Lat, Long) and some others may use (X, Y) as (Long, Lat); while others may be Cartesian projections.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions