PHPackages                             daandesmedt/phpwktadapter - 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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. daandesmedt/phpwktadapter

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

daandesmedt/phpwktadapter
=========================

Read and parse 2D, 3D and 4D WKT (Well Known Text) / EWKT (Extended Well-Known Text) object strings into geometry objects with this simple WKT PHP adapter library.

v1.0.0(6y ago)01.0k1MITPHPPHP &gt;=7.0

Since Jul 19Pushed 2y agoCompare

[ Source](https://github.com/DaanDeSmedt/PHPWKTParser)[ Packagist](https://packagist.org/packages/daandesmedt/phpwktadapter)[ RSS](/packages/daandesmedt-phpwktadapter/feed)WikiDiscussions dev Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (3)Used By (0)

PHPWKTParser
============

[](#phpwktparser)

Well-known text (WKT) is a text markup language for representing vector geometry objects on a map, spatial reference systems of spatial objects and transformations between spatial reference systems.

EWKT (Extended Well-Known Text), a PostGIS-specific format that includes the spatial reference system identifier (SRID) and up to 4 ordinate values (XYZM), is also supported (ex: `SRID=31370;POINT(44 60)`).

`PHPWKTParser` provides a simple usage helper class to read WKT and EWKT and parse this text representation to a workable PHP array holding the parsed WKT/EWKT definition. Read and parse 2D, 3D and 4D WKT (Well Known Text) / EWKT (Extended Well-Known Text) object strings into geometry objects with this simple WKT PHP adapter library.

Installation
------------

[](#installation)

Install the package through [composer](http://getcomposer.org):

```
composer require daandesmedt/phpwktadapter

```

Make sure, that you include the composer [autoloader](https://getcomposer.org/doc/01-basic-usage.md#autoloading) somewhere in your codebase.

Supported geometry
------------------

[](#supported-geometry)

Geometry TypeExamplePOINTPOINT(30 10)LNESTRINGLINESTRING(30 10, 10 30, 40 40)POLYGONPOLYGON((0 0,10 0,10 10,0 10,0 0))MULTIPOINTMULTIPOINTZM(0 0 10 10,10 0 0 0,10 10 0 0,20 20 0 10)MULTILINESTRINGMULTILINESTRING((0 0,10 0,10 10,0 10))MULTIPOLYGONMULTIPOLYGON(((40 40, 20 45, 45 30, 40 40)), ((20 35, 10 30, 10 10, 30 5, 45 20, 20 35), (30 20, 20 15, 20 25, 30 20)))GEOMETRYCOLLECTIONGEOMETRYCOLLECTION(POINT(10 20),LINESTRING(0 0,10 0))PHPWKTParser parsed and returned geometry array response
--------------------------------------------------------

[](#phpwktparser-parsed-and-returned-geometry-array-response)

The `read($wkt)` function of the `PHPWKTParser` adapter will return a associative array as representation of the parsed WKT/EWKT (in case of valid).

```
array(
    // the geometry object type
    "type"      =>  string,
    // integer or float values for POINT - nested array (integer or float) for other geometry types
    "value"     =>  array,
    // integer representing the EWKT SRID, null when not present
    "srid"      =>  integer | null,
    // string (Z, M or ZM) representing the dimension, null when not present
    "dimension" =>  string | null
)

```

Working examples
----------------

[](#working-examples)

Working examples can be found in the `examples` folder.

Sample usage
------------

[](#sample-usage)

```
