承接 sibyx/phpgpx 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

sibyx/phpgpx

Composer 安装命令:

composer require sibyx/phpgpx

包简介

A simple PHP library for GPX import/export

README 文档

README

Code Climate Latest development Packagist downloads Gitter

Simple library written in PHP for reading and creating GPX files. Documentation is available using GitHub pages generated by Jekyll.

Contribution and feedback is welcome! Please check the issues for TODO. I will be happy every feature or pull request.

Repository branches:

  • master: latest stable version
  • develop: works on 2.x

Features

Supported Extensions

Stats calculation

  • (Smoothed) Distance (m)
  • Average speed (m/s)
  • Average pace (s/km)
  • Min / max altitude (m)
  • Min / max coordinates ([lat,lng])
  • (Smoothed) Elevation gain / loss (m)
  • Start / end (DateTime object)
  • Start / end coordinates ([lat,lng])
  • Duration (seconds)

Installation

You can easily install phpGPX library with composer. There is no stable release yet, so please use release candidates.

composer require sibyx/phpgpx:1.3.0

Examples

Open GPX file and load basic stats

<?php
use phpGPX\phpGPX;

$gpx = new phpGPX();
	
$file = $gpx->load('example.gpx');
	
foreach ($file->tracks as $track)
{
    // Statistics for whole track
    $track->stats->toArray();
    
    foreach ($track->segments as $segment)
    {
    	// Statistics for segment of track
    	$segment->stats->toArray();
    }
}

Writing to file

<?php
use phpGPX\phpGPX;

$gpx = new phpGPX();
	
$file = $gpx->load('example.gpx');

// XML
$file->save('output.gpx', phpGPX::XML_FORMAT);
	
//JSON
$file->save('output.json', phpGPX::JSON_FORMAT);

Creating file from scratch

<?php

use phpGPX\Models\GpxFile;
use phpGPX\Models\Link;
use phpGPX\Models\Metadata;
use phpGPX\Models\Point;
use phpGPX\Models\Segment;
use phpGPX\Models\Track;

require_once '/vendor/autoload.php';

$sample_data = [
	[
		'longitude' => 9.860624216140083,
		'latitude' => 54.9328621088893,
		'elevation' => 0,
		'time' => new \DateTime("+ 1 MINUTE")
	],
	[
		'latitude' => 54.83293237320851,
		'longitude' => 9.76092208681491,
		'elevation' => 10.0,
		'time' => new \DateTime("+ 2 MINUTE")
	],
	[
		'latitude' => 54.73327743521187,
		'longitude' => 9.66187816543752,
		'elevation' => 42.42,
		'time' => new \DateTime("+ 3 MINUTE")
	],
	[
		'latitude' => 54.63342326167919,
		'longitude' => 9.562439849679859,
		'elevation' => 12,
		'time' => new \DateTime("+ 4 MINUTE")
	]
];

// Creating sample link object for metadata
$link = new Link();
$link->href = "https://sibyx.github.io/phpgpx";
$link->text = 'phpGPX Docs';

// GpxFile contains data and handles serialization of objects
$gpx_file = new GpxFile();

// Creating sample Metadata object
$gpx_file->metadata = new Metadata();

// Time attribute is always \DateTime object!
$gpx_file->metadata->time = new \DateTime();

// Description of GPX file
$gpx_file->metadata->description = "My pretty awesome GPX file, created using phpGPX library!";

// Adding link created before to links array of metadata
// Metadata of GPX file can contain more than one link
$gpx_file->metadata->links[] = $link;

// Creating track
$track = new Track();

// Name of track
$track->name = "Some random points in logical order. Input array should be already ordered!";

// Type of data stored in track
$track->type = 'RUN';

// Source of GPS coordinates
$track->source = "MySpecificGarminDevice";

// Creating Track segment
$segment = new Segment();


foreach ($sample_data as $sample_point)
{
	// Creating trackpoint
	$point = new Point(Point::TRACKPOINT);
	$point->latitude = $sample_point['latitude'];
	$point->longitude = $sample_point['longitude'];
	$point->elevation = $sample_point['elevation'];
	$point->time = $sample_point['time'];

	$segment->points[] = $point;
}

// Add segment to segment array of track
$track->segments[] = $segment;

// Recalculate stats based on received data
$track->recalculateStats();

// Add track to file
$gpx_file->tracks[] = $track;

// GPX output
$gpx_file->save('CreatingFileFromScratchExample.gpx', \phpGPX\phpGPX::XML_FORMAT);

// Serialized data as JSON
$gpx_file->save('CreatingFileFromScratchExample.json', \phpGPX\phpGPX::JSON_FORMAT);

// Direct GPX output to browser

header("Content-Type: application/gpx+xml");
header("Content-Disposition: attachment; filename=CreatingFileFromScratchExample.gpx");

echo $gpx_file->toXML()->saveXML();
exit();

Currently, supported output formats:

  • XML
  • JSON

Configuration

Use the static constants in phpGPX to modify behaviour.

/**
 * Create Stats object for each track, segment and route
 */
public static $CALCULATE_STATS = true;

/**
 * Additional sort based on timestamp in Routes & Tracks on XML read.
 * Disabled by default, data should be already sorted.
 */
public static $SORT_BY_TIMESTAMP = false;

/**
 * Default DateTime output format in JSON serialization.
 */
public static $DATETIME_FORMAT = 'c';

/**
 * Default timezone for display.
 * Data are always stored in UTC timezone.
 */
public static $DATETIME_TIMEZONE_OUTPUT = 'UTC';

/**
 * Pretty print.
 */
public static $PRETTY_PRINT = true;

/**
 * In stats elevation calculation: ignore points with an elevation of 0
 * This can happen with some GPS software adding a point with 0 elevation
 */
public static $IGNORE_ELEVATION_0 = true;

/**
 * Apply elevation gain/loss smoothing? If true, the threshold in
 * ELEVATION_SMOOTHING_THRESHOLD and ELEVATION_SMOOTHING_SPIKES_THRESHOLD (if not null) applies
 */
public static $APPLY_ELEVATION_SMOOTHING = false;

/**
 * if APPLY_ELEVATION_SMOOTHING is true
 * the minimum elevation difference between considered points in meters
 */
public static $ELEVATION_SMOOTHING_THRESHOLD = 2;

/**
 * if APPLY_ELEVATION_SMOOTHING is true
 * the maximum elevation difference between considered points in meters
 */
public static $ELEVATION_SMOOTHING_SPIKES_THRESHOLD = null;

/**
 * Apply distance calculation smoothing? If true, the threshold in
 * DISTANCE_SMOOTHING_THRESHOLD applies
 */
public static $APPLY_DISTANCE_SMOOTHING = false;

/**
 * if APPLY_DISTANCE_SMOOTHING is true
 * the minimum distance between considered points in meters
 */
public static $DISTANCE_SMOOTHING_THRESHOLD = 2;

I wrote this library as part of my job in Backbone s.r.o..

License

This project is licensed under the terms of the MIT license.

sibyx/phpgpx 适用场景与选型建议

sibyx/phpgpx 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.23M 次下载、GitHub Stars 达 168, 最近一次更新时间为 2017 年 02 月 20 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「geo」 「parser」 「gpx」 「geospacial」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 sibyx/phpgpx 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 sibyx/phpgpx 我们能提供哪些服务?
定制开发 / 二次开发

基于 sibyx/phpgpx 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.23M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 170
  • 点击次数: 22
  • 依赖项目数: 5
  • 推荐数: 0

GitHub 信息

  • Stars: 168
  • Watchers: 9
  • Forks: 55
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-02-20