/** * @runInSeparateProcess */ public function testAllWktStrings() { $codes = get_object_vars(json_decode(file_get_contents(__DIR__ . '/codes.json'))); foreach ($codes as $code => $defs) { $this->defs = $defs; $this->code = $code; if (isset($this->onlyTestTheseProjections) && !empty($this->onlyTestTheseProjections)) { if (is_array($this->onlyTestTheseProjections)) { if (!in_array($code, $this->onlyTestTheseProjections)) { continue; } } elseif ($code !== $this->onlyTestTheseProjections) { continue; } } if (in_array($code, $this->skipAllTestsForCode)) { continue; } if (key_exists('proj4', $defs) && !empty($defs->proj4) && key_exists($this->wkt, $defs) && !empty($defs->{$this->wkt})) { $wktStr = $defs->{$this->wkt}; if ($this->isInvalidWKT($wktStr)) { continue; } if ($this->isIgnoredProjection()) { continue; } $result = Wkt::Parse($wktStr); $this->assertTrue(gettype($result) == 'object'); } } }
/** * Constructor: initialize * Constructor for Proj4php::Proj objects * * Parameters: * $srsCode - a code for map projection definition parameters. These are usually * (but not always) EPSG codes. */ public function __construct($srsCode, Proj4php $proj4php) { //$this->srsCodeInput = $srsCode; $this->proj4php = $proj4php; // Check to see if $this is a Well Known Text (WKT) string. // This is an old, deprecated format, but still used. // CHECKME: are these the WKT "objects"? If so, we probably // need to check the string *starts* with these names. if (preg_match('/(GEOGCS|GEOCCS|PROJCS|LOCAL_CS)/', $srsCode)) { $this->to_rads = COMMON::D2R; $params = Wkt::Parse($srsCode); // TODO: find a better way to apply wkt params to this instance foreach ($params as $k => $v) { $this->{$k} = $v; } if (isset($this->defData)) { // wkt codes can contain EXTENSION["PROJ4", "..."] // for example SR-ORG:6 $this->parseDefs(); $this->initTransforms(); return; } $this->deriveConstants(); $this->loadProjCode($this->projName); return; } if (strpos($srsCode, '+proj') === 0) { $this->defData = $srsCode; $this->parseDefs(); $this->loadProjCode($this->projName); $this->initTransforms(); return; } elseif (strpos($srsCode, 'urn:') === 0) { // DGR 2008-08-03 : support urn and url //urn:ORIGINATOR:def:crs:CODESPACE:VERSION:ID $urn = explode(':', $srsCode); if (($urn[1] == 'ogc' || $urn[1] == 'x-ogc') && $urn[2] == 'def' && $urn[3] == 'crs') { $srsCode = $urn[4] . ':' . $urn[strlen($urn) - 1]; } } elseif (strpos($srsCode, 'http://') === 0) { //url#ID $url = explode('#', $srsCode); if (preg_match("/epsg.org/", $url[0])) { // http://www.epsg.org/# $srsCode = 'EPSG:' . $url[1]; } elseif (preg_match("/RIG.xml/", $url[0])) { //http://librairies.ign.fr/geoportail/resources/RIG.xml# //http://interop.ign.fr/registers/ign/RIG.xml# $srsCode = 'IGNF:' . $url[1]; } } $this->srsCode = strtoupper($srsCode); if (strpos($this->srsCode, "EPSG") === 0) { $this->srsCode = $this->srsCode; $this->srsAuth = 'epsg'; $this->srsProjNumber = substr($this->srsCode, 5); // DGR 2007-11-20 : authority IGNF } elseif (strpos($this->srsCode, "IGNF") === 0) { $this->srsCode = $this->srsCode; $this->srsAuth = 'IGNF'; $this->srsProjNumber = substr($this->srsCode, 5); // DGR 2008-06-19 : pseudo-authority CRS for WMS } elseif (strpos($this->srsCode, "CRS") === 0) { $this->srsCode = $this->srsCode; $this->srsAuth = 'CRS'; $this->srsProjNumber = substr($this->srsCode, 4); } else { $this->srsAuth = ''; $this->srsProjNumber = $this->srsCode; } $this->loadProjDefinition(); }