{"id":21650746,"url":"https://github.com/alexboia/kml-for-php","last_synced_at":"2026-02-12T13:05:58.736Z","repository":{"id":246797132,"uuid":"822118059","full_name":"alexboia/KML-for-PHP","owner":"alexboia","description":"PHP Kml Library","archived":false,"fork":false,"pushed_at":"2025-01-28T14:26:55.000Z","size":57,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-07T20:33:39.451Z","etag":null,"topics":["kml","library","parser","php","processor"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alexboia.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-06-30T10:47:38.000Z","updated_at":"2025-01-21T09:54:57.000Z","dependencies_parsed_at":null,"dependency_job_id":"1bbe9fa0-34af-4bc2-b19c-b037f152ccc6","html_url":"https://github.com/alexboia/KML-for-PHP","commit_stats":null,"previous_names":["alexboia/kml-for-php"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexboia%2FKML-for-PHP","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexboia%2FKML-for-PHP/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexboia%2FKML-for-PHP/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexboia%2FKML-for-PHP/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexboia","download_url":"https://codeload.github.com/alexboia/KML-for-PHP/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252953718,"owners_count":21830891,"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":["kml","library","parser","php","processor"],"created_at":"2024-11-25T07:42:24.625Z","updated_at":"2026-02-12T13:05:53.710Z","avatar_url":"https://github.com/alexboia.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003eKML for PHP library (KamelPhp)\u003c/h1\u003e\r\n\r\nA PHP KML parser library initially developed as part of the [WP-Trip-Summary WordPress plug-in](https://github.com/alexboia/WP-Trip-Summary/). \r\nIt is based on [Stepan Daleky's KML parser on GitLab](https://gitlab.com/stepandalecky/kml-parser) and has now been extracted as a separate library to ease up on the code base a bit.\r\n\r\n## About\r\n\r\nSupported KML entities:\r\n\r\n- `Kml` class (`\u003ckml\u003e` root element);\r\n- `Folder` and `Document` classes (and elements) as `Container` types and direct children of the KML root;\r\n- Abstract `Feature` class and element, with support for the following attributes: `id`, `styleUrl`, `name`, `description`, `open`, `visibility`, `address`, `phoneNumber`;\r\n- `Placemark` class and element, with support for `Point`, `Linestring`, `LinearRing`, `Polygon` and `MultiGeometry` geometries as well as `Style` and `ExtendedData`.\r\n\r\n## Installation\r\n\r\nInstall the latest version with:\r\n\r\n```\r\ncomposer require myclar/kamel-php\r\n```\r\n\r\n### Using the parser directly\r\n\r\nThe parser class simply parses a KML string (or a file that contains a KML string) and returns an object graph:\r\n\r\n```PHP\r\nuse KamelPhp\\KmlParser\\Parser;\r\n\r\n$kmlParser = Parser::fromString($fileContents);\r\n//OR\r\n$kmlParser = Parser::fromFile($filePath);\r\n\r\n//And then get the KML root and do your thing with it.\r\n$kml = $kmlParser-\u003egetKml();\r\n```\r\n\r\nSome samples:\r\n- The built-in [`Processor`](https://github.com/alexboia/KML-for-PHP/blob/main/src/KmlParser/Processor.php)\r\n- The [current set of tests for the parser class](https://github.com/alexboia/KML-for-PHP/blob/main/tests/LibKmlParserTests.php)\r\n\r\n### Using the processor\r\n\r\nThe [processor class](https://github.com/alexboia/KML-for-PHP/blob/main/src/KmlParser/Processor.php) provides a simple and expedient way of traversing a KML document, while allowing a certain degree of customization. Its usage is not mandatory.\r\n\r\nLimitations:\r\n\r\n- Either root KML folder or root KML document is considered, not both (first it checks for a root folder and, if not found for a root document);\r\n- A KML container is searched, in this order, for: folders, documents and placemarks;\r\n- Neither folder, nor document metadata is stored;\r\n- For a placemark, only the name and description metadata items are stored and reported;\r\n- Order in which various document parts are processed cannot be altered;\r\n- Visibility, as specified by the `visibility` feature attribute, is not accounted for.\r\n\r\nIn order to use the processor, you need to provide a mandatory delegate (a class implementing [`KamelPhp\\KmlParser\\Processor\\Delegate`](https://github.com/alexboia/KML-for-PHP/blob/main/src/KmlParser/Processor/Delegate.php)) which you can use to:\r\n\r\n- control what gets reported back to you (`Delegate::shouldXYZ()` methods, e.g. return `false` from `Delegate::shouldProcessPointGeometry()` if you do not what to have KML points sent back to you.);\r\n- process KML primitives as they are found and reported back to you (e.g. implement `Delegate::processPoint()` to process KML points);\r\n- react when processing begins (`Delegate::begin()`) and ends (`Delegate::end()`);\r\n- react when an error occurs (`Delegate::error()`).\r\n\r\nAs it may already be obvious, the way it works sort of breaks the tree structure, but that's perfectly acceptable in my use case - obtain relevant geometries for simple map drawing.\r\n\r\nIt's up to yo what the delegate does, either it stores the artefacts somewhere or it builds some representation in memory and provides a way to access it at the end. See [here an example implementation](https://github.com/alexboia/WP-Trip-Summary/blob/master/lib/route/track/documentParser/kml/LibKmlProcessorDelegate.php).\r\n\r\n```PHP\r\nuse KamelPhp\\KmlParser\\Parser;\r\n\r\n$delegate = new MyDelegate();\r\n$processor = new Processor($delegate);\r\n$processor-\u003eprocessKmlString($sourceString);\r\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexboia%2Fkml-for-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexboia%2Fkml-for-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexboia%2Fkml-for-php/lists"}