/** * Retrieves the metadata for all the supported spatial reference systems. * * @param boolean $refresh Set to true to force a full refresh, otherwise the result is cached. */ public static function system_metadata($refresh = false) { $cacheId = 'spatial-ref-systems'; if ($refresh) { $cache = Cache::instance(); $cache->delete($cacheId); self::$system_metadata = false; } if (self::$system_metadata === false) { $latlong_systems = Kohana::config('sref_notations.lat_long_systems'); $cache = Cache::instance(); if ($cached = $cache->get($cacheId)) { self::$system_metadata = $cached; } else { self::$system_metadata = array(); // fetch any systems that are just declared as srids, with no notation module required foreach (Kohana::config('sref_notations.sref_notations') as $code => $title) { self::$system_metadata["EPSG:{$code}"] = array('title' => $title, 'srid' => $code, 'treat_srid_as_x_y_metres' => !isset($latlong_systems[$code])); } // Now look for any modules which extend the sref systems available foreach (Kohana::config('config.modules') as $path) { $plugin = basename($path); if (file_exists("{$path}/plugins/{$plugin}.php")) { require_once "{$path}/plugins/{$plugin}.php"; if (function_exists($plugin . '_sref_systems')) { $metadata = call_user_func($plugin . '_sref_systems'); self::$system_metadata = array_merge(self::$system_metadata, $metadata); } } } $cache->set($cacheId, self::$system_metadata); } } return self::$system_metadata; }
/** * Define a form that is used to capture a set of predetermined values that apply to every record during an import. */ public function fixed_values_form() { $srefs = array(); $systems = spatial_ref::system_metadata(); foreach ($systems as $code => $metadata) { $srefs[] = "{$code}:" . $metadata['title']; } return array('website_id' => array('display' => 'Website', 'description' => 'Select the website to import records into.', 'datatype' => 'lookup', 'population_call' => 'direct:website:id:title'), 'location:centroid_sref_system' => array('display' => 'Spatial Ref. System', 'description' => 'Select the spatial reference system used in this import file. Note, if you have a file with a mix of spatial reference systems then you need a ' . 'column in the import file which is mapped to the Location Spatial Reference System field containing the spatial reference system code.', 'datatype' => 'lookup', 'lookup_values' => implode(',', $srefs))); }
/** * The upgrade might involve a change to spatial system support in plugins, so now is a good * time to refresh the spatial_systems metadata table. */ private function populate_spatial_systems_table() { $system_metadata = spatial_ref::system_metadata(true); $existing = $this->db->select('id', 'code')->from('spatial_systems')->get()->result_array(false); foreach ($system_metadata as $system => $metadata) { $id = false; foreach ($existing as $idx => $record) { if ($record['code'] === $system) { // record already exists $id = $record['id']; unset($existing[$idx]); break; } } $metadata['treat_srid_as_x_y_metres'] = isset($metadata['treat_srid_as_x_y_metres']) && $metadata['treat_srid_as_x_y_metres'] ? 't' : 'f'; if ($id) { $this->db->update('spatial_systems', array_merge($metadata, array('code' => $system)), array('id' => $id)); } else { $this->db->insert('spatial_systems', array_merge($metadata, array('code' => $system))); } } // delete any that remain in $existing, since they are no longer supported foreach ($existing as $idx => $record) { $this->db->delete('spatial_systems', array('id' => $record['id'])); } }
/** * Define a form that is used to capture a set of predetermined values that apply to every record during an import. */ public function fixed_values_form() { $srefs = array(); $systems = spatial_ref::system_metadata(); foreach ($systems as $code => $metadata) { $srefs[] = "{$code}:" . $metadata['title']; } return array('website_id' => array('display' => 'Website', 'description' => 'Select the website to import records into.', 'datatype' => 'lookup', 'population_call' => 'direct:website:id:title'), 'survey_id' => array('display' => 'Survey', 'description' => 'Select the survey to import records into.', 'datatype' => 'lookup', 'population_call' => 'direct:survey:id:title', 'linked_to' => 'website_id', 'linked_filter_field' => 'website_id'), 'sample:entered_sref_system' => array('display' => 'Spatial Ref. System', 'description' => 'Select the spatial reference system used in this import file. Note, if you have a file with a mix of spatial reference systems then you need a ' . 'column in the import file which is mapped to the Sample Spatial Reference System field containing the spatial reference system code.', 'datatype' => 'lookup', 'lookup_values' => implode(',', $srefs)), 'fkFilter:taxa_taxon_list:taxon_list_id' => array('display' => 'Species list', 'description' => 'Select the species checklist which will be used when attempting to match species names.', 'datatype' => 'lookup', 'population_call' => 'direct:taxon_list:id:title', 'linked_to' => 'website_id', 'linked_filter_field' => 'website_id'), 'occurrence:record_status' => array('display' => 'Record Status', 'description' => 'Select the initial status for imported records', 'datatype' => 'lookup', 'lookup_values' => 'C:Data entry complete/unverified,V:Verified,I:Data entry still in progress', 'default' => 'C')); }