Example #1
0
 protected function fromGeometry($geometry)
 {
     if ($geometry instanceof Geometry) {
         $extractor = new Extractor();
         $generator = new WKTGenerator($extractor);
         return $generator->generate($geometry);
     } elseif (is_string($geometry)) {
         if (json_decode($geometry)) {
             $geometry = json_decode($geometry);
             $geometry = GeoJson::jsonUnserialize($geometry);
             if ($geometry instanceof Feature) {
                 $geometry = $geometry->getGeometry();
             } elseif ($geometry instanceof FeatureCollection) {
                 $geometries = [];
                 foreach ($geometry->getFeatures() as $feature) {
                     $geometries[] = $feature->getGeometry();
                 }
                 return $this->fromGeometry(new GeometryCollection($geometries));
             }
             if ($geometry instanceof Geometry) {
                 return $this->fromGeometry($geometry);
             }
         }
         try {
             if ($this->toGeometry($geometry)) {
                 return $geometry;
             }
         } catch (Exception $e) {
         }
     }
     return 'POINT(0 0)';
 }
Example #2
0
 public function testGenerateShouldCatchExtractorExceptions()
 {
     $this->setExpectedException('GeoIO\\WKT\\Generator\\Exception\\GeneratorException');
     $extractor = Mockery::mock('GeoIO\\Extractor');
     $extractor->shouldIgnoreMissing();
     $extractor->shouldReceive('extractType')->once()->andThrow(new \Exception());
     $generator = new Generator($extractor);
     $generator->generate('foo');
 }