chillerlan/php-geojson-helpers

2.0.0 2023-01-08 15:13 UTC

This package is auto-updated.

Last update: 2024-12-08 19:40:12 UTC


README

PHP Version Support version license Continuous Integration Coverage Scrunitizer Packagist downloads

Documentation

Requirements

Installation

requires composer

composer.json (note: replace dev-master with a version boundary)

{
	"require": {
		"php": "^7.4 || ^8.0",
		"chillerlan/php-geojson-helpers": "dev-master"
	}
}

Profit!

Usage

FeatureCollection

$featureCollection = (new FeatureCollection)->setBbox([0, 0, 1024, 1024]);

// add a single feature
$feature = new Feature([512, 512], 'Point', 1);
$featureCollection->addFeature($feature);

// add an iterable of features
$featureCollection->addFeatures([$feature, /* ... more features ... */]);

// create the GeoJSON, feed leaflet
$json = $featureCollection->toJSON();

// as of v2.x via JsonSerializable
$json = json_encode($featureCollection);
{
    "type":"FeatureCollection",
    "bbox":[0, 0, 1024, 1024],
    "features":[
        {
            "type":"Feature",
            "geometry":{
                "type":"Point",
                "coordinates":[512, 512]
            },
            "properties":{
                "id":1
            }
        }
    ]
}

PolylineSimplifyer

$polylineCoords = [[11, 12], [21, 22], [31, 32], /* ... */];

$ps             = new PolylineSimplifyer($polylineCoords);
$simplified     = $ps->simplify(5, true);

API

Feature methods

FeatureCollection methods

common methods to Feature and FeatureCollection

ContinentRect

PolylineSimplifyer