class NaturalEarthCountries in Geolocation Field 8.3
Import Countries of the world.
Plugin annotation
@GeolocationGeometryData(
id = "natural_earth_countries",
name = @Translation("Natural Earth Countries"),
description = @Translation("Geometries of all countries in the world."),
)
Hierarchy
- class \Drupal\geolocation_geometry_data\GeolocationGeometryDataBase
- class \Drupal\geolocation_geometry_natural_earth_countries\Plugin\geolocation\GeolocationGeometryData\NaturalEarthCountries
Expanded class hierarchy of NaturalEarthCountries
File
- modules/
geolocation_geometry/ modules/ geolocation_geometry_natural_earth_countries/ src/ Plugin/ geolocation/ GeolocationGeometryData/ NaturalEarthCountries.php, line 17
Namespace
Drupal\geolocation_geometry_natural_earth_countries\Plugin\geolocation\GeolocationGeometryDataView source
class NaturalEarthCountries extends GeolocationGeometryDataBase {
/**
* {@inheritdoc}
*/
public $sourceUri = 'http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/110m/cultural/ne_110m_admin_0_countries.zip';
/**
* {@inheritdoc}
*/
public $sourceFilename = 'ne_110m_admin_0_countries.zip';
/**
* {@inheritdoc}
*/
public $localDirectory = 'geolocation_geometry_natural_earth_countries';
/**
* {@inheritdoc}
*/
public $shapeFilename = 'ne_110m_admin_0_countries.shp';
/**
* {@inheritdoc}
*/
public function import(&$context) {
parent::import($context);
$taxonomy_storage = \Drupal::entityTypeManager()
->getStorage('taxonomy_term');
$logger = \Drupal::logger('geolocation_geometry_natural_earth_countries');
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_geometry_countries',
'name' => $record
->getData('NAME'),
]);
$term
->set('field_geometry_data_geometry', [
'geojson' => $record
->getGeoJSON(),
]);
$term
->save();
}
return t('Done importing Countries.');
} catch (ShapefileException $e) {
$logger
->warning($e
->getMessage());
return t('ERROR importing Countries.');
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
GeolocationGeometryDataBase:: |
public | property | Shape file. | |
GeolocationGeometryDataBase:: |
public | function | Download batch callback. | |
GeolocationGeometryDataBase:: |
public | function | Return this batch. | |
NaturalEarthCountries:: |
public | property |
Directory extract of archive. Overrides GeolocationGeometryDataBase:: |
|
NaturalEarthCountries:: |
public | property |
Extracted filename. Overrides GeolocationGeometryDataBase:: |
|
NaturalEarthCountries:: |
public | property |
Filename of archive. Overrides GeolocationGeometryDataBase:: |
|
NaturalEarthCountries:: |
public | property |
URI to archive. Overrides GeolocationGeometryDataBase:: |
|
NaturalEarthCountries:: |
public | function |
Import batch callback. Overrides GeolocationGeometryDataBase:: |