Giter VIP home page Giter VIP logo

daandesmedt / phpwktparser Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 1.0 10 KB

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.

License: MIT License

PHP 100.00%
php7 php wkt wkt-strings ewkt geometry geometric-shapes spatial well-known-text

phpwktparser's Introduction

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

Install the package through composer:

composer require daandesmedt/phpwktadapter

Make sure, that you include the composer autoloader somewhere in your codebase.

Supported geometry

Geometry Type Example
POINT POINT(30 10)
LNESTRING LINESTRING(30 10, 10 30, 40 40)
POLYGON POLYGON((0 0,10 0,10 10,0 10,0 0))
MULTIPOINT MULTIPOINTZM(0 0 10 10,10 0 0 0,10 10 0 0,20 20 0 10)
MULTILINESTRING MULTILINESTRING((0 0,10 0,10 10,0 10))
MULTIPOLYGON MULTIPOLYGON(((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)))
GEOMETRYCOLLECTION GEOMETRYCOLLECTION(POINT(10 20),LINESTRING(0 0,10 0))

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 can be found in the examples folder.

Sample usage

<?php 

require __DIR__ . '/../vendor/autoload.php';

use daandesmedt\PHPWKTAdapter\WKTAdapter;

$adapter = new WKTAdapter();
$res = $adapter->read('SRID=31370;POINT(30 10)');
var_dump($res); 

Handling exceptions

Invalid format in the specified WKT / EWKT will result in a UnexpectedValueException thrown by the WKTAdapter .

<?php 

require __DIR__ . '/../vendor/autoload.php';

use daandesmedt\PHPWKTAdapter\WKTAdapter;

$adapter = new WKTAdapter();

try {
    $res = $adapter->read('SRID=31370;POINT(bad format)');
} catch (UnexpectedValueException $e) {
    var_dump($e->getMessage());
}

phpwktparser's People

Contributors

daandesmedt avatar

Watchers

 avatar

Forkers

prezent

phpwktparser's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.