NaturalEarthCountries.php in Geolocation Field 8.3
File
modules/geolocation_geometry/modules/geolocation_geometry_natural_earth_countries/src/Plugin/geolocation/GeolocationGeometryData/NaturalEarthCountries.php
View source
<?php
namespace Drupal\geolocation_geometry_natural_earth_countries\Plugin\geolocation\GeolocationGeometryData;
use Shapefile\ShapefileException;
use Drupal\geolocation_geometry_data\GeolocationGeometryDataBase;
class NaturalEarthCountries extends GeolocationGeometryDataBase {
public $sourceUri = 'http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/110m/cultural/ne_110m_admin_0_countries.zip';
public $sourceFilename = 'ne_110m_admin_0_countries.zip';
public $localDirectory = 'geolocation_geometry_natural_earth_countries';
public $shapeFilename = 'ne_110m_admin_0_countries.shp';
public function import(&$context) {
parent::import($context);
$taxonomy_storage = \Drupal::entityTypeManager()
->getStorage('taxonomy_term');
$logger = \Drupal::logger('geolocation_geometry_natural_earth_countries');
try {
while ($record = $this->shapeFile
->fetchRecord()) {
if ($record
->isDeleted()) {
continue;
}
$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.');
}
}
}