定制 plin-code/kml-parser 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

plin-code/kml-parser

Composer 安装命令:

composer require plin-code/kml-parser

包简介

A Laravel package to parse KML and KMZ files

README 文档

README

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.

统计信息

  • 总下载量: 2.3k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-08

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固