You are here

public function AbstractGeometryProvider::geocode in Geocoder 8.3

Same name and namespace in other branches
  1. 8.2 modules/geocoder_geofield/src/Geocoder/Provider/AbstractGeometryProvider.php \Drupal\geocoder_geofield\Geocoder\Provider\AbstractGeometryProvider::geocode()

Geocode a source string.

Parameters

string $filename: The file path with data to be geocoded.

Return value

\Geometry The Geometry result.

Throws

\Geocoder\Exception\Exception

Overrides GeometryProviderInterface::geocode

File

modules/geocoder_geofield/src/Geocoder/Provider/AbstractGeometryProvider.php, line 45

Class

AbstractGeometryProvider
Provides an abstract file handler to be used by GeoPHP Wrapper.

Namespace

Drupal\geocoder_geofield\Geocoder\Provider

Code

public function geocode($filename) : Geometry {
  if (file_exists($filename)) {
    $geophp_string = file_get_contents($filename);

    /* @var \Geometry $geometry */
    $geometry = $this->geophp
      ->load($geophp_string, $this->geophpType);
    if (!empty($geometry->components) || $geometry instanceof \Geometry) {
      return $geometry;
    }
  }
  throw new LogicException(sprintf('Could not find %s data in file: "%s".', $this->geophpType, basename($filename)));
}