ffogarasi / kmz-parser
Turn KML file into objects
1.1.2
2023-05-08 15:57 UTC
Requires
- php: >=7.0
Requires (Dev)
- phpunit/phpunit: ^6.5
README
The most intuitive KML parser. Each part of the file is represented by a special class, so everything you need is accessible via predictable and hinted methods.
Installation
Using composer:
composer require ffogarasi/kmz-parser
Usage
A simple example, how to use the parser:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2" id="test">
<Document>
<name>Document name</name>
<description>Description</description>
<Style id="icon-1899-0288D1-normal">
# ...
</Style>
<Style id="icon-1899-0288D1-highlight">
# ...
</Style>
<StyleMap id="icon-1899-0288D1">
# ...
</StyleMap>
<Folder>
<name>Unnamed layer</name>
# ...
</Folder>
</Document>
</kml>
use StepanDalecky\KmlParser\Parser;
$parser = Parser::fromFile('file.xml');
// $parser = Parser::fromString($xmlString);
$kml = $parser->getKml();
$document = $kml->getDocument();
$styles = $document->getStyles();
echo $styles[0]->getId(); // icon-1899-0288D1-normal
$folders = $document->getFolders();
echo $folders[0]->getName(); // Unnamed layer
For more examples see the tests.
Unsupported KML Elements?
Custom development of this library is not planned anymore. There are two ways to deal with elements that have not been covered yet:
- Fork this library, add elements you need and create a merge request back to this library.
- Use emergency method
Entity::getElement()
.