# API Reference

- Page History

## geoPHP static class

geoPHP provides a static class that contains useful utility functions. All methods must be called statically.

### Example

    $geometry = geoPHP::load('MULTILINESTRING((10 10,20 20,10 40))','wkt');

    $reduced_geometry = geoPHP::geometryReduce($geometry);

### Static Methods

Method | Description | Returns
version | Provides the current geoPHP version. Useful if you need to check compatablity | Numeric String
load | Load from an adapter format (like wkt) into a geometry. The first argument is the data, the second one is the format of the data ('wkt','wkb','json','kml','gpx','google_geocode'). All additional arguments are passed along to the read method of the relevant adapte | Geometry
getAdapterMap | Get a list of adapters as an array keyed by the value that should be passed to geoPHP::load | Array
geometryList | List all geometry types | Array
geosToGeometry | Given a GEOSGeometry, get a geoPHP geometry | Geometry
geometryReduce | Reduce a geometry, or an array of geometries, into their \'lowest\' available common geometry. For example a GeometryCollection of only points will become a MultiPoint, while a multi-point containing a single point will return a point. An array of geometries can be passed and they will be compiled into a single geometry. | Geometry
geosInstalled | Check if the GEOS php extension is installed and working | Boolean

## Adapters

Adapters are responsible for getting data in and out of geoPHP Geometries. Generally you will use an adapter to load data into a geoPHP geometry, do various manipulations on the geometry, then use another adapter to write it out to another (or the same) format. You can also use adapters by themselves to simply do conversion from one format to another (See example-format-converter for an example of this). Adapters should be instantiated and not called statically.

### Class Hierarchy

- GeoAdapter Abtract Class
  - WKT Enables reading and writing WKT (Well Known Text)
  - WKB Enables reading and writing WKB (Well Known Binary). This is very fast.
  - GeoJSON Enables reading and writing GeoJSON
  - KML Enables reading and writing KML (Google Earth)
  - GoogleGeocode Enables geocoding and reverse-geocoding via google geocoding API
  - GPX Enables reading and writing GPX (from handheld GPS devices)
  - GeoRSS Enables reading and writing of GeoRSS

### Example

    $wkb_reader = new WKB();

    $geometry = $wkb_reader->read('0101000000000000000000f03f000000000000f03f',TRUE);

    $wkt_writer = new wkt();

    $wkt = $wkt_writer->write($geometry);

### Methods

Method | Description | Returns
read | Read in input (generally a string) and return a Geometry | Geometry
write | Write out the given geometry into the adapter formater | String

## Geometries

Geometries form the heart of the geoPHP library. Once you have loaded your data into a Geometry object, you have access to all the various methods detailed below for doing conversions, transformations, and operations. While generally you would use an adapter to get a Geometry object, they can also be built by hand. See the constructor methods in the classes to see how to do this. GEOS-php extension needs to be installed in order to use some of the advanced methods (detailed below).

### Class Hierarchy

- Geometry
  - Point
  - Collection
    - LineString
    - Polygon
    - MultiLineString
    - MultiPoint
    - MultiPolygon
    - GeometryCollection

### Example

    $poly1 = geoPHP::load('POLYGON((30 10,10 20,20 40,40 40,30 10))','wkt');

    $poly2 = geoPHP::load('POLYGON((35 10,10 20,15 40,45 45,35 10),(20 30, 35 35, 30 20, 20 30))','wkt');

    $combined_poly = $poly1->union($poly2);

    $kml = $combined_poly->out('kml');

### Methods

Common Methods

Method | Description | Returns
out | Outputs the geometry into the specified adapter format. Available formats are wkt, wkb, json, kml, gpx, google_geocode | String
area | The area of this Polygon (or GeometryCollection), as measured in the spatial reference system of the geometry | Float
boundary | Returns the closure of the combinatorial boundary of this geometric object. | LinearRing
envelope | The minimum bounding box for this Geometry, returned as a Geometry. | Polygon
getBBox | The minimum bounding box for this Geometry, returned as an array. Also see envelope() | Array
centroid | The mathematical centroid for this geometry as a Point. For polygons, the result is not guaranteed to be interior. | Point
length | The length of this Curve in its associated spatial reference. | Float
y | The y-coordinate value for this Point. | Float
x | The x-coordinate value for this Point. | Float
numGeometries | The number of component geometries in this collection | Integer
geometryN | Returns the geometry N in this collection. Note that the index starts at 1. | Geometry
startPoint | The start Point of this LineString | Point
endPoint | The end Point of this LineString | Point
isRing | Returns 1 (TRUE) if this Curve is closed() and this Curve isSimple(). | Boolean
isClosed | Returns 1 (TRUE) if this Curve is closed. StartPoint() == EndPoint(). | Boolean
getComponents | Get all sub-geometry components of the geometry | Array of geometries
numPoints | The number of Points in this LineString | Integer
pointN | Returns the specified Point N in this LineString. Note that the index starts at 1. | Point
exteriorRing | Returns the exterior ring of this Polygon. | LineString
numInteriorRings | Returns the number of interior rings in this Polygon. | Integer
interiorRingN | Returns the Nth interior ring for this Polygon as a LineString. Note that the index starts at 1. | LineString
dimension | The inherent dimension of this geometric object. In non-homogeneous collections, this will return the largest topological dimension of the contained objects. | Integer
geometryType | Returns the name of the instantiable subtype of Geometry of which this geometric object is an instantiable member. The name of the subtype of Geometry is returned as a string. | String
SRID | Returns the Spatial Reference System ID for this geometric object. | integer
setSRID | Set the Spatial Reference System ID for this geometric object. | NULL
asArray | Get the given geometry as an array of components (recursive) | Array
getGeoInterface | Get the geometryType and Coordinates as an array | Array

Aliases

Method | Description | Returns
getCentroid | Alias for centroid() | Point
getArea | Alias for area() | Float
getX | Alias for x() | Float
getY | Alias for y() | Float
getGeos | Alias for geos() | GEOSGeometry
getGeomType | Alias for geometryType() | String
getSRID | Alias for SRID() | Integer
asText | Alias for $this->out('wkt') | String
asBinary | Alias for $this->out('wkb') | String

Advanced Methods

The GEOS-php extension needs to be installed for these functions to be available

Method | Description | Returns
geos | Return a GEOSGeometry object representing this geometry | GEOSGeometry
setGeos | Set a GEOSGeometry object representing this geometry | NULL
pointOnSurface | A Point guaranteed to be within a polygon | Point
equals | Returns 1 (TRUE) if this geometry is “spatially equal” to another Geometry | Boolean
equalsExact | Returns 1 (TRUE) if this gemometric object is exactly the same as another object, including the ordering of component parts | Boolean
relate | Returns 1 (TRUE) if this geometric object is spatially related to anotherGeometry by testing for intersections between the interior, boundary and exterior of the two geometric objects as specified by the values in the intersectionPatternMatrix. This returns FALSE if all the tested intersections are empty except exterior (this) intersect exterior (another). | Boolean
checkValidity | Boolean
isSimple | Returns 1 (TRUE) if this geometry does not pass through the same point in space more than once | Boolean
project | Project the geometry from from one SRID to another | Geometry
buffer | Returns a geometric object that represents all Points whose distance from this geometric object is less than or equal to distance. Calculations are in the spatial reference system of this geometric object. Because of the limitations of linear interpolation, there will often be some relatively small error in this distance, but it should be near the resolution of the coordinates used. | Geometry
intersection | Returns a geometric object that represents the Point set intersection of this geometric object with anotherGeometry. See http://en.wikipedia.org/wiki/Intersection_(set_theory) | Geometry
convexHull | Returns a geometric object that represents the convex hull of this geometric object. See http://en.wikipedia.org/wiki/Convex_hull | Geometry
difference | Returns a geometric object that represents the Point set difference of this geometric object with anotherGeometry. | Geometry
symDifference | Returns a geometric object that represents the Point set symmetric difference of this geometric object with another Geometry. See http://en.wikipedia.org/wiki/Symmetric_difference | Geometry
union | Returns a geometric object that represents the Point set union of this geometric object with anotherGeometry. See http://en.wikipedia.org/wiki/Union_(set_theory) | Geometry
simplify | Simplify the geometry | Geometry
disjoint | Returns 1 (TRUE) if this geometric object is “spatially disjoint” from another Geometry. | Boolean
touches | Returns 1 (TRUE) if this geometric object “spatially touches” another Geometry. | Boolean
intersects | Returns 1 (TRUE) if this geometric object “spatially intersects” another Geometry. | Boolean
crosses | Returns 1 (TRUE) if this geometric object “spatially crosses? another Geometry. | Boolean
within | Returns 1 (TRUE) if this geometric object is “spatially within” another Geometry. | Boolean
contains | Returns 1 (TRUE) if this geometric object “spatially contains” another Geometry. | Boolean
overlaps | Returns 1 (TRUE) if this geometric object “spatially overlaps” another Geometry. | Boolean
covers | Alias for contains() | Boolean
coveredBy | Alias for within() | Boolean
distance | Returns the shortest distance between any two Points in the two geometric objects as calculated in the spatial reference system of this geometric object. Because the geometries are closed, it is possible to find a point on each geometric object involved, such that the distance between these 2 points is the returned distance between their geometric objects. | Float
hausdorffDistance | See http://en.wikipedia.org/wiki/Hausdorff_distance | Float

Placeholders

These methods are part of the specification, but are not really supported by geoPHP.

Method | Description | Returns
hasZ | returns FALSE. geoPHP does not support Z values at the moment. | Boolean
is3D | returns FALSE. geoPHP does not support 3D geometries at the moment. | Boolean
isMeasured | returns FALSE. geoPHP does not yet support M values | Boolean
isEmpty | returns FALSE. geoPHP does not yet support empty geometries | Boolean
coordinateDimension | returns 2. geoPHP only supports 2-dimentional space | Integer
z | returns NULL. geoPHP does not support Z values at the moment | NULL
m | returns NULL. geoPHP does not support M values | NULL