Skip to content
phayes edited this page Apr 15, 2011 · 14 revisions
read($data); if (count($args) == 1) $result = $processor->read($data, $args[0]); if (count($args) == 2) $result = $processor->read($data, $args[0],$args[1]); if (count($args) == 3) $result = $processor->read($data, $args[0],$args[1],$args[2]); if (count($args) == 4) $result = $processor->read($data, $args[0],$args[1],$args[2], $args[3]); if (count($args) == 5) $result = $processor->read($data, $args[0],$args[1],$args[2], $args[3], $args[4]); return $result; } static function getAdapterMap() { return array ( 'wkt' => 'WKT', 'wkb' => 'WKB', 'json' => 'GeoJSON', 'kml' => 'KML', 'gpx' => 'GPX', 'google_geocode' => 'GoogleGeocode', ); } static function geosToGeometry($geos) { $wkb_writer = new GEOSWKBWriter(); $wkb = $wkb_writer->writeHEX($geos); $geometry = geoPHP::load($wkb,'wkb',TRUE); $geometry->setGeos($geos); return $geometry; } static function geometryList() { return array( 'point' => 'Point', 'linestring' => 'LineString', 'linearring' => 'LinearRing', 'polygon' => 'Polygon', 'multipoint' => 'MultiPoint', 'multilinestring' => 'MultiLineString', 'multipolygon' => 'MultiPolygon', 'geometrycollection' => 'GeometryCollection', ); } // 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 // 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 static function geometryReduce($geometry) { // If it's an array of one, then just parse the one if (is_array($geometry)) { if (count($geometry) == 1) return geoPHP::geometryReduce($geometry[0]); } // If the geometry cannot even theoretically be reduced more, then pass it back if (gettype($geometry) == 'object') { $passbacks = array('Point','LineString','LinearRing','Polygon'); if (in_array(get_class($geometry),$passbacks)) { return $geometry; } } // If it is a mutlti-geometry, check to see if it just has one member // If it does, then pass the member, if not, then just pass back the geometry if (gettype($geometry) == 'object') { $simple_collections = array('MultiPoint','MultiLineString','MultiPolygon'); if (in_array(get_class($geometry),$passbacks)) { $components = $geometry->getComponents(); if (count($components) == 1) { return $components[0]; } else { return $geometry; } } } // So now we either have an array of geometries, a GeometryCollection, or an array of GeometryCollections if (!is_array($geometry)) { $geometry = array($geometry); } $geometries = array(); $geom_types = array(); $collections = array('MultiPoint','MultiLineString','MultiPolygon','GeometryCollection'); foreach ($geometry as $item) { if (in_array(get_class($item), $collections)) { foreach ($item->getComponents() as $component) { $geometries[] = $component; $geom_types[] = get_class($component); } } else { $geometries[] = $item; $geom_types[] = get_class($item); } } $geom_types = array_unique($geom_types); if (count($geom_types) == 1) { $class = 'Multi'.$geom_types[0]; return new $class($geometries); } else { return new GeometryCollection($geometries); } } }
Clone this wiki locally