ronappleton / php-geojson
GeoJSON object builder.
Requires
- php: >=8.1
Requires (Dev)
- stematic/testing: dev-develop
This package is auto-updated.
Last update: 2024-11-10 03:31:09 UTC
README
GeoJSON object builder.
Introduction
This library is a simple builder for GeoJSON objects for use within php.
The inspiration for this is another project I am working on Tile38 PHP Client in that project part of the requirement is valid GeoJSON objects, so this library is being made to fulfill that requirement.
For more information about GeoJSON objects, please see This Website or the official RFC 7946
The initial release of this library, will provide the functionality for use within the Tile38 project, the subsequent release will be to ensure full implementation of the rfc, and then the 3rd release will provide unserialisation of GeoJSON data, back into objects.
Installation
Please use composer to pull in the package composer require ronappleton/php-geojson
please note that this library requires php ^8.1, I may at some point release for php ^7.4 but for the moment it is ^8.1, if anyone would like to branch this to other php versions, I will assist.
Usage
The library provides:
RonAppleton\GeoJson\Enums\GeoJsonType::class RonAppleton\GeoJson\Objects\BoundingBox::class RonAppleton\GeoJson\Objects\Feature::class RonAppleton\GeoJson\Objects\FeatureCollection::class RonAppleton\GeoJson\Objects\GeometryCollection::class RonAppleton\GeoJson\Objects\LineString::class RonAppleton\GeoJson\Objects\MultiLineString::class RonAppleton\GeoJson\Objects\MultiPoint::class RonAppleton\GeoJson\Objects\MultiPolygon::class RonAppleton\GeoJson\Objects\Point::class RonAppleton\GeoJson\Objects\Polygon::class
It also provides a factory for convenience, this is RonAppleton\GeoJson\Objects\Factory::class
Using the factory provides a simple interface for creating the objects:
$point = Factory::make(GeoJsonType::Point);
And when making LineStrings for example, you can also pass a count as the second parameter to the factory:
[$point, $point2, $point3, $point4] = Factory::make(Point::class, 4);
All objects provide a toArray()
method and a toJson()
method, when making objects of combined types, like Polygons etc, the toArray and toJson methods cascade through all objects so they will all be converted automatically.