Skip to content

Commit

Permalink
Merge pull request phayes#93 from mprins/travis-ci
Browse files Browse the repository at this point in the history
Add a Travis-ci configuration
  • Loading branch information
phayes committed Nov 30, 2014
2 parents d5b508a + d90eff9 commit b2465be
Show file tree
Hide file tree
Showing 18 changed files with 187 additions and 149 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/vendor
27 changes: 27 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# docs available at http://docs.travis-ci.com/user/languages/php/
# example available at https://github.com/travis-ci/travis-ci-php-example
language: php

before_script:
- composer self-update

install:
- composer install
# TODO optionally install geos library
# TODO optionally set up a postgis database for testing

script: cd tests && phpunit --verbose --colors --stderr tests

# run tests on the following versions
php:
- 5.6
- 5.5
- 5.4
- 5.3
- hhvm

matrix:
fast_finish: false
allow_failures:
# php 5.3 does not support random file list as an argument to scandir
- php: 5.3
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@
{
"name":"Patrick Hayes"
}
]
],
"require-dev": {
"phpunit/phpunit": "4.1.*"
}
}
4 changes: 2 additions & 2 deletions lib/adapters/KML.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,11 @@ public function write(Geometry $geometry, $namespace = FALSE) {
}

public function geomFromText($text) {

// Change to lower-case and strip all CDATA
$text = mb_strtolower($text, mb_detect_encoding($text));
$text = preg_replace('/<!\[cdata\[(.*?)\]\]>/s','',$text);

// Load into DOMDOcument
// Load into DOMDocument
$xmlobj = new DOMDocument();
@$xmlobj->loadXML($text);
if ($xmlobj === false) {
Expand Down Expand Up @@ -235,6 +234,7 @@ private function linestringToKML($geom, $type = FALSE) {

public function polygonToKML($geom) {
$components = $geom->getComponents();
$str = '';
if (!empty($components)) {
$str = '<'.$this->nss.'outerBoundaryIs>' . $this->linestringToKML($components[0], 'LinearRing') . '</'.$this->nss.'outerBoundaryIs>';
foreach (array_slice($components, 1) as $comp) {
Expand Down
62 changes: 34 additions & 28 deletions lib/adapters/WKT.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/
class WKT extends GeoAdapter
{

/**
* Read WKT string into geometry objects
*
Expand All @@ -14,7 +14,7 @@ class WKT extends GeoAdapter
*/
public function read($wkt) {
$wkt = trim($wkt);

// If it contains a ';', then it contains additional SRID data
if (strpos($wkt,';')) {
$parts = explode(';', $wkt);
Expand All @@ -25,7 +25,7 @@ public function read($wkt) {
else {
$srid = NULL;
}

// If geos is installed, then we take a shortcut and let it parse the WKT
if (geoPHP::geosInstalled()) {
$reader = new GEOSWKTReader();
Expand All @@ -34,35 +34,39 @@ public function read($wkt) {
$geom->setSRID($srid);
return $geom;
}
else {
else {
return geoPHP::geosToGeometry($reader->read($wkt));
}
}
$wkt = str_replace(', ', ',', $wkt);

// For each geometry type, check to see if we have a match at the
// beggining of the string. If we do, then parse using that type
// beginning of the string. If we do, then parse using that type
foreach (geoPHP::geometryList() as $geom_type) {
$wkt_geom = strtoupper($geom_type);
if (strtoupper(substr($wkt, 0, strlen($wkt_geom))) == $wkt_geom) {
$data_string = $this->getDataString($wkt);
$method = 'parse'.$geom_type;

if ($srid) {
$geom = $this->$method($data_string);
$geom->setSRID($srid);
return $geom;
}
else {
else {
return $this->$method($data_string);
}

}
}
}

private function parsePoint($data_string) {
$data_string = $this->trimParens($data_string);

// If it's marked as empty, then return an empty point
if ($data_string == 'EMPTY') return new Point();

$parts = explode(' ',$data_string);
return new Point($parts[0], $parts[1]);
}
Expand All @@ -72,7 +76,7 @@ private function parseLineString($data_string) {

// If it's marked as empty, then return an empty line
if ($data_string == 'EMPTY') return new LineString();

$parts = explode(',',$data_string);
$points = array();
foreach ($parts as $part) {
Expand All @@ -83,10 +87,10 @@ private function parseLineString($data_string) {

private function parsePolygon($data_string) {
$data_string = $this->trimParens($data_string);

// If it's marked as empty, then return an empty polygon
if ($data_string == 'EMPTY') return new Polygon();

$parts = explode('),(',$data_string);
$lines = array();
foreach ($parts as $part) {
Expand All @@ -99,24 +103,24 @@ private function parsePolygon($data_string) {

private function parseMultiPoint($data_string) {
$data_string = $this->trimParens($data_string);

// If it's marked as empty, then return an empty MutiPoint
if ($data_string == 'EMPTY') return new MultiPoint();

$parts = explode(',',$data_string);
$points = array();
foreach ($parts as $part) {
$points[] = $this->parsePoint($part);
}
return new MultiPoint($points);
}

private function parseMultiLineString($data_string) {
$data_string = $this->trimParens($data_string);

// If it's marked as empty, then return an empty multi-linestring
if ($data_string == 'EMPTY') return new MultiLineString();

$parts = explode('),(',$data_string);
$lines = array();
foreach ($parts as $part) {
Expand All @@ -133,7 +137,7 @@ private function parseMultiPolygon($data_string) {

// If it's marked as empty, then return an empty multi-polygon
if ($data_string == 'EMPTY') return new MultiPolygon();

$parts = explode(')),((',$data_string);
$polys = array();
foreach ($parts as $part) {
Expand All @@ -150,12 +154,12 @@ private function parseGeometryCollection($data_string) {

// If it's marked as empty, then return an empty geom-collection
if ($data_string == 'EMPTY') return new GeometryCollection();

$geometries = array();
$matches = array();
$str = preg_replace('/,\s*([A-Za-z])/', '|$1', $data_string);
$components = explode('|', trim($str));

foreach ($components as $component) {
$geometries[] = $this->read($component);
}
Expand All @@ -167,23 +171,25 @@ protected function getDataString($wkt) {

if ($first_paren !== FALSE) {
return substr($wkt, $first_paren);
}
return FALSE;
} elseif (strstr($wkt,'EMPTY')) {
return 'EMPTY';
} else
return FALSE;
}

/**
* Trim the parenthesis and spaces
*/
protected function trimParens($str) {
$str = trim($str);

// We want to only strip off one set of parenthesis
if ($this->beginsWith($str, '(')) {
return substr($str,1,-1);
}
else return $str;
}

protected function beginsWith($str, $char) {
if (substr($str,0,strlen($char)) == $char) return TRUE;
else return FALSE;
Expand All @@ -193,7 +199,7 @@ protected function endsWith($str, $char) {
if (substr($str,(0 - strlen($char))) == $char) return TRUE;
else return FALSE;
}

/**
* Serialize geometries into a WKT string.
*
Expand All @@ -208,15 +214,15 @@ public function write(Geometry $geometry) {
$writer->setTrim(TRUE);
return $writer->write($geometry->geos());
}

if ($geometry->isEmpty()) {
return strtoupper($geometry->geometryType()).' EMPTY';
}
else if ($data = $this->extractData($geometry)) {
return strtoupper($geometry->geometryType()).' ('.$data.')';
}
}

/**
* Extract geometry to a WKT string
*
Expand Down
6 changes: 3 additions & 3 deletions lib/geometry/Geometry.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,17 +330,17 @@ public function isMeasured() {
}

public function coordinateDimension() {
// geoPHP only supports 2-dimentional space
// geoPHP only supports 2-dimensional space
return 2;
}

public function z() {
// geoPHP only supports 2-dimentional space
// geoPHP only supports 2-dimensional space
return NULL;
}

public function m() {
// geoPHP only supports 2-dimentional space
// geoPHP only supports 2-dimensional space
return NULL;
}

Expand Down
10 changes: 5 additions & 5 deletions lib/geometry/Point.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Point extends Geometry
{
public $coords = array(2);
protected $geom_type = 'Point';
protected $dimention = 2;
protected $dimension = 2;

/**
* Constructor
Expand All @@ -28,7 +28,7 @@ public function __construct($x, $y, $z = NULL) {
if (!is_numeric($z)) {
throw new Exception("Cannot construct Point. z should be numeric");
}
$this->dimention = 3;
$this->dimension = 3;
}

// Convert to floatval in case they are passed in as a string or integer etc.
Expand All @@ -37,10 +37,10 @@ public function __construct($x, $y, $z = NULL) {
$z = floatval($z);

// Add poitional elements
if ($this->dimention == 2) {
if ($this->dimension == 2) {
$this->coords = array($x, $y);
}
if ($this->dimention == 3) {
if ($this->dimension == 3) {
$this->coords = array($x, $y, $z);
}
}
Expand Down Expand Up @@ -69,7 +69,7 @@ public function y() {
* @return float The Z coordinate or NULL is not a 3D point
*/
public function z() {
if ($this->dimention == 3) {
if ($this->dimension == 3) {
return $this->coords[2];
}
else return NULL;
Expand Down
2 changes: 1 addition & 1 deletion tests/input/an_empty_polygon.wkt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
POLYGON EMPTY
POLYGON EMPTY
1 change: 1 addition & 0 deletions tests/input/empty_point.wkt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
POINT EMPTY
2 changes: 1 addition & 1 deletion tests/postgis.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function run_test() {
// Working with PostGIS and EWKB
// ----------------------------

foreach (scandir('./input') as $file) {
foreach (scandir('./input', SCANDIR_SORT_NONE) as $file) {
$parts = explode('.',$file);
if ($parts[0]) {
$name = $parts[0];
Expand Down
2 changes: 1 addition & 1 deletion tests/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function run_test() {
print "GEOS is not installed.\n";
}

foreach (scandir('./input') as $file) {
foreach (scandir('./input', SCANDIR_SORT_NONE) as $file) {
$parts = explode('.',$file);
if ($parts[0]) {
$format = $parts[1];
Expand Down
2 changes: 0 additions & 2 deletions tests/tests/20120702Test.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php
require_once('../geoPHP.inc');
require_once('PHPUnit/Autoload.php');

class Tests_20120702 extends PHPUnit_Framework_TestCase {

function setUp() {
Expand Down
Loading

0 comments on commit b2465be

Please sign in to comment.