pointArray, array("x" => $x, "y" => $y)); } public function addPointToRing ($i, $x, $y) { if (count($this->innerRingArray) < $i) { array_push($this->innerRingArray, array()); } array_push($this->innerRingArray[$i-1], array("x" => $x, "y" => $y)); } public function toGml2 () { $str = "srs\">" . "" . ""; $ptArray = array(); foreach ($this->pointArray as $point) { $ptArray[] = $point["x"] . "," . $point["y"]; } $str .= implode(" ", $ptArray); $str .= ''; foreach ($this->innerRingArray as $ring) { $str .= ""; $ptArray = array(); foreach ($ring as $point) { $ptArray[] = $point["x"] . "," . $point["y"]; } $str .= implode(" ", $ptArray); $str .= ""; } $str .= ""; return $str; } public function toGml3 () { $str = "srs\">" . "" . ""; $ptArray = array(); foreach ($this->pointArray as $point) { $ptArray[] = "" . $point["x"] . " " . $point["y"] . ""; } $str .= implode("", $ptArray); $str .= ''; foreach ($this->innerRingArray as $ring) { $str .= ""; $ptArray = array(); foreach ($ring as $point) { $ptArray[] = "" . $point["x"] . " " . $point["y"] . ""; } $str .= implode("", $ptArray); $str .= ""; } $str .= ""; return $str; } public function isEmpty () { return !(count($this->pointArray) > 0); } public function toGeoJSON () { $numberOfPoints = count($this->pointArray); $str = ""; if ($numberOfPoints > 0) { $str .= "{\"type\": \"Polygon\", \"coordinates\":[["; for ($i=0; $i < $numberOfPoints; $i++) { if ($i > 0) { $str .= ","; } if (in_array($this->srs, $this->latLonSrs)) { $str .= "[".$this->pointArray[$i]["y"].",".$this->pointArray[$i]["x"]."]"; } else { $str .= "[".$this->pointArray[$i]["x"].",".$this->pointArray[$i]["y"]."]"; } } $str .= "]"; for ($i=0; $i < count($this->innerRingArray); $i++) { $str .= ",["; for ($j=0; $j < count($this->innerRingArray[$i]); $j++) { if ($j > 0) { $str .= ","; } if (in_array($this->srs, $this->latLonSrs)) { $str .= "[".$this->innerRingArray[$i][$j]["y"].",".$this->innerRingArray[$i][$j]["x"]."]"; } else { $str .= "[".$this->innerRingArray[$i][$j]["x"].",".$this->innerRingArray[$i][$j]["y"]."]"; } } $str .= "]"; } $str .= "]}"; } else { $e = new mb_exception("GMLPolygon: toGeoJSON: this point is null."); } return $str; } } ?>