chillerlan / php-geojson-helpers
PHP 7.2+
Fund package maintenance!
Ko Fi
www.paypal.com/donate?hosted_button_id=WLYUNAT9ZTJZ4
Installs: 1 826
Dependents: 1
Suggesters: 0
Security: 0
Stars: 2
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: ^7.4 || ^8.0
- ext-json: *
Requires (Dev)
- phan/phan: ^5.4
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-11-08 19:30:22 UTC
README
Documentation
Requirements
- PHP 7.4+
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);