You are here

class CanadaProvinces in Geolocation Field 8.3

Import Provinces of Canada.

Plugin annotation


@GeolocationGeometryData(
  id = "open_canada_provinces",
  name = @Translation("Provinces of Canada"),
  description = @Translation("Geometries of all us states."),
)

Hierarchy

Expanded class hierarchy of CanadaProvinces

File

modules/geolocation_geometry/modules/geolocation_geometry_open_canada_provinces/src/Plugin/geolocation/GeolocationGeometryData/CanadaProvinces.php, line 17

Namespace

Drupal\geolocation_geometry_open_canada_provinces\Plugin\geolocation\GeolocationGeometryData
View source
class CanadaProvinces extends GeolocationGeometryDataBase {

  /**
   * {@inheritdoc}
   */
  public $sourceUri = 'https://www.weather.gov/source/gis/Shapefiles/Misc/province.zip';

  /**
   * {@inheritdoc}
   */
  public $sourceFilename = 'province.zip';

  /**
   * {@inheritdoc}
   */
  public $localDirectory = 'geolocation_geometry_open_canadian_provinces';

  /**
   * {@inheritdoc}
   */
  public $shapeFilename = 'province.shp';

  /**
   * {@inheritdoc}
   */
  public function import(&$context) {
    parent::import($context);
    $taxonomy_storage = \Drupal::entityTypeManager()
      ->getStorage('taxonomy_term');
    $logger = \Drupal::logger('geolocation_provinces_of_canada');
    try {

      /** @var \Shapefile\Geometry\Geometry $record */
      while ($record = $this->shapeFile
        ->fetchRecord()) {
        if ($record
          ->isDeleted()) {
          continue;
        }
        $name = $record
          ->getData('NAME');
        if (empty($name)) {
          continue;
        }

        /** @var \Drupal\taxonomy\TermInterface $term */
        $term = $taxonomy_storage
          ->create([
          'vid' => 'geolocation_provinces_of_canada',
          'name' => $name,
        ]);
        $term
          ->set('field_geometry_data_geometry', [
          'geojson' => $record
            ->getGeoJSON(),
        ]);
        $term
          ->save();
      }
      return 'Done importing Provinces of Canada.';
    } catch (ShapefileException $e) {
      $logger
        ->warning($e
        ->getMessage());
      return t('Error importing Provinces of Canada.');
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CanadaProvinces::$localDirectory public property Directory extract of archive. Overrides GeolocationGeometryDataBase::$localDirectory
CanadaProvinces::$shapeFilename public property Extracted filename. Overrides GeolocationGeometryDataBase::$shapeFilename
CanadaProvinces::$sourceFilename public property Filename of archive. Overrides GeolocationGeometryDataBase::$sourceFilename
CanadaProvinces::$sourceUri public property URI to archive. Overrides GeolocationGeometryDataBase::$sourceUri
CanadaProvinces::import public function Import batch callback. Overrides GeolocationGeometryDataBase::import
GeolocationGeometryDataBase::$shapeFile public property Shape file.
GeolocationGeometryDataBase::download public function Download batch callback.
GeolocationGeometryDataBase::getBatch public function Return this batch.