Landslide Science Rule · country
← All rules

country → writes country

1556 already match 0 would change

Function source

This is read live from inventory/derived.py via inspect.getsource(); what you see is exactly what runs.

def compute_country():
    """Country attribution from the primary-polygon centroid.

    The centroid point is tested against the `countries` reference table —
    Marine Regions "EEZ + land union" polygons (load_countries), i.e. each
    sovereign's land PLUS its waters out to 200 nmi — so a centroid in a
    fjord or nearshore attributes correctly with pure containment (no
    nearest-neighbor fallback needed). ST_Covers so a boundary point counts;
    ORDER BY name for a deterministic pick where overlapping/joint-regime
    EEZ claims exist. NULL centroid (no polygons yet) → NULL country. An
    empty countries table (reference data not loaded) leaves every value
    NULL rather than erroring — the table itself is created by
    migrate_regions so this SQL is always valid.
    """
    return """
        SELECT l.id,
               CASE WHEN l.centroid_lon IS NULL OR l.centroid_lat IS NULL THEN NULL
                    ELSE (SELECT c.name FROM countries c
                          WHERE ST_Covers(c.geom,
                                ST_SetSRID(ST_MakePoint(l.centroid_lon, l.centroid_lat), 4326))
                          ORDER BY c.name LIMIT 1)
               END AS computed
        FROM landslides l
        ORDER BY l.id
    """

Proposed changes

All rows already match this rule — nothing to apply.