, (*1)
geojson-rewind
A set of PHP helper classes to assist in generating GeoJSON geometries that are
compliant with the GeoJSON specification., (*2)
Polygon ring order was undefined in the original GeoJSON spec, but since RFC7946 the right hand rule is mandated., (*3)
A linear ring MUST follow the right-hand rule with respect to the area it bounds, i.e., exterior rings are counterclockwise, and holes are clockwise., (*4)
(If you know British English rather than American English, simply substitute anticlockwise for counterclockwise.), (*5)
Acknowledgements
geojson-rewind
is a port to PHP of Mapbox's Node.JS geojson-rewind
module by Tom McWright et al. Full credits, kudos and acknowledgements are due to Tom and the rest of the Mapbox team., (*6)
Install
The easiest way to install geojson-rewind
is by using composer:, (*7)
$> composer require vicchi/geojson-rewind
Usage
'Polygon',
'coordinates' => [
[ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0], [100.0, 0.0] ],
[ [100.2, 0.2], [100.8, 0.2], [100.8, 0.8], [100.2, 0.8], [100.2, 0.2] ]
]
];
$enforce_rfc7946=true;
$output = Vicchi\GeoJson\Rewind::rewind($source, $enforce_rfc7946);
// show output for demonstration purposes
var_dump($output);
?>
The output could look like this ($>
is the command line prompt)., (*8)
$> php test.php
array(2) {
["type"]=>
string(7) "Polygon"
["coordinates"]=>
array(2) {
[0]=>
array(5) {
[0]=>
array(2) {
[0]=>
float(100)
[1]=>
float(0)
}
[1]=>
array(2) {
[0]=>
float(101)
[1]=>
float(0)
}
[2]=>
array(2) {
[0]=>
float(101)
[1]=>
float(1)
}
[3]=>
array(2) {
[0]=>
float(100)
[1]=>
float(1)
}
[4]=>
array(2) {
[0]=>
float(100)
[1]=>
float(0)
}
}
[1]=>
array(5) {
[0]=>
array(2) {
[0]=>
float(100.2)
[1]=>
float(0.2)
}
[1]=>
array(2) {
[0]=>
float(100.2)
[1]=>
float(0.8)
}
[2]=>
array(2) {
[0]=>
float(100.8)
[1]=>
float(0.8)
}
[3]=>
array(2) {
[0]=>
float(100.8)
[1]=>
float(0.2)
}
[4]=>
array(2) {
[0]=>
float(100.2)
[1]=>
float(0.2)
}
}
}
}
License
geojson-rewind
is published under the BSD-3-Clause license. See License File for more information., (*9)