PHPackages                             sam-it/cs2cs - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. sam-it/cs2cs

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

sam-it/cs2cs
============

Cs2cs wrapper for PHP

v1.0.0(10y ago)01.8kMITPHP

Since Apr 22Pushed 9y ago1 watchersCompare

[ Source](https://github.com/SAM-IT/cs2cs-php)[ Packagist](https://packagist.org/packages/sam-it/cs2cs)[ RSS](/packages/sam-it-cs2cs/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (1)DependenciesVersions (2)Used By (0)

cs2cs-php
=========

[](#cs2cs-php)

Coordinate transformation via PHP and cs2cs

Usage
=====

[](#usage)

```
$cs2cs = new SamIT\Proj4\Cs2cs([
    'proj' => 'sterea',
    'lat_0' => 52.15616055555555,
    'lon_0' => 5.38763888888889,
    'k' => 0.9999079,
    'x_0' => 155000,
    'y_0' => 463000,
    'ellps' => 'bessel',
    'towgs84' => implode(',', [565.417,50.3319,465.552,-0.398957,0.343988,-1.8774,4.0725]),
    'no_defs',
], [
    'proj' => 'longlat',
    'datum' => 'WGS84',
    'no_defs'
], []);

$x = 236296.709;
$y = 590744.631;

$cs2cs->transform($x, $y, function($x, $y, $lon, $lat) use (&$count) {
    $count++;
});
$cs2cs->close();

```

Explanation
===========

[](#explanation)

Cs2cs uses output buffering, instead of writing a line immediately after reading a line from stdin, it waits until its output buffer is full and gets flushed automatically.

To efficiently transform many coordinates, we instead pass a callback that gets called with the result when it becomes available.

Short function doc:
===================

[](#short-function-doc)

```
transform($x, $y, $callback)

```

Sets up a callback that gets called when the transformation of `$x` and `$y` is complete.

```
close()

```

Terminates the cs2cs process, reads all remaining data. This will call all remaining callbacks.

```
read($timeout = 0)

```

Attempts to read data from cs2cs and fires the appropriate callbacks. Mostly used internally. If a timeout is set it will block until data becomes available. Using this can cause deadlocks.

```
blockingTransform($x, $y)

```

If you really need to do the transformation synchronously you can use this. This will write dummy data to cs2cs and force it to flush its buffers. If you just need to transform a single coordinate use `transform()` followed by `flush()` instead. Using this effectively writes 4000 bytes instead of ~25. This is ~10000x slower then doing it asynchronously.

Cloning
=======

[](#cloning)

In case you want to do this even faster (not tested!) the object supports cloning. When a cs2cs object is cloned it creates a new cs2cs process.

Benchmark, blocking vs async.
=============================

[](#benchmark-blocking-vs-async)

Synchronous, note the run size of 100.

```
[Runcount] => 50
[Runsize] => 100
[Blocking] => 1
[Average:] => 1.0074578237534
[Minimum:] => 0.94923281669617
[Maximum:] => 1.6763138771057

```

Asynchronous, note the runsize of 10000.

```
[Runcount] => 50
[Runsize] => 10000
[Blocking] =>
[Average:] => 0.19135624885559
[Minimum:] => 0.17859697341919
[Maximum:] => 0.20333218574524

```

Conclusion: go async.

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3714d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/18b13c534e3812b66a72645fe215301b54fc4d288f6396fee9385b681e27da18?d=identicon)[SamMousa](/maintainers/SamMousa)

---

Top Contributors

[![SamMousa](https://avatars.githubusercontent.com/u/547021?v=4)](https://github.com/SamMousa "SamMousa (13 commits)")

---

Tags

transformationcoordinateproj4cs2csproj

### Embed Badge

![Health badge](/badges/sam-it-cs2cs/health.svg)

```
[![Health](https://phpackages.com/badges/sam-it-cs2cs/health.svg)](https://phpackages.com/packages/sam-it-cs2cs)
```

###  Alternatives

[mjaschen/phpgeo

Simple Yet Powerful Geo Library

1.6k9.1M27](/packages/mjaschen-phpgeo)[spatie/geocoder

Geocoding addresses to coordinates

8425.0M19](/packages/spatie-geocoder)[proj4php/proj4php

A PHP-Class for geographic coordinates transformation using proj4 definitions, thanks to a translation from Proj4JS

1331.9M21](/packages/proj4php-proj4php)[ozdemirburak/iris

PHP library for color manipulation and conversion.

1201.8M20](/packages/ozdemirburak-iris)[spatie/google-time-zone

Get time zones for coordinates

109713.6k1](/packages/spatie-google-time-zone)[ssnepenthe/color-utils

A PHP library for performing SASS-like color manipulations.

631.2M15](/packages/ssnepenthe-color-utils)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
