2017 © Pedro Peláez
 

library geojson-rewind

PHP helper classes to enforce RFC7946 polygon winding order in GeoJSON

image

vicchi/geojson-rewind

PHP helper classes to enforce RFC7946 polygon winding order in GeoJSON

  • Friday, February 9, 2018
  • by vicchi
  • Repository
  • 0 Watchers
  • 1 Stars
  • 4 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 100 % Grown

The README.md

Build Status, (*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)

The Versions

09/02 2018

dev-master

9999999-dev

PHP helper classes to enforce RFC7946 polygon winding order in GeoJSON

  Sources   Download

BSD-3-Clause

The Requires

 

php geojson polygon winding order

09/02 2018

v1.0.0

1.0.0.0

PHP helper classes to enforce RFC7946 polygon winding order in GeoJSON

  Sources   Download

BSD-3-Clause

The Requires

 

php geojson polygon winding order