Refactor get_optimal_extent in safe_interface into safe.utilities.analysis.