def handle_output(self, output, result, task): cleanup_grass_context(result['context']) cols = output.split(':') if len(cols) == 7: # Correct scale measurement for web mercator # https://gis.stackexchange.com/questions/93332/calculating-distance-scale-factor-by-latitude-for-mercator#93335 latitude = task.dsm_extent.centroid[1] scale_factor = math.cos(math.radians(latitude)) ** 2 volume = abs(float(cols[6]) * scale_factor) return str(volume) else: raise TaskResultOutputError(output)
def get(self, request, pk=None, celery_task_id=None): res = celery.AsyncResult(celery_task_id) if not res.ready(): return Response({'ready': False}, status=status.HTTP_200_OK) else: result = res.get() if result.get('error', None) is not None: cleanup_grass_context(result['context']) return Response({'ready': True, 'error': result['error']}) contours_file = result.get('output') if not contours_file or not os.path.exists(contours_file): cleanup_grass_context(result['context']) return Response({'ready': True, 'error': 'Contours file could not be generated. This might be a bug.'}) request.session['contours_' + celery_task_id] = contours_file return Response({'ready': True})
def get(self, request, pk=None, celery_task_id=None): res = celery.AsyncResult(celery_task_id) if not res.ready(): return Response({'ready': False}, status=status.HTTP_200_OK) else: result = res.get() if result.get('error', None) is not None: cleanup_grass_context(result['context']) return Response({'ready': True, 'error': result['error']}) output = result.get('output') if not output or not os.path.exists(output): cleanup_grass_context(result['context']) return Response({'ready': True, 'error': output}) request.session['elevation_map_' + celery_task_id] = output return Response({'ready': True})
def handle_output(self, output, result, task): cleanup_grass_context(result['context']) cols = output.split(':') if len(cols) == 7: # Legacy: we had rasters in EPSG:3857 for a while # This could be removed at some point in the future # Correct scale measurement for web mercator # https://gis.stackexchange.com/questions/93332/calculating-distance-scale-factor-by-latitude-for-mercator#93335 scale_factor = 1.0 dsm = os.path.abspath(task.get_asset_download_path("dsm.tif")) with rasterio.open(dsm) as dst: if str(dst.crs) == 'EPSG:3857': latitude = task.dsm_extent.centroid[1] scale_factor = math.cos(math.radians(latitude))**2 volume = abs(float(cols[6]) * scale_factor) return str(volume) else: raise TaskResultOutputError(output)
def on_error(self, result): cleanup_grass_context(result['context'])