Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Kml Parser Laravel Package

plin-code/kml-parser

Parse KML and KMZ files in Laravel to extract placemarks, styles, style maps, and document metadata. Simple installation, configurable namespace and temp directory, with a clean API for reading geographic data.

View on GitHub
Deep Wiki
Context7

Laravel KML Parser

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

A simple Laravel package to parse KML and KMZ files, extracting geographic data in a convenient format.

Installation

You can install the package via composer:

composer require plin-code/kml-parser

You can publish the config file with:

php artisan vendor:publish --tag="kml-parser-config"

This is the contents of the published config file:

return [
    /*
    |--------------------------------------------------------------------------
    | Default KML Namespace
    |--------------------------------------------------------------------------
    |
    | This value is the default namespace used for parsing KML files.
    | Usually you don't need to change this.
    |
    */
    'namespace' => 'http://www.opengis.net/kml/2.2',
    
    /*
    |--------------------------------------------------------------------------
    | Temporary Directory
    |--------------------------------------------------------------------------
    |
    | This value determines the temporary directory used for extracting KMZ files.
    | If null, the system temp directory will be used.
    |
    */
    'temp_directory' => null,
];

Usage

Basic Usage

use PlinCode\KmlParser\KmlParser;

// Parse a KML file
$parser = new KmlParser();
$parser->loadFromFile('path/to/file.kml');

// Get placemarks (points of interest)
$placemarks = $parser->getPlacemarks();

// Get styles
$styles = $parser->getStyles();

// Get style maps
$styleMaps = $parser->getStyleMaps();

// Get document name and description
$name = $parser->getDocumentName();
$description = $parser->getDocumentDescription();

// Convert to GeoJSON
$geoJson = $parser->toGeoJson();

Working with KMZ Files

KMZ files are ZIP archives that contain a KML file and possibly other assets like images:

// Parse a KMZ file
$parser = new KmlParser();
$parser->loadFromKmz('path/to/file.kmz');

// Work with the data just like with KML
$placemarks = $parser->getPlacemarks();

Extract all files from a KMZ:

use PlinCode\KmlParser\KmzExtractor;

$extractor = new KmzExtractor();
$files = $extractor->extractAllFiles('path/to/file.kmz', 'extraction/directory');

Facade Usage

You can also use the provided facade:

use PlinCode\KmlParser\Facades\KmlParser;

$placemarks = KmlParser::loadFromFile('path/to/file.kml')->getPlacemarks();

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
andydefer/laravel-notification
adachsoft/cli-process-tester
jhaskell13/laraflow
sebastienheyd/boilerplate-media-manager
ccast/tagixo-primix
pretendtrue/laravel-builder
sawmainek/laravel-scout-tntsearch-driver
tomshaw/laravel-calendar-table
dibakar/laravel-ownership
steadrun/laravel-monitor
labyrinthe/connect-laravel
elmogy/layan
drewdan/sentinel-client
dskripchenko/laravel-llm
fatryst/nuonuo
stevenay/myanfont
gmostafa/php-graphql-client
xeviant/paystack
snowsoft/faker
meditationsteps/blogetc