定制 hular369/geo-shapify 二次开发

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

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

hular369/geo-shapify

Composer 安装命令:

composer require hular369/geo-shapify

包简介

A PHP library that allows to check if a coordinate(lat,long) is inside or outside of a country or a circle or a polygon, calculate area occupied by a polygon/circle, and find out the nearest vertex of a country or a polygon from a given point.

README 文档

README

This package enables you to check if a coordinate is inside a defined boundary of a country or a polygon. It also provides a feature to calculate the area of a given boundary defined by a country or a polygon coordinates (latitude, longitude), and also for circles.

Features

  • Country Boundaries:

    • Check if a coordinate is inside a country.
    • Determine which boundary coordinate is nearest to a given point(lat, long),
    • Calculate the area of a country.
  • Polygon Boundaries:

    • Check if a coordinate is inside a polygon.
    • Calculate the area of a polygon.
  • Circular Boundaries:

    • Check if a coordinate is inside a circle defined by a center and radius.
    • Calculate the area of a circle.

Usage

For Countries and Polygons:

  1. Define the polygon coordinates.
  2. Create a polygon shape using ShapeFactory.
  3. Check if a coordinate is inside the polygon using contains.
  4. Calculate the area of the polygon using area.

For Circles:

  1. Create a circle shape using ShapeFactory with center coordinates and radius.
  2. Check if a coordinate is inside the circle using contains.
  3. Calculate the area of the circle using area.

This package enables you to check if a coordinate is inside a defined boundary of a polygon. It also facilitates with a feature to calculate area of a given boundary defined by polygon coordinates (Lat,long).

To work features on countries, you can implement as follows:

Note: currently the feature is available only for 'norway', 'sweden', 'finland', 'denmark', 'germany', 'lithuania', 'nepal'.

<?php

// Create a polygon shape
$drawCountry = ShapeFactory::create('sweden');

// Check if a point is inside the polygon
$isInside = $drawCountry->contains(56.701853, 12.319418);

// Calculate the area of the polygon
$area = $drawCountry->area();

// get nearest vertex of the polygon
$nearestVertex = $drawCountry->nearestVertex(57.322011, 11.229478)

To create and work with polygons, you can use the ShapeFactory class as follows:

<?php
// Define the coordinates of the polygon vertices
$egpt = [
    [31.597741, 25.112545], 
    [22.152357, 24.958816], 
    [22.081148, 36.719048], 
    [31.269823, 31.338550]
];


// Create a polygon shape
$drawShape = ShapeFactory::create('polygon', $egpt);

// Check if a point is inside the polygon
$isInside = $drawShape->contains(27.701853, 85.319418);

// Calculate the area of the polygon
$area = $drawShape->area();

// get nearest vertex of the polygon
$nearestVertex = $drawShape->nearestVertex(27.701853, 85.319418)

// Output the results
echo "Nearest vertex of the polygon: " . json_encode($nearestVertex) . PHP_EOL;
echo "Is inside: " . ($isInside ? "Yes" : "No") . PHP_EOL;
echo "Area: " . $area . PHP_EOL;
?>

For circles:
<?php
// Create a ShapeFactory instance
$shape = new ShapeFactory();

// Create a circle shape with center coordinates and radius
$drawShape = $shape::create('circle', null, 27.710258, 85.279664, 10); // radius=10 in km

// Check if a point is inside the circle
$isInside = $drawShape->contains(27.710258, 85.279664);

// Calculate the area of the circle
$area = $drawShape->area(); // area in sq. km

// Output the results
echo "Is inside: " . ($isInside ? "Yes" : "No") . PHP_EOL;
echo "Area: " . $area . PHP_EOL;
?>; 

hular369/geo-shapify 适用场景与选型建议

hular369/geo-shapify 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 09 月 17 日, 在 PHP 生态内属于活跃度较高的组件。

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

围绕 hular369/geo-shapify 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 11
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 27
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-09-17