def run(self): out_fname = pjoin(self.out_dir, CONFIG.get('outputs', 'rasterise_filename')) ds_list_fname = pjoin(self.out_dir, CONFIG.get('outputs', 'query_filename')) with open(ds_list_fname, 'r') as infile: ds_list = pickle.load(infile) vector_fname = CONFIG.get('work', 'vector_filename') img_fname = ds_list[0].datasets[DatasetType.FC25].path with rasterio.open(img_fname) as src: crs = src.crs transform = src.affine height = src.height width = src.width res = rasterise_vector(vector_fname, shape=(height, width), transform=transform, crs=crs) kwargs = {'count': 1, 'width': width, 'height': height, 'crs': crs, 'transform': transform, 'dtype': res.dtype.name, 'nodata': 0} with rasterio.open(out_fname, 'w', **kwargs) as src: src.write(1, res) # We could just set the image as the Luigi completion target... with self.output().open('w') as outf: outf.write('Complete')
def run(self): out_fname = pjoin(self.out_dir, CONFIG.get('outputs', 'rasterise_filename')) ds_list_fname = pjoin(self.out_dir, CONFIG.get('outputs', 'query_filename')) with open(ds_list_fname, 'r') as infile: ds_list = pickle.load(infile) vector_fname = CONFIG.get('work', 'vector_filename') img_fname = ds_list[0].datasets[DatasetType.FC25].path with rasterio.open(img_fname) as src: crs = src.crs transform = src.affine height = src.height width = src.width res = rasterise_vector(vector_fname, shape=(height, width), transform=transform, crs=crs) kwargs = { 'count': 1, 'width': width, 'height': height, 'crs': crs, 'transform': transform, 'dtype': res.dtype.name, 'nodata': 0 } with rasterio.open(out_fname, 'w', **kwargs) as src: src.write(1, res) # We could just set the image as the Luigi completion target... with self.output().open('w') as outf: outf.write('Complete')
def test_input_crs(self): ras = segmentation.rasterise_vector(self.vector_3577, shape=self.dims, transform=self.transform, crs=self.crs_4326) self.assertEqual(ras.sum(), 40000)
def test_different_proj(self): ras = segmentation.rasterise_vector(self.vector_3577, raster_filename=self.raster_fname) self.assertEqual(ras.sum(), 40000)
def test_same_proj(self): ras = segmentation.rasterise_vector(self.vector_4326, raster_filename=self.raster_fname) self.assertEqual(ras.sum(), 40000)