/** * Read WKT string into geometry objects * * @param string $WKT A WKT string * * @return Geometry */ public function read($wkt) { $wkt = trim($wkt); // If it contains a ';', then it contains additional SRID data if (strpos($wkt, ';')) { $parts = explode(';', $wkt); $wkt = $parts[1]; $eparts = explode('=', $parts[0]); $srid = $eparts[1]; } else { $srid = null; } // If geos is installed, then we take a shortcut and let it parse the WKT if (FOX_geo::geosInstalled()) { $reader = new GEOSWKTReader(); if ($srid) { $geom = FOX_geo::geosToGeometry($reader->read($wkt)); $geom->setSRID($srid); return $geom; } else { return FOX_geo::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 foreach (FOX_geo::geometryList() as $geom_type) { $wkt_geom = strtoupper($geom_type); if (strtoupper(substr($wkt, 0, strlen($wkt_geom))) == $wkt_geom) { $data_string = $this->getDataString($wkt, $wkt_geom); $method = 'parse' . $geom_type; if ($srid) { $geom = $this->{$method}($data_string); $geom->setSRID($srid); return $geom; } else { return $this->{$method}($data_string); } } } }
public function parseGeometryCollection($xml) { $components = array(); $geom_types = FOX_geo::geometryList(); foreach ($xml->childNodes as $child) { $nodeName = $child->nodeName == 'linearring' ? 'linestring' : $child->nodeName; if (array_key_exists($nodeName, $geom_types)) { $function = 'parse' . $geom_types[$nodeName]; $components[] = $this->{$function}($child); } } return new FOX_geometryCollection($components); }