public function projectGeometry(MapGeometry $geometry) { if ($geometry instanceof MapPolygon) { $rings = $geometry->getRings(); $projectedRings = array(); foreach ($rings as $ring) { if ($ring instanceof MapPolyline) { $ring = $ring->getPoints(); } $projectedRings[] = $this->projectPoints($ring); } return new MapBasePolygon($projectedRings); } elseif ($geometry instanceof MapPolyline) { $points = $geometry->getPoints(); $projectedPoints = $this->projectPoints($points); return new MapBasePolyline($projectedPoints); } else { // point $point = $geometry->getCenterCoordinate(); $projectedPoint = $this->projectPoint($point); return new MapBasePoint($projectedPoint); } }
public static function wktFromGeometry(MapGeometry $geometry) { $wkt = null; if ($geometry instanceof MapPolygon) { $ringStrings = array(); $rings = $geometry->getRings(); foreach ($rings as $ring) { $points = array_map(array('WKTParser', 'implodeLatLon'), $ring->getPoints()); $ringStrings[] = '(' . implode(',', $points) . ')'; } return 'POLYGON(' . implode(',', $ringStrings) . ')'; } elseif ($geometry instanceof MapPolyline) { $points = array_map(array('WKTParser', 'implodeLatLon'), $geometry->getPoints()); return 'LINESTRING(' . implode(',', $points) . ')'; } else { // this should be a point, but it will work for any MapGeometry $point = $geometry->getCenterCoordinate(); return 'POINT(' . self::implodeLatLon($point) . ')'; } return $wkt; }
protected function formatGeometry(MapGeometry $geometry) { $result = array(); if ($geometry instanceof MapPolygon) { foreach ($geometry->getRings() as $aRing) { $result[] = $aRing->getPoints(); } } elseif ($geometry instanceof MapPolyline) { $result = $geometry->getPoints(); } else { $result = $geometry->getCenterCoordinate(); } return $result; }