You are here

class UsStates in Geolocation Field 8.3

Import US states.

Plugin annotation


@GeolocationGeometryData(
  id = "natural_earth_us_states",
  name = @Translation("Natural Earth US States"),
  description = @Translation("Geometries of all us states."),
)

Hierarchy

  • class \Drupal\geolocation_geometry_data\GeolocationGeometryDataBase
    • class \Drupal\geolocation_geometry_natural_earth_us_states\Plugin\geolocation\GeolocationGeometryData\UsStates

Expanded class hierarchy of UsStates

File

modules/geolocation_geometry/modules/geolocation_geometry_natural_earth_us_states/src/Plugin/geolocation/GeolocationGeometryData/UsStates.php, line 17

Namespace

Drupal\geolocation_geometry_natural_earth_us_states\Plugin\geolocation\GeolocationGeometryData
View source
class UsStates extends GeolocationGeometryDataBase {

  /**
   * {@inheritdoc}
   */
  public $sourceUri = 'http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/110m/cultural/ne_110m_admin_1_states_provinces.zip';

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

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

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

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

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

        /** @var \Drupal\taxonomy\TermInterface $term */
        $term = $taxonomy_storage
          ->create([
          'vid' => 'geolocation_us_states',
          'name' => $record
            ->getData('NAME'),
        ]);
        $term
          ->set('field_geometry_data_geometry', [
          'geojson' => $record
            ->getGeoJSON(),
        ]);
        $term
          ->save();
      }
      return t('Done importing US States.');
    } catch (ShapefileException $e) {
      $logger
        ->warning($e
        ->getMessage());
      return t('ERROR importing US States.');
    }
  }

}

Members

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