Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proper autoloading for composer, PSR-4 compliant, Cleanup #130

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ Example usage

```php
<?php
include_once('geoPHP.inc');

using Phayser\GeoPHP\GeoPHP;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
using Phayser\GeoPHP\GeoPHP;
using Phayes\GeoPHP\GeoPHP;

there's a typo there


// Polygon WKT example
$polygon = geoPHP::load('POLYGON((1 1,5 1,5 5,1 5,1 1),(2 2,2 3,3 3,3 2,2 2))','wkt');
$polygon = GeoPHP::load('POLYGON((1 1,5 1,5 5,1 5,1 1),(2 2,2 3,3 3,3 2,2 2))','wkt');
$area = $polygon->getArea();
$centroid = $polygon->getCentroid();
$centX = $centroid->getX();
Expand All @@ -56,7 +57,7 @@ $json =
]
}';

$multipoint = geoPHP::load($json, 'json');
$multipoint = GeoPHP::load($json, 'json');
$multipoint_points = $multipoint->getComponents();
$first_wkt = $multipoint_points[0]->out('wkt');

Expand All @@ -69,17 +70,17 @@ More Examples

The Well Known Text (WKT) and Well Known Binary (WKB) support is ideal for integrating with MySQL's or PostGIS's spatial capability.
Once you have SELECTed your data with `'AsText('geo_field')'` or `'AsBinary('geo_field')'`, you can put it straight into
geoPHP (can be wkt or wkb, but must be the same as how you extracted it from your database):
GeoPHP (can be wkt or wkb, but must be the same as how you extracted it from your database):

$geom = geoPHP::load($dbRow,'wkt');
$geom = GeoPHP::load($dbRow,'wkt');

You can collect multiple geometries into one (note that you must use wkt for this):

$geom = geoPHP::load("GEOMETRYCOLLECTION(".$dbString1.",".$dbString2.")",'wkt');
$geom = GeoPHP::load("GEOMETRYCOLLECTION(".$dbString1.",".$dbString2.")",'wkt');

Calling get components returns the sub-geometries within a geometry as an array.

$geom2 = geoPHP::load("GEOMETRYCOLLECTION(LINESTRING(1 1,5 1,5 5,1 5,1 1),LINESTRING(2 2,2 3,3 3,3 2,2 2))");
$geom2 = GeoPHP::load("GEOMETRYCOLLECTION(LINESTRING(1 1,5 1,5 5,1 5,1 1),LINESTRING(2 2,2 3,3 3,3 2,2 2))");
$geomComponents = $geom2->getComponents(); //an array of the two linestring geometries
$linestring1 = $geomComponents[0]->getComponents(); //an array of the first linestring's point geometries
$linestring2 = $geomComponents[1]->getComponents();
Expand All @@ -101,7 +102,9 @@ geoPHP, through it's EWKB adapter, has good integration with postGIS. Here's an

```php
<?php
include_once('geoPHP.inc');

using Phayser\GeoPHP\GeoPHP;

$host = 'localhost';
$database = 'phayes';
$table = 'test';
Expand All @@ -118,7 +121,7 @@ $connection = pg_connect("host=$host dbname=$database user=$user password=$pass"
$result = pg_fetch_all(pg_query($connection, "SELECT asBinary($column) as geom FROM $table"));
foreach ($result as $item) {
$wkb = pg_unescape_bytea($item['geom']); // Make sure to unescape the hex blob
$geom = geoPHP::load($wkb, 'ewkb'); // We now a full geoPHP Geometry object
$geom = GeoPHP::load($wkb, 'ewkb'); // We now a full GeoPHP Geometry object

// Let's insert it back into the database
$insert_string = pg_escape_bytea($geom->out('ewkb'));
Expand All @@ -129,7 +132,7 @@ foreach ($result as $item) {
$result = pg_fetch_all(pg_query($connection, "SELECT $column as geom FROM $table"));
foreach ($result as $item) {
$wkb = pack('H*',$item['geom']); // Unpacking the hex blob
$geom = geoPHP::load($wkb, 'ewkb'); // We now have a geoPHP Geometry
$geom = GeoPHP::load($wkb, 'ewkb'); // We now have a GeoPHP Geometry

// To insert directly into postGIS we need to unpack the WKB
$unpacked = unpack('H*', $geom->out('ewkb'));
Expand Down
26 changes: 18 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
{
"name": "phayes/geophp",
"license": "GPL-2 or New-BSD",
"type": "library",
"description": "GeoPHP is a open-source native PHP library for doing geometry operations. It is written entirely in PHP and can therefore run on shared hosts. It can read and write a wide variety of formats: WKT (including EWKT), WKB (including EWKB), GeoJSON, KML, GPX, GeoRSS). It works with all Simple-Feature geometries (Point, LineString, Polygon, GeometryCollection etc.) and can be used to get centroids, bounding-boxes, area, and a wide variety of other useful information.",
"type": "library",
"keywords": ["geojson", "wkt", "geophp", "converter", "geometry"],
"homepage": "https://github.com/phayes/geoPHP",
"autoload": {
"classmap": ["geoPHP.inc"]
},
"authors":[
"license": "GPL-2 or New-BSD",
"authors": [
{
"name":"Patrick Hayes"
"name": "Patrick Hayes",
"email": "[email protected]",
"homepage": "https://benramsey.com"
}
],
"support": {
"issues": "https://github.com/phayes/geoPHP/issues",
"source": "https://github.com/phayes/geoPHP"
},
"require": {
"php": ">=5.3"
},
"require-dev": {
"phpunit/phpunit": "4.1.*"
"phpunit/phpunit": "4.1.*"
},
"autoload": {
"psr-4": {"Phayes\\GeoPHP\\": "src/"}
}
}
96 changes: 0 additions & 96 deletions lib/adapters/EWKB.class.php

This file was deleted.

166 changes: 0 additions & 166 deletions lib/adapters/GoogleGeocode.class.php

This file was deleted.

21 changes: 0 additions & 21 deletions lib/geometry/MultiPoint.class.php

This file was deleted.

Loading