{"id":16894295,"url":"https://github.com/jsor/geokit","last_synced_at":"2025-04-12T20:44:19.016Z","repository":{"id":1779570,"uuid":"2702522","full_name":"jsor/geokit","owner":"jsor","description":"Geo-Toolkit for PHP.","archived":false,"fork":false,"pushed_at":"2022-02-10T08:05:30.000Z","size":397,"stargazers_count":248,"open_issues_count":8,"forks_count":28,"subscribers_count":15,"default_branch":"main","last_synced_at":"2025-03-23T07:34:11.464Z","etag":null,"topics":["bounds","distance","geo","geography","geometry","latlng","php","polygon"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jsor.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2011-11-03T14:30:11.000Z","updated_at":"2024-11-13T22:25:02.000Z","dependencies_parsed_at":"2022-09-07T15:21:01.859Z","dependency_job_id":null,"html_url":"https://github.com/jsor/geokit","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsor%2Fgeokit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsor%2Fgeokit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsor%2Fgeokit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jsor%2Fgeokit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jsor","download_url":"https://codeload.github.com/jsor/geokit/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248631687,"owners_count":21136556,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bounds","distance","geo","geography","geometry","latlng","php","polygon"],"created_at":"2024-10-13T17:18:16.654Z","updated_at":"2025-04-12T20:44:18.991Z","avatar_url":"https://github.com/jsor.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Geokit\n======\n\nGeokit is a PHP toolkit to solve geo-related tasks like:\n\n* Distance calculations.\n* Heading, midpoint and endpoint calculations.\n* Rectangular bounding box calculations.\n\n[![Build Status](https://github.com/jsor/geokit/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/jsor/geokit/actions/workflows/ci.yml)\n[![Coverage Status](https://coveralls.io/repos/jsor/geokit/badge.svg?branch=main\u0026service=github)](https://coveralls.io/github/jsor/geokit?branch=main)\n\n* [Installation](#installation)\n* [Reference](#reference)\n    * [Distance](#distance)\n    * [Position](#position)\n    * [BoundingBox](#boundingbox)\n    * [Polygon](#polygon)\n    * [Functions](#functions)\n        * [Distance calculations](#distance-calculations)\n        * [Transformations](#transformations)\n        * [Other calculations](#other-calculations)\n* [License](#license)\n\nInstallation\n------------\n\nInstall the latest version with [Composer](https://getcomposer.org).\n\n```bash\ncomposer require geokit/geokit\n```\n\nCheck the [Packagist page](https://packagist.org/packages/geokit/geokit) for all\navailable versions.\n\nReference\n---------\n\n### Distance\n\nA Distance instance allows for a convenient representation of a distance unit of\nmeasure.\n\n```php\nuse Geokit\\Distance;\n\n$distance = new Distance(1000); // Defaults to meters\n// or\n$distance = new Distance(1, Distance::UNIT_KILOMETERS);\n\n$meters = $distance-\u003emeters();\n$kilometers = $distance-\u003ekilometers();\n$miles = $distance-\u003emiles();\n$yards = $distance-\u003eyards();\n$feet = $distance-\u003efeet();\n$inches = $distance-\u003einches();\n$nauticalMiles = $distance-\u003enautical();\n```\n\nA Distance can also be created from a string with an optional unit.\n\n```php\nuse Geokit\\Distance;\n\n$distance = Distance::fromString('1000'); // Defaults to meters\n$distance = Distance::fromString('1000m');\n$distance = Distance::fromString('1km');\n$distance = Distance::fromString('100 miles');\n$distance = Distance::fromString('100 yards');\n$distance = Distance::fromString('1 foot');\n$distance = Distance::fromString('1 inch');\n$distance = Distance::fromString('234nm');\n```\n\n### Position\n\nA `Position` is a fundamental construct representing a geographical position in\n`x` (or `longitude`) and `y` (or `latitude`) coordinates.\n\nNote, that `x`/`y` coordinates are kept as is, while `longitude`/`latitude` are\nnormalized.\n\n* Longitudes range between -180 and 180 degrees, inclusive. Longitudes above 180\n  or below -180 are normalized. For example, 480, 840 and 1200 will all be\n  normalized to 120 degrees.\n* Latitudes range between -90 and 90 degrees, inclusive. Latitudes above 90 or\n  below -90 are normalized. For example, 100 will be normalized to 80 degrees.\n\n```php\nuse Geokit\\Position;\n\n$position = new Position(181, 91);\n\n$x = $position-\u003ex(); // Returns 181.0\n$y = $position-\u003ey(); // Returns 91.0\n$longitude = $position-\u003elongitude(); // Returns -179.0, normalized\n$latitude = $position-\u003elatitude(); // Returns 89.0, normalized\n```\n\n### BoundingBox\n\nA BoundingBox instance represents a rectangle in geographical coordinates,\nincluding one that crosses the 180 degrees longitudinal meridian.\n\nIt is constructed from its left-bottom (south-west) and right-top (north-east)\ncorner points.\n\n```php\nuse Geokit\\BoundingBox;\nuse Geokit\\Position;\n\n$southWest = Position::fromXY(2, 1);\n$northEast = Position::fromXY(2, 1);\n\n$boundingBox = BoundingBox::fromCornerPositions($southWest, $northEast);\n\n$southWestPosition = $boundingBox-\u003esouthWest();\n$northEastPosition = $boundingBox-\u003enorthEast();\n\n$center = $boundingBox-\u003ecenter();\n\n$span = $boundingBox-\u003espan();\n\n$boolean = $boundingBox-\u003econtains($position);\n\n$newBoundingBox = $boundingBox-\u003eextend($position);\n$newBoundingBox = $boundingBox-\u003eunion($otherBoundingBox);\n```\n\nWith the `expand()` and `shrink()` methods, you can expand or shrink a\nBoundingBox instance by a distance.\n\n```php\nuse Geokit\\Distance;\n\n$expandedBoundingBox = $boundingBox-\u003eexpand(\n    Distance::fromString('10km')\n);\n\n$shrinkedBoundingBox = $boundingBox-\u003eshrink(\n    Distance::fromString('10km')\n);\n```\n\nThe `toPolygon()` method converts the BoundingBox to an equivalent Polygon\ninstance.\n\n```php\n$polygon = $boundingBox-\u003etoPolygon();\n```\n\n### Polygon\n\nA Polygon instance represents a two-dimensional shape of connected line segments\nand may either be closed (the first and last point are the same) or open.\n\n```php\nuse Geokit\\BoundingBox;\nuse Geokit\\Polygon;\nuse Geokit\\Position;\n\n$polygon = Polygon::fromPositions(\n    Position::fromXY(0, 0),\n    Position::fromXY(1, 0),\n    Position::fromXY(1, 1)\n);\n\n$closedPolygon = $polygon-\u003eclose();\n\n/** @var Position $position */\nforeach ($polygon as $position) {\n}\n\n$polygon-\u003econtains(Position::fromXY(0.5, 0.5)); // true\n\n/** @var BoundingBox $boundingBox */\n$boundingBox = $polygon-\u003etoBoundingBox();\n```\n\n### Functions\n\nGeokit provides several functions to perform geographic calculations.\n\n#### Distance calculations\n\n* `distanceHaversine(Position $from, Position $to)`:\n  Calculates the approximate sea level great circle (Earth) distance between two\n  points using the Haversine formula.\n* `distanceVincenty(Position $from, Position $to)`:\n  Calculates the geodetic distance between two points using the Vincenty inverse\n  formula for ellipsoids.\n\n```php\nuse function Geokit\\distanceHaversine;\nuse function Geokit\\distanceVincenty;\n\n$distance1 = distanceHaversine($from, $to);\n$distance2 = distanceVincenty($from, $to);\n```\n\nBoth functions return a [Distance](#distance) instance.\n\n#### Transformations\n\nThe `circle()` function calculates a closed circle Polygon given a center,\nradius and steps for precision.\n\n```php\nuse Geokit\\Distance;\nuse Geokit\\Position;\nuse function Geokit\\circle;\n\n$circlePolygon = circle(\n    Position::fromXY(8.50207515, 49.50042565), \n    Distance::fromString('5km'),\n    32\n);\n```\n\n#### Other calculations\n\nOther useful functions are:\n\n* `heading(Position $from, Position $to)`: Calculates the (initial) heading from\n  the first point to the second point in degrees.\n* `midpoint(Position $from, Position $to)`: Calculates an intermediate point on\n  the geodesic between the two given points.\n* `endpoint(Position $start, float $heading, Geokit\\Distance $distance)`:\n  Calculates the destination point along a geodesic, given an initial heading\n  and distance, from the given start point.\n\nLicense\n-------\n\nCopyright (c) 2011-2022 Jan Sorgalla.\nReleased under the [MIT License](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsor%2Fgeokit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjsor%2Fgeokit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjsor%2Fgeokit/lists"}