{"id":29420004,"url":"https://github.com/allebb/cartographer","last_synced_at":"2025-07-12T01:15:17.980Z","repository":{"id":62491432,"uuid":"65943609","full_name":"allebb/cartographer","owner":"allebb","description":"Cartographer is a PHP library for constructing GeoJSON objects.","archived":false,"fork":false,"pushed_at":"2022-12-28T12:11:56.000Z","size":110,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-23T12:22:09.264Z","etag":null,"topics":["geojson","geometry","google-maps-api","json","latlng","linestring","maps","markers","multilinestring","php","polygon","polygons"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/allebb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-08-17T21:35:14.000Z","updated_at":"2024-01-07T10:48:56.000Z","dependencies_parsed_at":"2023-01-31T06:31:03.482Z","dependency_job_id":null,"html_url":"https://github.com/allebb/cartographer","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/allebb/cartographer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/allebb%2Fcartographer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/allebb%2Fcartographer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/allebb%2Fcartographer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/allebb%2Fcartographer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/allebb","download_url":"https://codeload.github.com/allebb/cartographer/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/allebb%2Fcartographer/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264922929,"owners_count":23683707,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["geojson","geometry","google-maps-api","json","latlng","linestring","maps","markers","multilinestring","php","polygon","polygons"],"created_at":"2025-07-12T01:15:16.997Z","updated_at":"2025-07-12T01:15:17.895Z","avatar_url":"https://github.com/allebb.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cartographer\n\n[![Build](https://github.com/allebb/cartographer/workflows/build/badge.svg)](https://github.com/allebb/cartographer/actions)\n[![Code Coverage](https://codecov.io/gh/allebb/cartographer/branch/master/graph/badge.svg)](https://codecov.io/gh/allebb/cartographer)\n[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/allebb/cartographer/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/allebb/cartographer/?branch=master)\n[![Code Climate](https://codeclimate.com/github/allebb/cartographer/badges/gpa.svg)](https://codeclimate.com/github/allebb/cartographer)\n[![Latest Stable Version](https://poser.pugx.org/ballen/cartographer/v/stable)](https://packagist.org/packages/ballen/cartographer)\n[![Latest Unstable Version](https://poser.pugx.org/ballen/cartographer/v/unstable)](https://packagist.org/packages/ballen/cartographer)\n[![License](https://poser.pugx.org/ballen/cartographer/license)](https://packagist.org/packages/ballen/cartographer)\n\nCartographer is a PHP library providing the ability to programmatically generate GeoJSON objects.\n\nGeoJSON is a format for encoding a variety of geographic data structures. A GeoJSON object may represent a geometry, a feature, or a collection of features. GeoJSON supports the following geometry types: ``Point``, ``LineString``, ``Polygon``, ``MultiPoint``, ``MultiLineString``, ``MultiPolygon``, and ``GeometryCollection``. Features in GeoJSON contain a geometry object and additional properties, and a feature collection represents a list of features.\n\nCartographer was written to adhere to the GeoJSON specification, information can be found here: http://geojson.org/geojson-spec.html\n\nRequirements\n------------\n\n* PHP \u003e= 7.3.0\n\nThis library is unit tested against PHP 7.3, 7.4, 8.0, 8.1 and 8.2!\n\nIf you need to use an older version of PHP, you should instead install the 1.x version of this library (see below for details).\n\nLicense\n-------\n\nThis client library is released under the [GPLv3](https://raw.githubusercontent.com/allebb/cartographer/master/LICENSE) license, you are welcome to use it, improve it and contribute your changes back!\n\nInstallation\n------------\n\nThe recommended way of installing this library is via. [Composer](http://getcomposer.org); To install using Composer type the following command at the console:\n\n```shell\ncomposer require ballen/cartographer\n```\n\n**If you need to use an older version of PHP, version 1.x.x supports PHP 5.3, 5.4, 5.5, 5.6, 7.0, 7.1 and 7.2, you can install this version using Composer with this command instead:**\n\n```shell\ncomposer require ballen/cartographer ^1.0\n```\n\nExample usage\n-------------\n\n### Point\n\nThe \"Point\" type is the most basic to construct, this example shows an example of plotting a single point on a map.\n\n```php\nuse Ballen\\Cartographer\\Core\\LatLong;\nuse Ballen\\Cartographer\\Point;\n\n$point = new Point(new LatLong(52.005523, 1.045936));\necho $point-\u003egenerate();\n// {\"type\":\"Point\",\"coordinates\":[1.045936,52.005523]}\n```\n\nCheck out the GitHub Gist rendition of the GeoJSON output: https://gist.github.com/allebb/55f059efbd708be130112b6d39b16406\n\n### Linestring\n\nThe \"LineString\" type contains a list of geographic points (Lat/Longs) of which are joined together to display a line.\n\n```php\nuse Ballen\\Cartographer\\Core\\LatLong;\nuse Ballen\\Cartographer\\LineString;\n\n$points = [\n    new LatLong(51.973683,1.044497),\n    new LatLong(51.974067,1.044134),\n    new LatLong(51.974355,1.045795),\n    new LatLong(51.975010,1.049768),\n    new LatLong(51.976018,1.055869),\n    new LatLong(51.976195,1.056060),\n    new LatLong(51.976432,1.056083),\n    new LatLong(51.976774,1.056036),\n    new LatLong(51.977023,1.056115),\n    new LatLong(51.977107,1.056379),\n    new LatLong(51.977102,1.056658),\n ];\n$linestring = new LineString($points);\necho $linestring-\u003egenerate();\n// {\"type\":\"LineString\",\"coordinates\":[[1.044497,51.973683],[1.044134,51.974067],[1.045795,51.974355],[1.049768,51.97501],[1.055869,51.976018],[1.05606,51.976195],[1.056083,51.976432],[1.056036,51.976774],[1.056115,51.977023],[1.056379,51.977107],[1.056658,51.977102]]}\n```\n\nCheck out the GitHub Gist rendition of the GeoJSON output: https://gist.github.com/allebb/ec422a00b877e28a3d6913df68c5954c\n\n#### Polygon\n\nA Polygon type object, contains a list of coordinates, the first and last coordinate must match. For Polygons with multiple rings, the first must be the exterior ring and any others must be interior rings or holes.\n\n```php\nuse Ballen\\Cartographer\\Core\\LatLong;\nuse Ballen\\Cartographer\\Polygon;\nuse Ballen\\Cartographer\\Core\\LinearRing;\n\n$points = [\n    (new LatLong(52.064761, 1.174470))-\u003elngLatArray(),\n    (new LatLong(52.065045, 1.176098))-\u003elngLatArray(),\n    (new LatLong(52.064964, 1.176156))-\u003elngLatArray(),\n    (new LatLong(52.065172, 1.177106))-\u003elngLatArray(),\n    (new LatLong(52.064146, 1.177594))-\u003elngLatArray(),\n    (new LatLong(52.063968, 1.176768))-\u003elngLatArray(),\n    (new LatLong(52.063714, 1.174875))-\u003elngLatArray(),\n    (new LatLong(52.064761, 1.174470))-\u003elngLatArray(),\n];\n$linestring = new Polygon((new LinearRing())-\u003eaddRing($points));\necho $linestring-\u003egenerate();\n// {\"type\":\"Polygon\",\"coordinates\":[[[1.17447,52.064761],[1.176098,52.065045],[1.176156,52.064964],[1.177106,52.065172],[1.177594,52.064146],[1.176768,52.063968],[1.174875,52.063714],[1.17447,52.064761]]]}\n```\n\nCheck out the GitHub Gist rendition of the GeoJSON object: https://gist.github.com/allebb/30dd0db2a33b763309e64af8cfe3e33c\n\n#### Feature\n\nA feature enables you to plot a single GeoJSON object on a map with associated properties, Google Maps enable you to render ``Feature`` and ``FeatureCollection`` types.\n\nA example of a ``Point`` feature type is as follows:\n\n```php\nuse Ballen\\Cartographer\\Core\\LatLong;\nuse Ballen\\Cartographer\\Feature;\nuse Ballen\\Cartographer\\Point;\n\n$feature = new Feature(new Point(new LatLong(52.063186, 1.157385)), [\n    // Your own personal marker points (appear when you click on the Feature point)\n    'Park' =\u003e 'Christchurch Park',\n    'Post code' =\u003e 'IP4 2BX',\n    'Link' =\u003e 'http://focp.org.uk/',\n    // Optional Mapbox supported properties (See: https://www.mapbox.com/help/markers/)\n    'marker-color' =\u003e '#3bb2d0', // A light blue marker colour\n    'marker-symbol' =\u003e 'park',\n    'marker-size' =\u003e 'large',\n]);\necho $feature-\u003egenerate();\n// {\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[1.157385,52.063186]},\"properties\":{\"Park\":\"Christchurch Park\",\"Post code\":\"IP4 2BX\",\"Link\":\"http:\\/\\/focp.org.uk\\/\",\"marker-color\":\"#3bb2d0\",\"marker-symbol\":\"park\",\"marker-size\":\"large\"}}\n```\n\nCheck out the GitHub Gist rendition of the GeoJSON output: https://gist.github.com/allebb/a1dfa013273cc75ce061a13250ae6683\n\n#### Feature Collection\n\nA feature collection can contain any number of GeoJSON objects with their own properties, all of the features in a collection with their own properties.\n\n```php\nuse Ballen\\Cartographer\\Core\\LatLong;\nuse Ballen\\Cartographer\\Feature;\nuse Ballen\\Cartographer\\Point;\n\n$park = new Feature(new Point(new LatLong(52.063186, 1.157385)), [\n    // Your own personal marker points (appear when you click on the Feature point)\n    'Park' =\u003e 'Christchurch Park',\n    'Post code' =\u003e 'IP4 2BX',\n    'Link' =\u003e 'http://focp.org.uk/',\n    // Optional Mapbox supported properties (See: https://www.mapbox.com/help/markers/)\n    'marker-color' =\u003e '#3bb2d0', // A light blue marker colour\n    'marker-symbol' =\u003e 'park',\n    'marker-size' =\u003e 'large',\n]);\n\n// Train Station Specific codes\n$station_properties = [\n    'marker-color' =\u003e '#F6546A',\n    'marker-symbol' =\u003e 'rail',\n    'marker-size' =\u003e 'medium'\n];\n\n// Set some train stations with their own names (merge the standard train station details)\n$station_central = new Feature(new Point(new LatLong(52.050743, 1.143012)), array_merge($station_properties, ['Name' =\u003e 'Ipswich Train Station']));\n$station_derbyroad = new Feature(new Point(new LatLong(52.050808, 1.182638)), array_merge($station_properties, ['Name' =\u003e 'Derby Road Station']));\n$station_westerfield = new Feature(new Point(new LatLong(52.081026, 1.166773)), array_merge($station_properties, ['Name' =\u003e 'Westerfield Train Station']));\n\n// Create the new collection and add each of the GeoJSON objects to it...\n$collection = new Ballen\\Cartographer\\FeatureCollection([$station_central, $park, $station_westerfield, $station_derbyroad]);\necho $collection-\u003egenerate();\n// {\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[1.143012,52.050743]},\"properties\":{\"marker-color\":\"#F6546A\",\"marker-symbol\":\"rail\",\"marker-size\":\"medium\",\"Name\":\"Ipswich Train Station\"}},{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[1.157385,52.063186]},\"properties\":{\"Park\":\"Christchurch Park\",\"Post code\":\"IP4 2BX\",\"Link\":\"http:\\/\\/focp.org.uk\\/\",\"marker-color\":\"#3bb2d0\",\"marker-symbol\":\"park\",\"marker-size\":\"large\"}},{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[1.166773,52.081026]},\"properties\":{\"marker-color\":\"#F6546A\",\"marker-symbol\":\"rail\",\"marker-size\":\"medium\",\"Name\":\"Westerfield Train Station\"}},{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[1.182638,52.050808]},\"properties\":{\"marker-color\":\"#F6546A\",\"marker-symbol\":\"rail\",\"marker-size\":\"medium\",\"Name\":\"Derby Road Station\"}}]}\n```\n\nCheck out the GitHub Gist rendition of the GeoJSON output: https://gist.github.com/allebb/1802d538814ed0875ab05060a439b774\n\n#### Other examples\n\nOther examples of the types of GeoJSON object type, see the [examples/test.php](https://github.com/allebb/cartographer/blob/master/examples/test.php) file.\n\nTests and coverage\n------------------\n\nThis library is fully unit tested using [PHPUnit](https://phpunit.de/).\n\nI use [GitHub Actions](https://github.com/) for continuous integration, which triggers tests for PHP 7.3, 7.4, 8.0, 8.1 and 8.2 each time a commit is pushed.\n\nIf you wish to run the tests yourself you should run the following:\n\n```shell\n# Install the Cartographer Library (which will include PHPUnit as part of the require-dev dependencies)\ncomposer install\n\n# Now we run the unit tests (from the root of the project) like so:\n./vendor/bin/phpunit\n```\n\nCode coverage can also be run, and a report generated (this does require XDebug to be installed)...\n\n```shell\n./vendor/bin/phpunit --coverage-html ./report\n```\n\nSupport\n-------\n\nI am happy to provide support via. my personal email address, so if you need a hand drop me an email at: [ballen@bobbyallen.me](mailto:ballen@bobbyallen.me).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fallebb%2Fcartographer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fallebb%2Fcartographer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fallebb%2Fcartographer/lists"}