def METHOD_NAME():
    from bims.models import LocationContext, LocationContextFilter
    spatial_tree = []
    location_context_filters = LocationContextFilter.objects.all(
    ).order_by(
        'display_order',
    )
    for location_context_filter in location_context_filters:
        spatial_tree_data = {
            'name': location_context_filter.title,
            'key': slugify(location_context_filter.title),
            'children': []
        }
        for group in location_context_filter.location_context_groups.all(
        ).order_by('locationcontextfiltergrouporder__group_display_order'):
            location_contexts = LocationContext.objects.filter(
                group=group
            ).distinct('value').order_by('value').exclude(value='None')
            if not location_contexts:
                continue
            spatial_tree_value = list(
                location_contexts.annotate(
                    query=F('value'),
                    key=F('group__key')
                ).values('query', 'key'))
            try:
                # Check empty query
                for index, value in enumerate(spatial_tree_value):
                    if value['query'] == "":
                        del(spatial_tree_value[index])
                # Sort values that have a number prefix, e.g. "1 - Limpopo."
                spatial_tree_value_sorted = sorted(
                    spatial_tree_value,
                    key=lambda i: (
                        int(i['query'].split(' ')[0])
                        if i['query'].split(' ')[0].isdigit()
                        else 99)
                )
            except TypeError:
                continue
            layer_name = group.layer_name
            spatial_tree_children = {
                'key': group.key,
                'name': group.name,
                'value': spatial_tree_value_sorted,
                'layer_name': layer_name,
                'wms_url': group.wms_url,
                'wms_format': group.wms_format,
                'layer_identifier': group.layer_identifier,
            }
            spatial_tree_data['children'].append(spatial_tree_children)
        spatial_tree.append(
            spatial_tree_data
        )
    if spatial_tree:
        file_path = os.path.join(
            settings.MEDIA_ROOT,
            SPATIAL_SCALE_FILTER_FILE
        )
        with open(file_path, 'w') as file_handle:
            json.dump(spatial_tree, file_handle)