def ingest_habitats(self): base_msg = "Ingesting 'habitats'..." self.logger.info(base_msg) habs_logger = self.get_section_logger('habs', base_msg) self.habs = {} self.habs_spatial_hash = SpatialHash(cell_size=self.hash_cell_size) habs_file = os.path.join(self.data_dir, 'habitats', "habitats.shp") habs_config = self.config.get('sections', {}).get('habitats', {}) def add_to_habs_spatial_hash(data=None, **kwargs): self.habs_spatial_hash.add_rect(data.mbr, data) return data def process_neg_depth(neg_depth): if neg_depth is not None: depth = -1.0 * float(neg_depth) return depth Ingestor( reader=ShapefileReader( shp_file=habs_file, reproject_to='EPSG:4326', ), processors=[ ClassMapper(clazz=self.dao.schema['sources']['Habitat'], mappings=[ { 'source': 'SUBSTRATE', 'target': 'substrate_id' }, { 'source': 'ENERGY', 'target': 'energy_id' }, { 'source': 'Z', 'target': 'depth', 'processor': process_neg_depth }, { 'source': '__shape', 'target': 'shape' }, ]), self.add_area_mbr, add_to_habs_spatial_hash, DictWriter(dict_=self.habs), ], logger=habs_logger, limit=habs_config.get('limit'), ).ingest()