spatial_curation_intersect_areas: Perform spatial intersection with a geospatial layer

View source: R/spatial_curation_intersect_areas.R

spatial_curation_intersect_areasR Documentation

Perform spatial intersection with a geospatial layer

Description

This function performs the spatial intersection between a georeferenced dataset (input layer) and a georeferenced code list stored in Sardara database (intersection layer). It provides the features of the intersection layer that intersect the features of the input layer, along with the proportion of the area of the input layer feature being intersected by the intersection layer feature.

Usage

spatial_curation_intersect_areas(
con,
df_input,
df_spatial_code_list_name,
intersection_spatial_code_list_name)

Arguments

con

a wrapper of rpostgresql connection (connection to a database)

df_input

data.frame of fact. The dataframe must have at least a column 'geographic_identifier'. The code list used for the column 'geographic_identifier' must be one of the table of the schema 'area' of the database.

df_spatial_code_list_name

string . Dataset name of the code list used for the column 'geographic_identifier' of df_input (type polygon)

intersection_spatial_code_list_name

string . Name of the intersection layer to use (type polygon). Corresponds to the name of the table in the database.

Details

User has to be aware that the intersection might return several rows for 1 given row of df_input. This happens when one spatial feature of the input layer intersects several features of the intersection layer. Hence, the values of the ouput dataset might not be summed directly. Example:

1 row of df_input:

flag time_start time_end geographic_identifier gear species value
AUS 1992-02-01 1992-03-01 235140 LL YFT 0.05

When executing the function function spatial_curation_intersect_areas taking as intersection layer "fao_fishing_areas", the output dataset will return 2 rows:

flag time_start time_end geographic_identifier gear species value geographic_identifier_intersection_layer proportion_intersection
AUS 1992-02-01 1992-03-01 235140 LL YFT 3.2 F51 0.5
AUS 1992-02-01 1992-03-01 235140 LL YFT 3.2 F57 0.5

This table means that the geograpical identifier "235140" intersects two areas of the intersection layer: "F51" with 50% (proportion_intersection=0.5) of the area of 235140 being intersected by F51, and "F57" with 50% (proportion_intersection=0.5) of the area of 235140 being intersected by F57. However, the value of catch is 3.2 in both cases - i.e. it has not been multiplied by the proportion of area intersected.

Value

a list with 2 objects:

  • "df": df_input with additional columns:

    • "geographic_identifier_intersection_layer": Code of the feature from the intersection layer (intersection_spatial_code_list_name) that intersects the geographical identifier of df_input

    • "proportion_source_area_intersection": Proportion of the area of the df_input feature being intersected by the intersection layer feature.

  • "df_input_areas_intersect_intersection_layer": a data.frame summarizing the results of the spatial intersection. The columns are:

    • "geographic_identifier_source_layer": Code of the feature (geographic identifier) from df_input

    • "geographic_identifier_intersection_layer": Code of the feature from (intersection_spatial_code_list_name) that intersects the feature of df_input

    • "codelist_source_layer": Name of the code list used for the column 'geographic_identifier' of df_input

    • "codelist_intersection_layer": Name of the intersection layer code list (intersection_spatial_code_list_name)

    • "proportion_source_area_intersection": Proportion of the area of the input layer feature being intersected by the intersection layer feature.

Author(s)

Paul Taconet, paul.taconet@ird.fr

See Also

Other process data: convert_units, create_calendar, create_grid, get_rfmos_datasets_level0, map_codelist, raise_datasets_by_dimension, raise_get_rf, raise_incomplete_dataset_to_total_dataset, rasterize_geo_timeseries, spatial_curation_downgrade_resolution, spatial_curation_reallocate_data, spatial_curation_upgrade_resolution

Examples


# Connect to Tuna atlas database
con<-db_connection_tunaatlas_world()

# Extract a dataset
dataset_metadata<-list_metadata_datasets(con,identifier="west_pacific_ocean_catch_1970_01_01_2016_01_01_5deg_1m_ps_tunaatlasWCPFC_2017_level0")
df<-extract_dataset(con,dataset_metadata)

# Retrieve the spatial coding system used in the dataset
df_spatial_codingsystem <- get_codelist_of_dimension(con,dataset_metadata,"area")

# Get the list of geospatial layers available in the database
spatial_code_lists_available<-list_metadata_codelists(con,dimension="area")

# Intersect df with continents (to check which data are located on land areas)
df_intersect_continents<-spatial_curation_intersect_areas(con,df_input=df,df_spatial_code_list_name=df_spatial_codingsystem$dataset_name,intersection_spatial_code_list_name="gshhs_world_coastlines")

head(df_intersect_continents$df)
head(df_intersect_continents$df_input_areas_intersect_intersection_layer)

# Intersect df with EEZ (to know what percentage of df is located on EEZs)
df_intersect_eez<-spatial_curation_intersect_areas(con,df_input=df,df_spatial_code_list_name=df_spatial_codingsystem$dataset_name,intersection_spatial_code_list_name="vliz_world_eez_v8_2014")

head(df_intersect_eez$df)
head(df_intersect_eez$df_input_areas_intersect_intersection_layer)


ptaconet/rtunaatlas documentation built on June 23, 2024, 9:35 p.m.